refactor: rename function-runtime-oci package to container

Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
This commit is contained in:
Philippe Scorsolini 2023-08-17 11:49:30 +02:00
parent dba139a3d3
commit d6ffe9fbd1
No known key found for this signature in database
GPG Key ID: 58CAEA8F1CC8503E
8 changed files with 38 additions and 38 deletions

View File

@ -30,7 +30,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/errors"
"github.com/crossplane/function-runtime-oci/cmd/function-runtime-oci/start" "github.com/crossplane/function-runtime-oci/cmd/function-runtime-oci/start"
"github.com/crossplane/function-runtime-oci/internal/function-runtime-oci" "github.com/crossplane/function-runtime-oci/internal/container"
"github.com/crossplane/function-runtime-oci/internal/proto/v1alpha1" "github.com/crossplane/function-runtime-oci/internal/proto/v1alpha1"
) )
@ -65,7 +65,7 @@ func (c *Command) Run(args *start.Args) error {
// own UID and GID to root inside the user namespace. // own UID and GID to root inside the user namespace.
rootUID := os.Getuid() rootUID := os.Getuid()
rootGID := os.Getgid() rootGID := os.Getgid()
setuid := function_runtime_oci.HasCapSetUID() && function_runtime_oci.HasCapSetGID() // We're using 'setuid' as shorthand for both here. setuid := container.HasCapSetUID() && container.HasCapSetGID() // We're using 'setuid' as shorthand for both here.
if setuid { if setuid {
rootUID = c.MapRootUID rootUID = c.MapRootUID
rootGID = c.MapRootGID rootGID = c.MapRootGID
@ -91,7 +91,7 @@ func (c *Command) Run(args *start.Args) error {
return errors.Wrap(err, errAuthCfg) return errors.Wrap(err, errAuthCfg)
} }
f := function_runtime_oci.NewContainerRunner(function_runtime_oci.SetUID(setuid), function_runtime_oci.MapToRoot(rootUID, rootGID), function_runtime_oci.WithCacheDir(filepath.Clean(c.CacheDir)), function_runtime_oci.WithRegistry(args.Registry)) f := container.NewRunner(container.SetUID(setuid), container.MapToRoot(rootUID, rootGID), container.WithCacheDir(filepath.Clean(c.CacheDir)), container.WithRegistry(args.Registry))
rsp, err := f.RunFunction(context.Background(), &v1alpha1.RunFunctionRequest{ rsp, err := f.RunFunction(context.Background(), &v1alpha1.RunFunctionRequest{
Image: c.Image, Image: c.Image,
Input: c.FunctionIO, Input: c.FunctionIO,

View File

@ -25,7 +25,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/errors" "github.com/crossplane/crossplane-runtime/pkg/errors"
"github.com/crossplane/crossplane-runtime/pkg/logging" "github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/crossplane/function-runtime-oci/internal/function-runtime-oci" "github.com/crossplane/function-runtime-oci/internal/container"
) )
// Error strings // Error strings
@ -54,18 +54,18 @@ func (c *Command) Run(args *Args, log logging.Logger) error {
// own UID and GID to root inside the user namespace. // own UID and GID to root inside the user namespace.
rootUID := os.Getuid() rootUID := os.Getuid()
rootGID := os.Getgid() rootGID := os.Getgid()
setuid := function_runtime_oci.HasCapSetUID() && function_runtime_oci.HasCapSetGID() // We're using 'setuid' as shorthand for both here. setuid := container.HasCapSetUID() && container.HasCapSetGID() // We're using 'setuid' as shorthand for both here.
if setuid { if setuid {
rootUID = c.MapRootUID rootUID = c.MapRootUID
rootGID = c.MapRootGID rootGID = c.MapRootGID
} }
// TODO(negz): Expose a healthz endpoint and otel metrics. // TODO(negz): Expose a healthz endpoint and otel metrics.
f := function_runtime_oci.NewContainerRunner( f := container.NewRunner(
function_runtime_oci.SetUID(setuid), container.SetUID(setuid),
function_runtime_oci.MapToRoot(rootUID, rootGID), container.MapToRoot(rootUID, rootGID),
function_runtime_oci.WithCacheDir(filepath.Clean(c.CacheDir)), container.WithCacheDir(filepath.Clean(c.CacheDir)),
function_runtime_oci.WithLogger(log), container.WithLogger(log),
function_runtime_oci.WithRegistry(args.Registry)) container.WithRegistry(args.Registry))
return errors.Wrap(f.ListenAndServe(c.Network, c.Address), errListenAndServe) return errors.Wrap(f.ListenAndServe(c.Network, c.Address), errListenAndServe)
} }

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package function_runtime_oci package container
import ( import (
"io" "io"
@ -36,9 +36,9 @@ const (
const defaultCacheDir = "/function-runtime-oci" const defaultCacheDir = "/function-runtime-oci"
// An ContainerRunner runs a Composition Function packaged as an OCI image by // A Runner runs a Composition Function packaged as an OCI image by
// extracting it and running it as a 'rootless' container. // extracting it and running it as a 'rootless' container.
type ContainerRunner struct { type Runner struct {
v1alpha1.UnimplementedContainerizedFunctionRunnerServiceServer v1alpha1.UnimplementedContainerizedFunctionRunnerServiceServer
log logging.Logger log logging.Logger
@ -50,13 +50,13 @@ type ContainerRunner struct {
registry string registry string
} }
// A ContainerRunnerOption configures a new ContainerRunner. // A RunnerOption configures a new Runner.
type ContainerRunnerOption func(*ContainerRunner) type RunnerOption func(*Runner)
// MapToRoot configures what UID and GID should map to root (UID/GID 0) in the // MapToRoot configures what UID and GID should map to root (UID/GID 0) in the
// user namespace in which the function will be run. // user namespace in which the function will be run.
func MapToRoot(uid, gid int) ContainerRunnerOption { func MapToRoot(uid, gid int) RunnerOption {
return func(r *ContainerRunner) { return func(r *Runner) {
r.rootUID = uid r.rootUID = uid
r.rootGID = gid r.rootGID = gid
} }
@ -65,40 +65,40 @@ func MapToRoot(uid, gid int) ContainerRunnerOption {
// SetUID indicates that the container runner should attempt operations that // SetUID indicates that the container runner should attempt operations that
// require CAP_SETUID and CAP_SETGID, for example creating a user namespace that // require CAP_SETUID and CAP_SETGID, for example creating a user namespace that
// maps arbitrary UIDs and GIDs to the parent namespace. // maps arbitrary UIDs and GIDs to the parent namespace.
func SetUID(s bool) ContainerRunnerOption { func SetUID(s bool) RunnerOption {
return func(r *ContainerRunner) { return func(r *Runner) {
r.setuid = s r.setuid = s
} }
} }
// WithCacheDir specifies the directory used for caching function images and // WithCacheDir specifies the directory used for caching function images and
// containers. // containers.
func WithCacheDir(d string) ContainerRunnerOption { func WithCacheDir(d string) RunnerOption {
return func(r *ContainerRunner) { return func(r *Runner) {
r.cache = d r.cache = d
} }
} }
// WithRegistry specifies the default registry used to retrieve function images and // WithRegistry specifies the default registry used to retrieve function images and
// containers. // containers.
func WithRegistry(dr string) ContainerRunnerOption { func WithRegistry(dr string) RunnerOption {
return func(r *ContainerRunner) { return func(r *Runner) {
r.registry = dr r.registry = dr
} }
} }
// WithLogger configures which logger the container runner should use. Logging // WithLogger configures which logger the container runner should use. Logging
// is disabled by default. // is disabled by default.
func WithLogger(l logging.Logger) ContainerRunnerOption { func WithLogger(l logging.Logger) RunnerOption {
return func(cr *ContainerRunner) { return func(cr *Runner) {
cr.log = l cr.log = l
} }
} }
// NewContainerRunner returns a new Runner that runs functions as rootless // NewRunner returns a new Runner that runs functions as rootless
// containers. // containers.
func NewContainerRunner(o ...ContainerRunnerOption) *ContainerRunner { func NewRunner(o ...RunnerOption) *Runner {
r := &ContainerRunner{cache: defaultCacheDir, log: logging.NewNopLogger()} r := &Runner{cache: defaultCacheDir, log: logging.NewNopLogger()}
for _, fn := range o { for _, fn := range o {
fn(r) fn(r)
} }
@ -107,7 +107,7 @@ func NewContainerRunner(o ...ContainerRunnerOption) *ContainerRunner {
} }
// ListenAndServe gRPC connections at the supplied address. // ListenAndServe gRPC connections at the supplied address.
func (r *ContainerRunner) ListenAndServe(network, address string) error { func (r *Runner) ListenAndServe(network, address string) error {
r.log.Debug("Listening", "network", network, "address", address) r.log.Debug("Listening", "network", network, "address", address)
lis, err := net.Listen(network, address) lis, err := net.Listen(network, address)
if err != nil { if err != nil {

View File

@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package function_runtime_oci package container
import ( import (
"bytes" "bytes"
@ -82,7 +82,7 @@ func HasCapSetGID() bool {
// RunFunction runs a function as a rootless OCI container. Functions that // RunFunction runs a function as a rootless OCI container. Functions that
// return non-zero, or that cannot be executed in the first place (e.g. because // return non-zero, or that cannot be executed in the first place (e.g. because
// they cannot be fetched from the registry) will return an error. // they cannot be fetched from the registry) will return an error.
func (r *ContainerRunner) RunFunction(ctx context.Context, req *v1alpha1.RunFunctionRequest) (*v1alpha1.RunFunctionResponse, error) { func (r *Runner) RunFunction(ctx context.Context, req *v1alpha1.RunFunctionRequest) (*v1alpha1.RunFunctionResponse, error) {
r.log.Debug("Running function", "image", req.Image) r.log.Debug("Running function", "image", req.Image)
/* /*

View File

@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package function_runtime_oci package container
import ( import (
"context" "context"
@ -35,6 +35,6 @@ func HasCapSetUID() bool { return false }
func HasCapSetGID() bool { return false } func HasCapSetGID() bool { return false }
// RunFunction returns an error on non-Linux. // RunFunction returns an error on non-Linux.
func (r *ContainerRunner) RunFunction(_ context.Context, _ *v1alpha1.RunFunctionRequest) (*v1alpha1.RunFunctionResponse, error) { func (r *Runner) RunFunction(_ context.Context, _ *v1alpha1.RunFunctionRequest) (*v1alpha1.RunFunctionResponse, error) {
return nil, errors.New(errLinuxOnly) return nil, errors.New(errLinuxOnly)
} }

View File

@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package function_runtime_oci package container
import ( import (
"os/exec" "os/exec"

View File

@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package function_runtime_oci package container
import ( import (
"os/exec" "os/exec"

View File

@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Package function-runtime-oci is the reference implementation of Composition // Package container is the reference implementation of Composition
// Functions. // Functions.
package function_runtime_oci package container