Skip to content

Commit

Permalink
Populate CreatedAt
Browse files Browse the repository at this point in the history
Populates the CreatedAt value from the container's info
field.

Ref: openfaas/faas-provider#59

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Mar 11, 2021
1 parent c7d9353 commit 659f98c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -30,7 +30,7 @@ require (
github.com/opencontainers/runc v1.0.0-rc9 // indirect
github.com/opencontainers/runtime-spec v1.0.2
github.com/openfaas/faas v0.0.0-20201205125747-9bbb25e3c7c4
github.com/openfaas/faas-provider v0.17.1
github.com/openfaas/faas-provider v0.17.2
github.com/pkg/errors v0.9.1
github.com/prometheus/procfs v0.2.0 // indirect
github.com/sethvargo/go-password v0.1.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -185,6 +185,8 @@ github.com/openfaas/faas-provider v0.17.0 h1:4rT8CosKhI5xaAMqbyihEgR6KefO/ViJdF0
github.com/openfaas/faas-provider v0.17.0/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98=
github.com/openfaas/faas-provider v0.17.1 h1:P5xTLN+/08PLLh4auIlO/PaUD/J3BUTmaC3en8N5zbs=
github.com/openfaas/faas-provider v0.17.1/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98=
github.com/openfaas/faas-provider v0.17.2 h1:jZ+Z83A/tyJoI1AnpyLN3o0B4K0UEsz1YJ3erASMu+s=
github.com/openfaas/faas-provider v0.17.2/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/handlers/deploy.go
Expand Up @@ -29,8 +29,8 @@ import (

const annotationLabelPrefix = "com.openfaas.annotations."

// MakeDeployHandler returns a handler to deploy a function
func MakeDeployHandler(client *containerd.Client, cni gocni.CNI, secretMountPath string, alwaysPull bool) func(w http.ResponseWriter, r *http.Request) {

return func(w http.ResponseWriter, r *http.Request) {

if r.Body == nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/provider/handlers/functions.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/opencontainers/runtime-spec/specs-go"

Expand All @@ -27,6 +28,7 @@ type Function struct {
secrets []string
envVars map[string]string
envProcess string
createdAt time.Time
}

// ListFunctions returns a map of all functions with running tasks on namespace
Expand Down Expand Up @@ -81,6 +83,11 @@ func GetFunction(client *containerd.Client, name string) (Function, error) {
return Function{}, fmt.Errorf("unable to load function spec for reading secrets: %s, error %s", name, err)
}

info, err := c.Info(ctx)
if err != nil {
return Function{}, fmt.Errorf("can't load info for: %s, error %s", name, err)
}

envVars, envProcess := readEnvFromProcessEnv(spec.Process.Env)
secrets := readSecretsFromMounts(spec.Mounts)

Expand All @@ -92,6 +99,7 @@ func GetFunction(client *containerd.Client, name string) (Function, error) {
fn.secrets = secrets
fn.envVars = envVars
fn.envProcess = envProcess
fn.createdAt = info.CreatedAt

replicas := 0
task, err := c.Task(ctx, nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/handlers/read.go
Expand Up @@ -34,13 +34,13 @@ func MakeReadHandler(client *containerd.Client) func(w http.ResponseWriter, r *h
Secrets: fn.secrets,
EnvVars: fn.envVars,
EnvProcess: fn.envProcess,
CreatedAt: fn.createdAt,
})
}

body, _ := json.Marshal(res)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(body)

}
}
1 change: 1 addition & 0 deletions pkg/provider/handlers/replicas.go
Expand Up @@ -26,6 +26,7 @@ func MakeReplicaReaderHandler(client *containerd.Client) func(w http.ResponseWri
Secrets: f.secrets,
EnvVars: f.envVars,
EnvProcess: f.envProcess,
CreatedAt: f.createdAt,
}

functionBytes, _ := json.Marshal(found)
Expand Down
10 changes: 9 additions & 1 deletion vendor/github.com/openfaas/faas-provider/types/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 659f98c

Please sign in to comment.