From 6c5a75bf733299686aba053499042274c204b6d6 Mon Sep 17 00:00:00 2001 From: liuhuiping Date: Tue, 18 Sep 2018 18:10:45 +0800 Subject: [PATCH] remove metadata.creationTimestamp field from configMapGenerator --- .gitignore | 1 + pkg/app/application_test.go | 2 -- pkg/commands/testdata/testcase-configmaps/expected.yaml | 2 -- .../testcase-multiple-patches-noconflict/expected.yaml | 2 -- pkg/commands/testdata/testcase-simple/expected.yaml | 3 --- .../testdata/testcase-single-overlay/expected.yaml | 3 --- .../testdata/testcase-variable-ref/expected.yaml | 1 - pkg/configmapandsecret/configmapfactory.go | 2 ++ pkg/configmapandsecret/configmapfactory_test.go | 3 +-- pkg/resmap/configmap_test.go | 9 +++------ pkg/resmap/secret_test.go | 6 ++---- pkg/resource/resource.go | 3 +++ 12 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index f1c181ec9..73dba7766 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +kustomize # Test binary, build with `go test -c` *.test diff --git a/pkg/app/application_test.go b/pkg/app/application_test.go index 659700aeb..b18da7fa0 100644 --- a/pkg/app/application_test.go +++ b/pkg/app/application_test.go @@ -159,7 +159,6 @@ func TestResources1(t *testing.T) { "annotations": map[string]interface{}{ "note": "This is a test annotation", }, - "creationTimestamp": nil, }, "data": map[string]interface{}{ "DB_USERNAME": "admin", @@ -179,7 +178,6 @@ func TestResources1(t *testing.T) { "annotations": map[string]interface{}{ "note": "This is a test annotation", }, - "creationTimestamp": nil, }, "type": string(corev1.SecretTypeOpaque), "data": map[string]interface{}{ diff --git a/pkg/commands/testdata/testcase-configmaps/expected.yaml b/pkg/commands/testdata/testcase-configmaps/expected.yaml index be56db9c2..59656f4ee 100644 --- a/pkg/commands/testdata/testcase-configmaps/expected.yaml +++ b/pkg/commands/testdata/testcase-configmaps/expected.yaml @@ -6,7 +6,6 @@ data: kind: ConfigMap metadata: annotations: {} - creationTimestamp: null labels: {} name: p1-com1-dhbbm922gd --- @@ -16,6 +15,5 @@ data: kind: ConfigMap metadata: annotations: {} - creationTimestamp: null labels: {} name: p2-com2-c4b8md75k9 diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.yaml b/pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.yaml index 743f93bde..2404ec1c9 100644 --- a/pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.yaml +++ b/pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.yaml @@ -5,7 +5,6 @@ kind: ConfigMap metadata: annotations: note: This is a test annotation - creationTimestamp: null labels: app: mynginx env: staging @@ -18,7 +17,6 @@ data: hello: world kind: ConfigMap metadata: - creationTimestamp: null labels: env: staging name: staging-configmap-in-overlay-k7cbc75tg8 diff --git a/pkg/commands/testdata/testcase-simple/expected.yaml b/pkg/commands/testdata/testcase-simple/expected.yaml index af067bfd0..f36471e2e 100644 --- a/pkg/commands/testdata/testcase-simple/expected.yaml +++ b/pkg/commands/testdata/testcase-simple/expected.yaml @@ -7,7 +7,6 @@ kind: ConfigMap metadata: annotations: note: This is a test annotation - creationTimestamp: null labels: app: mungebot org: kubernetes @@ -22,7 +21,6 @@ kind: ConfigMap metadata: annotations: note: This is a test annotation - creationTimestamp: null labels: app: mungebot org: kubernetes @@ -37,7 +35,6 @@ kind: Secret metadata: annotations: note: This is a test annotation - creationTimestamp: null labels: app: mungebot org: kubernetes diff --git a/pkg/commands/testdata/testcase-single-overlay/expected.yaml b/pkg/commands/testdata/testcase-single-overlay/expected.yaml index 91f209111..9a6fcac31 100644 --- a/pkg/commands/testdata/testcase-single-overlay/expected.yaml +++ b/pkg/commands/testdata/testcase-single-overlay/expected.yaml @@ -5,7 +5,6 @@ kind: ConfigMap metadata: annotations: note: This is a test annotation - creationTimestamp: null labels: app: mynginx env: staging @@ -18,7 +17,6 @@ data: hello: world kind: ConfigMap metadata: - creationTimestamp: null labels: env: staging team: override-foo @@ -33,7 +31,6 @@ kind: Secret metadata: annotations: note: This is a test annotation - creationTimestamp: null labels: app: mynginx env: staging diff --git a/pkg/commands/testdata/testcase-variable-ref/expected.yaml b/pkg/commands/testdata/testcase-variable-ref/expected.yaml index cb60233e6..ab030bf5b 100644 --- a/pkg/commands/testdata/testcase-variable-ref/expected.yaml +++ b/pkg/commands/testdata/testcase-variable-ref/expected.yaml @@ -72,7 +72,6 @@ data: foo: bar kind: ConfigMap metadata: - creationTimestamp: null name: dev-base-test-config-map-b2g2dmd64b --- apiVersion: v1 diff --git a/pkg/configmapandsecret/configmapfactory.go b/pkg/configmapandsecret/configmapfactory.go index 33407071a..caf81f66e 100644 --- a/pkg/configmapandsecret/configmapfactory.go +++ b/pkg/configmapandsecret/configmapfactory.go @@ -26,6 +26,7 @@ import ( "github.com/pkg/errors" "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation" @@ -70,6 +71,7 @@ func objectToUnstructured(in runtime.Object) (*unstructured.Unstructured, error) } var out unstructured.Unstructured err = out.UnmarshalJSON(marshaled) + out.SetCreationTimestamp(metav1.Time{}) return &out, err } diff --git a/pkg/configmapandsecret/configmapfactory_test.go b/pkg/configmapandsecret/configmapfactory_test.go index 03fd9c4f9..8dbda254d 100644 --- a/pkg/configmapandsecret/configmapfactory_test.go +++ b/pkg/configmapandsecret/configmapfactory_test.go @@ -50,8 +50,7 @@ func makeUnstructuredEnvConfigMap(name string) *unstructured.Unstructured { "apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{ - "name": name, - "creationTimestamp": nil, + "name": name, }, "data": map[string]interface{}{ "DB_USERNAME": "admin", diff --git a/pkg/resmap/configmap_test.go b/pkg/resmap/configmap_test.go index 8a06be6c5..26fb310d3 100644 --- a/pkg/resmap/configmap_test.go +++ b/pkg/resmap/configmap_test.go @@ -60,8 +60,7 @@ func TestNewFromConfigMaps(t *testing.T) { "apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{ - "name": "envConfigMap", - "creationTimestamp": nil, + "name": "envConfigMap", }, "data": map[string]interface{}{ "DB_USERNAME": "admin", @@ -87,8 +86,7 @@ func TestNewFromConfigMaps(t *testing.T) { "apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{ - "name": "fileConfigMap", - "creationTimestamp": nil, + "name": "fileConfigMap", }, "data": map[string]interface{}{ "app-init.ini": `FOO=bar @@ -114,8 +112,7 @@ BAR=baz "apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{ - "name": "literalConfigMap", - "creationTimestamp": nil, + "name": "literalConfigMap", }, "data": map[string]interface{}{ "a": "x", diff --git a/pkg/resmap/secret_test.go b/pkg/resmap/secret_test.go index a3d48c0a1..ee573431d 100644 --- a/pkg/resmap/secret_test.go +++ b/pkg/resmap/secret_test.go @@ -66,8 +66,7 @@ func TestNewResMapFromSecretArgs(t *testing.T) { "apiVersion": "v1", "kind": "Secret", "metadata": map[string]interface{}{ - "name": "apple", - "creationTimestamp": nil, + "name": "apple", }, "type": string(corev1.SecretTypeOpaque), "data": map[string]interface{}{ @@ -80,8 +79,7 @@ func TestNewResMapFromSecretArgs(t *testing.T) { "apiVersion": "v1", "kind": "Secret", "metadata": map[string]interface{}{ - "name": "peanuts", - "creationTimestamp": nil, + "name": "peanuts", }, "type": string(corev1.SecretTypeOpaque), "data": map[string]interface{}{ diff --git a/pkg/resource/resource.go b/pkg/resource/resource.go index ad9b3c2e7..e8dc88f3e 100644 --- a/pkg/resource/resource.go +++ b/pkg/resource/resource.go @@ -23,6 +23,7 @@ import ( "strings" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" ) @@ -43,6 +44,8 @@ func NewResourceWithBehavior(obj runtime.Object, b GenerationBehavior) (*Resourc } var u unstructured.Unstructured err = u.UnmarshalJSON(marshaled) + // creationTimestamp always 'null', remove it + u.SetCreationTimestamp(metav1.Time{}) return &Resource{Unstructured: u, b: b}, err }