diff --git a/pkg/provider/handlers/deploy.go b/pkg/provider/handlers/deploy.go index e8cd585..b4919e7 100644 --- a/pkg/provider/handlers/deploy.go +++ b/pkg/provider/handlers/deploy.go @@ -126,7 +126,7 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container labels, err := buildLabels(&req) if err != nil { - return fmt.Errorf("unable to apply labels to container: %s, error: %s", name, err) + return fmt.Errorf("unable to apply labels to container: %s, error: %w", name, err) } var memory *specs.LinuxMemory @@ -157,7 +157,7 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container ) if err != nil { - return fmt.Errorf("unable to create container: %s, error: %s", name, err) + return fmt.Errorf("unable to create container: %s, error: %w", name, err) } return createTask(ctx, client, container, cni) @@ -195,7 +195,7 @@ func createTask(ctx context.Context, client *containerd.Client, container contai task, taskErr := container.NewTask(ctx, cio.BinaryIO("/usr/local/bin/faasd", nil)) if taskErr != nil { - return fmt.Errorf("unable to start task: %s, error: %s", name, taskErr) + return fmt.Errorf("unable to start task: %s, error: %w", name, taskErr) } log.Printf("Container ID: %s\tTask ID %s:\tTask PID: %d\t\n", name, task.ID(), task.Pid()) diff --git a/pkg/provider/handlers/functions.go b/pkg/provider/handlers/functions.go index 232ec8b..19ba3b4 100644 --- a/pkg/provider/handlers/functions.go +++ b/pkg/provider/handlers/functions.go @@ -60,7 +60,7 @@ func GetFunction(client *containerd.Client, name string, namespace string) (Func c, err := client.LoadContainer(ctx, name) if err != nil { - return Function{}, fmt.Errorf("unable to find function: %s, error %s", name, err) + return Function{}, fmt.Errorf("unable to find function: %s, error %w", name, err) } image, err := c.Image(ctx) @@ -72,19 +72,19 @@ func GetFunction(client *containerd.Client, name string, namespace string) (Func allLabels, labelErr := c.Labels(ctx) if labelErr != nil { - log.Printf("cannot list container %s labels: %s", containerName, labelErr.Error()) + log.Printf("cannot list container %s labels: %w", containerName, labelErr) } labels, annotations := buildLabelsAndAnnotations(allLabels) spec, err := c.Spec(ctx) if err != nil { - return Function{}, fmt.Errorf("unable to load function spec for reading secrets: %s, error %s", name, err) + return Function{}, fmt.Errorf("unable to load function spec for reading secrets: %s, error %w", name, err) } info, err := c.Info(ctx) if err != nil { - return Function{}, fmt.Errorf("can't load info for: %s, error %s", name, err) + return Function{}, fmt.Errorf("can't load info for: %s, error %w", name, err) } envVars, envProcess := readEnvFromProcessEnv(spec.Process.Env) @@ -106,7 +106,7 @@ func GetFunction(client *containerd.Client, name string, namespace string) (Func // Task for container exists svc, err := task.Status(ctx) if err != nil { - return Function{}, fmt.Errorf("unable to get task status for container: %s %s", name, err) + return Function{}, fmt.Errorf("unable to get task status for container: %s %w", name, err) } if svc.Status == "running" { diff --git a/pkg/service/service.go b/pkg/service/service.go index 1e05269..c856258 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -33,7 +33,7 @@ func Remove(ctx context.Context, client *containerd.Client, name string) error { if errdefs.IsNotFound(err) { taskFound = false } else { - return fmt.Errorf("unable to get task %s: ", err) + return fmt.Errorf("unable to get task %w: ", err) } } @@ -47,12 +47,12 @@ func Remove(ctx context.Context, client *containerd.Client, name string) error { log.Printf("Need to kill task: %s\n", name) if err = killTask(ctx, t); err != nil { - return fmt.Errorf("error killing task %s, %s, %s", container.ID(), name, err) + return fmt.Errorf("error killing task %s, %s, %w", container.ID(), name, err) } } if err := container.Delete(ctx, containerd.WithSnapshotCleanup); err != nil { - return fmt.Errorf("error deleting container %s, %s, %s", container.ID(), name, err) + return fmt.Errorf("error deleting container %s, %s, %w", container.ID(), name, err) } } else { @@ -79,9 +79,10 @@ func killTask(ctx context.Context, task containerd.Task) error { if task != nil { wait, err := task.Wait(ctx) if err != nil { - err = fmt.Errorf("error waiting on task: %s", err) + log.Printf("error waiting on task: %s", err) return } + if err := task.Kill(ctx, unix.SIGTERM, containerd.WithKillAll); err != nil { log.Printf("error killing container task: %s", err) }