refactor: rename function-runtime-oci package to container
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
This commit is contained in:
parent
dba139a3d3
commit
d6ffe9fbd1
|
@ -30,7 +30,7 @@ import (
|
|||
"github.com/crossplane/crossplane-runtime/pkg/errors"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
|
@ -65,7 +65,7 @@ func (c *Command) Run(args *start.Args) error {
|
|||
// own UID and GID to root inside the user namespace.
|
||||
rootUID := os.Getuid()
|
||||
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 {
|
||||
rootUID = c.MapRootUID
|
||||
rootGID = c.MapRootGID
|
||||
|
@ -91,7 +91,7 @@ func (c *Command) Run(args *start.Args) error {
|
|||
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{
|
||||
Image: c.Image,
|
||||
Input: c.FunctionIO,
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"github.com/crossplane/crossplane-runtime/pkg/errors"
|
||||
"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
|
||||
|
@ -54,18 +54,18 @@ func (c *Command) Run(args *Args, log logging.Logger) error {
|
|||
// own UID and GID to root inside the user namespace.
|
||||
rootUID := os.Getuid()
|
||||
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 {
|
||||
rootUID = c.MapRootUID
|
||||
rootGID = c.MapRootGID
|
||||
}
|
||||
|
||||
// TODO(negz): Expose a healthz endpoint and otel metrics.
|
||||
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.WithLogger(log),
|
||||
function_runtime_oci.WithRegistry(args.Registry))
|
||||
f := container.NewRunner(
|
||||
container.SetUID(setuid),
|
||||
container.MapToRoot(rootUID, rootGID),
|
||||
container.WithCacheDir(filepath.Clean(c.CacheDir)),
|
||||
container.WithLogger(log),
|
||||
container.WithRegistry(args.Registry))
|
||||
return errors.Wrap(f.ListenAndServe(c.Network, c.Address), errListenAndServe)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package function_runtime_oci
|
||||
package container
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
@ -36,9 +36,9 @@ const (
|
|||
|
||||
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.
|
||||
type ContainerRunner struct {
|
||||
type Runner struct {
|
||||
v1alpha1.UnimplementedContainerizedFunctionRunnerServiceServer
|
||||
|
||||
log logging.Logger
|
||||
|
@ -50,13 +50,13 @@ type ContainerRunner struct {
|
|||
registry string
|
||||
}
|
||||
|
||||
// A ContainerRunnerOption configures a new ContainerRunner.
|
||||
type ContainerRunnerOption func(*ContainerRunner)
|
||||
// A RunnerOption configures a new Runner.
|
||||
type RunnerOption func(*Runner)
|
||||
|
||||
// MapToRoot configures what UID and GID should map to root (UID/GID 0) in the
|
||||
// user namespace in which the function will be run.
|
||||
func MapToRoot(uid, gid int) ContainerRunnerOption {
|
||||
return func(r *ContainerRunner) {
|
||||
func MapToRoot(uid, gid int) RunnerOption {
|
||||
return func(r *Runner) {
|
||||
r.rootUID = uid
|
||||
r.rootGID = gid
|
||||
}
|
||||
|
@ -65,40 +65,40 @@ func MapToRoot(uid, gid int) ContainerRunnerOption {
|
|||
// SetUID indicates that the container runner should attempt operations that
|
||||
// require CAP_SETUID and CAP_SETGID, for example creating a user namespace that
|
||||
// maps arbitrary UIDs and GIDs to the parent namespace.
|
||||
func SetUID(s bool) ContainerRunnerOption {
|
||||
return func(r *ContainerRunner) {
|
||||
func SetUID(s bool) RunnerOption {
|
||||
return func(r *Runner) {
|
||||
r.setuid = s
|
||||
}
|
||||
}
|
||||
|
||||
// WithCacheDir specifies the directory used for caching function images and
|
||||
// containers.
|
||||
func WithCacheDir(d string) ContainerRunnerOption {
|
||||
return func(r *ContainerRunner) {
|
||||
func WithCacheDir(d string) RunnerOption {
|
||||
return func(r *Runner) {
|
||||
r.cache = d
|
||||
}
|
||||
}
|
||||
|
||||
// WithRegistry specifies the default registry used to retrieve function images and
|
||||
// containers.
|
||||
func WithRegistry(dr string) ContainerRunnerOption {
|
||||
return func(r *ContainerRunner) {
|
||||
func WithRegistry(dr string) RunnerOption {
|
||||
return func(r *Runner) {
|
||||
r.registry = dr
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogger configures which logger the container runner should use. Logging
|
||||
// is disabled by default.
|
||||
func WithLogger(l logging.Logger) ContainerRunnerOption {
|
||||
return func(cr *ContainerRunner) {
|
||||
func WithLogger(l logging.Logger) RunnerOption {
|
||||
return func(cr *Runner) {
|
||||
cr.log = l
|
||||
}
|
||||
}
|
||||
|
||||
// NewContainerRunner returns a new Runner that runs functions as rootless
|
||||
// NewRunner returns a new Runner that runs functions as rootless
|
||||
// containers.
|
||||
func NewContainerRunner(o ...ContainerRunnerOption) *ContainerRunner {
|
||||
r := &ContainerRunner{cache: defaultCacheDir, log: logging.NewNopLogger()}
|
||||
func NewRunner(o ...RunnerOption) *Runner {
|
||||
r := &Runner{cache: defaultCacheDir, log: logging.NewNopLogger()}
|
||||
for _, fn := range o {
|
||||
fn(r)
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ func NewContainerRunner(o ...ContainerRunnerOption) *ContainerRunner {
|
|||
}
|
||||
|
||||
// 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)
|
||||
lis, err := net.Listen(network, address)
|
||||
if err != nil {
|
|
@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package function_runtime_oci
|
||||
package container
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -82,7 +82,7 @@ func HasCapSetGID() bool {
|
|||
// 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
|
||||
// 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)
|
||||
|
||||
/*
|
|
@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package function_runtime_oci
|
||||
package container
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -35,6 +35,6 @@ func HasCapSetUID() bool { return false }
|
|||
func HasCapSetGID() bool { return false }
|
||||
|
||||
// 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)
|
||||
}
|
|
@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package function_runtime_oci
|
||||
package container
|
||||
|
||||
import (
|
||||
"os/exec"
|
|
@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package function_runtime_oci
|
||||
package container
|
||||
|
||||
import (
|
||||
"os/exec"
|
|
@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package function-runtime-oci is the reference implementation of Composition
|
||||
// Package container is the reference implementation of Composition
|
||||
// Functions.
|
||||
package function_runtime_oci
|
||||
package container
|
Loading…
Reference in New Issue