Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ func (c *Client) Create(f Function) (err error) {
return
}

// Write the Function metadata (func.yaml)
// Mark it as having been created via this client library and Write (save)
f.Created = time.Now()
if err = writeConfig(f); err != nil {
return
}
Expand Down
24 changes: 24 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"reflect"
"testing"
"time"

fn "knative.dev/kn-plugin-func"
"knative.dev/kn-plugin-func/mock"
Expand Down Expand Up @@ -877,6 +878,29 @@ func TestRuntimes(t *testing.T) {
}
}

// TestCreateStamp ensures that the creation timestamp is set on functions
// which are successfully initialized using the client library.
func TestCreateStamp(t *testing.T) {
root := "testdata/example.com/testCreateStamp"
defer using(t, root)()

start := time.Now()

client := fn.New(fn.WithRegistry(TestRegistry))

if err := client.New(context.Background(), fn.Function{Root: root}); err != nil {
t.Fatal(err)
}

f, err := fn.NewFunction(root)
if err != nil {
t.Fatal(err)
}
if !f.Created.After(start) {
t.Fatalf("expected function timestamp to be after '%v', got '%v'", start, f.Created)
}
}

// Helpers ----

// USING: Make specified dir. Return deferrable cleanup fn.
Expand Down
1 change: 1 addition & 0 deletions cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ builders:
envs: []
annotations: {}
labels: []
created: 2021-01-01T00:00:00+00:00
`
if err := ioutil.WriteFile("func.yaml", []byte(funcYaml), 0600); err != nil {
t.Fatal(err)
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"regexp"
"strings"
"time"

"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -146,6 +147,7 @@ type Config struct {
Annotations map[string]string `yaml:"annotations"`
Options Options `yaml:"options"`
Labels Labels `yaml:"labels"`
Created time.Time `yaml:"created"`
// Add new values to the toConfig/fromConfig functions.
}

Expand Down Expand Up @@ -268,6 +270,7 @@ func fromConfig(c Config) (f Function) {
Annotations: c.Annotations,
Options: c.Options,
Labels: c.Labels,
Created: c.Created,
}
}

Expand All @@ -289,6 +292,7 @@ func toConfig(f Function) Config {
Annotations: f.Annotations,
Options: f.Options,
Labels: f.Labels,
Created: f.Created,
}
}

Expand Down
6 changes: 6 additions & 0 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
)

type Function struct {
Expand Down Expand Up @@ -75,6 +76,11 @@ type Function struct {

// Health endpoints specified by the language pack
HealthEndpoints HealthEndpoints

// Created time is the moment that creation was successfully completed
// according to the client which is in charge of what constitutes being
// fully "Created" (aka initialized)
Created time.Time
}

// NewFunction loads a Function from a path on disk. use .Initialized() to determine if
Expand Down
7 changes: 6 additions & 1 deletion schema/func_yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"envs",
"annotations",
"options",
"labels"
"labels",
"created"
],
"properties": {
"name": {
Expand Down Expand Up @@ -96,6 +97,10 @@
"$ref": "#/definitions/Label"
},
"type": "array"
},
"created": {
"type": "string",
"format": "date-time"
}
},
"additionalProperties": false,
Expand Down