mirror of https://github.com/knative/func.git
feat: function creation timestamp (#651)
This commit is contained in:
parent
fc1e874a5d
commit
1bf17ec976
|
@ -481,7 +481,8 @@ func (c *Client) Create(f Function) (err error) {
|
||||||
return
|
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 {
|
if err = writeConfig(f); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
fn "knative.dev/kn-plugin-func"
|
fn "knative.dev/kn-plugin-func"
|
||||||
"knative.dev/kn-plugin-func/mock"
|
"knative.dev/kn-plugin-func/mock"
|
||||||
|
@ -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 ----
|
// Helpers ----
|
||||||
|
|
||||||
// USING: Make specified dir. Return deferrable cleanup fn.
|
// USING: Make specified dir. Return deferrable cleanup fn.
|
||||||
|
|
|
@ -63,6 +63,7 @@ builders:
|
||||||
envs: []
|
envs: []
|
||||||
annotations: {}
|
annotations: {}
|
||||||
labels: []
|
labels: []
|
||||||
|
created: 2021-01-01T00:00:00+00:00
|
||||||
`
|
`
|
||||||
if err := ioutil.WriteFile("func.yaml", []byte(funcYaml), 0600); err != nil {
|
if err := ioutil.WriteFile("func.yaml", []byte(funcYaml), 0600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
@ -146,6 +147,7 @@ type Config struct {
|
||||||
Annotations map[string]string `yaml:"annotations"`
|
Annotations map[string]string `yaml:"annotations"`
|
||||||
Options Options `yaml:"options"`
|
Options Options `yaml:"options"`
|
||||||
Labels Labels `yaml:"labels"`
|
Labels Labels `yaml:"labels"`
|
||||||
|
Created time.Time `yaml:"created"`
|
||||||
// Add new values to the toConfig/fromConfig functions.
|
// Add new values to the toConfig/fromConfig functions.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,6 +270,7 @@ func fromConfig(c Config) (f Function) {
|
||||||
Annotations: c.Annotations,
|
Annotations: c.Annotations,
|
||||||
Options: c.Options,
|
Options: c.Options,
|
||||||
Labels: c.Labels,
|
Labels: c.Labels,
|
||||||
|
Created: c.Created,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +292,7 @@ func toConfig(f Function) Config {
|
||||||
Annotations: f.Annotations,
|
Annotations: f.Annotations,
|
||||||
Options: f.Options,
|
Options: f.Options,
|
||||||
Labels: f.Labels,
|
Labels: f.Labels,
|
||||||
|
Created: f.Created,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Function struct {
|
type Function struct {
|
||||||
|
@ -75,6 +76,11 @@ type Function struct {
|
||||||
|
|
||||||
// Health endpoints specified by the language pack
|
// Health endpoints specified by the language pack
|
||||||
HealthEndpoints HealthEndpoints
|
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
|
// NewFunction loads a Function from a path on disk. use .Initialized() to determine if
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
"envs",
|
"envs",
|
||||||
"annotations",
|
"annotations",
|
||||||
"options",
|
"options",
|
||||||
"labels"
|
"labels",
|
||||||
|
"created"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": {
|
"name": {
|
||||||
|
@ -96,6 +97,10 @@
|
||||||
"$ref": "#/definitions/Label"
|
"$ref": "#/definitions/Label"
|
||||||
},
|
},
|
||||||
"type": "array"
|
"type": "array"
|
||||||
|
},
|
||||||
|
"created": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|
Loading…
Reference in New Issue