From 32c00f0e9e5143ac14dd3db717d45b4674eb5764 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Sun, 3 Jan 2021 15:54:39 +0000 Subject: [PATCH] Use the openfaas namespace for core services All services like docker and k8s.io use their own namespaces for core services, this change moves openfaas services into the openfaas namespace instead of the default one. The main change is that logs will look like: journalctl -t openfaas:gateway Instead of "default:gateway" Function logs will remain unaffected and scheduled in the openfaas-fn namespace. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- README.md | 8 +++++--- pkg/constants.go | 7 +++++++ pkg/service/service.go | 24 ++++++++++++++---------- pkg/supervisor.go | 4 ---- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index fe3e444..61de7fb 100644 --- a/README.md +++ b/README.md @@ -125,14 +125,16 @@ echo logs | faas-cli invoke figlet Core services as defined in the docker-compose.yaml file are deployed as containers by faasd. +The namespace is `openfaas` for core services. + View the logs for a component by giving its NAME: ```bash -journalctl -t default:NAME +journalctl -t openfaas:NAME -journalctl -t default:gateway +journalctl -t openfaas:gateway -journalctl -t default:queue-worker +journalctl -t openfaas:queue-worker ``` You can also use `-f` to follow the logs, or `--lines` to tail a number of lines, or `--since` to give a timeframe. diff --git a/pkg/constants.go b/pkg/constants.go index 27361a4..f92d484 100644 --- a/pkg/constants.go +++ b/pkg/constants.go @@ -3,4 +3,11 @@ package pkg const ( // FunctionNamespace is the default containerd namespace functions are created FunctionNamespace = "openfaas-fn" + + // faasdNamespace is the containerd namespace services are created + faasdNamespace = "openfaas" + + faasServicesPullAlways = false + + defaultSnapshotter = "overlayfs" ) diff --git a/pkg/service/service.go b/pkg/service/service.go index 5459d10..31afb7a 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -38,20 +38,21 @@ func Remove(ctx context.Context, client *containerd.Client, name string) error { } if found { - status, _ := t.Status(ctx) - fmt.Printf("Status of %s is: %s\n", name, status.Status) + status, err := t.Status(ctx) + if err != nil { + fmt.Printf("Status of %s is: %s\n", name, status.Status) + } log.Printf("Need to kill %s\n", name) - err := killTask(ctx, t) - if err != nil { + if err = killTask(ctx, t); err != nil { return fmt.Errorf("error killing task %s, %s, %s", container.ID(), name, err) } } - err = container.Delete(ctx, containerd.WithSnapshotCleanup) - if err != nil { + if err := container.Delete(ctx, containerd.WithSnapshotCleanup); err != nil { return fmt.Errorf("error deleting container %s, %s, %s", container.ID(), name, err) } + } else { service := client.SnapshotService("") key := name + "snapshot" @@ -70,6 +71,7 @@ func killTask(ctx context.Context, task containerd.Task) error { wg := &sync.WaitGroup{} wg.Add(1) var err error + go func() { defer wg.Done() if task != nil { @@ -114,6 +116,7 @@ func getResolver(ctx context.Context, configFile *configfile.ConfigFile) (remote } return ac.Username, ac.Password, nil } + authOpts := []docker.AuthorizerOpt{docker.WithAuthCreds(credFunc)} authorizer := docker.NewDockerAuthorizer(authOpts...) opts := docker.ResolverOptions{ @@ -128,7 +131,7 @@ func PrepareImage(ctx context.Context, client *containerd.Client, imageName, sna resolver remotes.Resolver ) - if _, stErr := os.Stat(filepath.Join(dockerConfigDir, config.ConfigFileName)); stErr == nil { + if _, statErr := os.Stat(filepath.Join(dockerConfigDir, config.ConfigFileName)); statErr == nil { configFile, err := config.Load(dockerConfigDir) if err != nil { return nil, err @@ -137,8 +140,8 @@ func PrepareImage(ctx context.Context, client *containerd.Client, imageName, sna if err != nil { return empty, err } - } else if !os.IsNotExist(stErr) { - return empty, stErr + } else if !os.IsNotExist(statErr) { + return empty, statErr } var image containerd.Image @@ -150,7 +153,6 @@ func PrepareImage(ctx context.Context, client *containerd.Client, imageName, sna image = img } else { - img, err := client.GetImage(ctx, imageName) if err != nil { if !errdefs.IsNotFound(err) { @@ -187,9 +189,11 @@ func pullImage(ctx context.Context, client *containerd.Client, resolver remotes. rOpts := []containerd.RemoteOpt{ containerd.WithPullUnpack, } + if resolver != nil { rOpts = append(rOpts, containerd.WithResolver(resolver)) } + img, err := client.Pull(ctx, imageName, rOpts...) if err != nil { return empty, fmt.Errorf("cannot pull: %s", err) diff --git a/pkg/supervisor.go b/pkg/supervisor.go index 0385ab3..ceef8a5 100644 --- a/pkg/supervisor.go +++ b/pkg/supervisor.go @@ -26,11 +26,7 @@ import ( ) const ( - defaultSnapshotter = "overlayfs" workingDirectoryPermission = 0644 - // faasdNamespace is the containerd namespace services are created - faasdNamespace = "default" - faasServicesPullAlways = false ) type Service struct {