diff --git a/pkg/crd/gen.go b/pkg/crd/gen.go index c6c5f88b8..32a5d77d4 100644 --- a/pkg/crd/gen.go +++ b/pkg/crd/gen.go @@ -153,7 +153,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } else { fileName = fmt.Sprintf("%s_%s.%s.yaml", crdRaw.Spec.Group, crdRaw.Spec.Names.Plural, crdVersions[i]) } - if err := ctx.WriteYAML(fileName, []interface{}{crd}, genall.WithTransform(transformRemoveCRDStatus)); err != nil { + if err := ctx.WriteYAML(fileName, []interface{}{crd}, genall.WithTransform(transformRemoveCRDStatus), genall.WithTransform(genall.TransformRemoveCreationTimestamp)); err != nil { return err } } diff --git a/pkg/crd/testdata/gen/bar.example.com_foos.v1beta1.yaml b/pkg/crd/testdata/gen/bar.example.com_foos.v1beta1.yaml index c0626821b..e7bee22c9 100644 --- a/pkg/crd/testdata/gen/bar.example.com_foos.v1beta1.yaml +++ b/pkg/crd/testdata/gen/bar.example.com_foos.v1beta1.yaml @@ -4,7 +4,6 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - creationTimestamp: null name: foos.bar.example.com spec: group: bar.example.com diff --git a/pkg/crd/testdata/gen/bar.example.com_foos.yaml b/pkg/crd/testdata/gen/bar.example.com_foos.yaml index e20c13965..e4cfca302 100644 --- a/pkg/crd/testdata/gen/bar.example.com_foos.yaml +++ b/pkg/crd/testdata/gen/bar.example.com_foos.yaml @@ -4,7 +4,6 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - creationTimestamp: null name: foos.bar.example.com spec: group: bar.example.com diff --git a/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.v1beta1.yaml b/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.v1beta1.yaml index 2de49adb5..207bb0230 100644 --- a/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.v1beta1.yaml +++ b/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.v1beta1.yaml @@ -4,7 +4,6 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - creationTimestamp: null name: zoos.bar.example.com spec: group: bar.example.com diff --git a/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.yaml b/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.yaml index 7721bd6a0..7509cc0ce 100644 --- a/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.yaml +++ b/pkg/crd/testdata/gen/zoo/bar.example.com_zooes.yaml @@ -4,7 +4,6 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - creationTimestamp: null name: zooes.bar.example.com spec: group: bar.example.com diff --git a/pkg/crd/testdata/plural/plural.example.com_testquotas.yaml b/pkg/crd/testdata/plural/plural.example.com_testquotas.yaml index 646179112..ba72ef4bd 100644 --- a/pkg/crd/testdata/plural/plural.example.com_testquotas.yaml +++ b/pkg/crd/testdata/plural/plural.example.com_testquotas.yaml @@ -5,7 +5,6 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - creationTimestamp: null name: testquotas.plural.example.com spec: group: plural.example.com diff --git a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml index b3c7ab1dd..ce3163cba 100644 --- a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml +++ b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml @@ -6,7 +6,6 @@ metadata: controller-gen.kubebuilder.io/version: (devel) api-approved.kubernetes.io: https://github.com/kubernetes-sigs/controller-tools cert-manager.io/inject-ca-from-secret: cert-manager/cert-manager-webhook-ca - creationTimestamp: null name: cronjobs.testdata.kubebuilder.io spec: group: testdata.kubebuilder.io diff --git a/pkg/crd/testdata/testdata.kubebuilder.io_jobs.yaml b/pkg/crd/testdata/testdata.kubebuilder.io_jobs.yaml index e4eed5463..3729af3ed 100644 --- a/pkg/crd/testdata/testdata.kubebuilder.io_jobs.yaml +++ b/pkg/crd/testdata/testdata.kubebuilder.io_jobs.yaml @@ -4,7 +4,6 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - creationTimestamp: null name: jobs.testdata.kubebuilder.io spec: group: testdata.kubebuilder.io diff --git a/pkg/genall/genall.go b/pkg/genall/genall.go index 63afbac07..8e676d2f6 100644 --- a/pkg/genall/genall.go +++ b/pkg/genall/genall.go @@ -133,6 +133,13 @@ func WithTransform(transform func(obj map[string]interface{}) error) *WriteYAMLO } } +// TransformRemoveCreationTimestamp ensures we do not write the metadata.creationTimestamp field. +func TransformRemoveCreationTimestamp(obj map[string]interface{}) error { + metadata := obj["metadata"].(map[interface{}]interface{}) + delete(metadata, "creationTimestamp") + return nil +} + // WriteYAML writes the given objects out, serialized as YAML, using the // context's OutputRule. Objects are written as separate documents, separated // from each other by `---` (as per the YAML spec). diff --git a/pkg/rbac/parser.go b/pkg/rbac/parser.go index c2a24f471..bc5e05a08 100644 --- a/pkg/rbac/parser.go +++ b/pkg/rbac/parser.go @@ -263,5 +263,5 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { return nil } - return ctx.WriteYAML("role.yaml", objs) + return ctx.WriteYAML("role.yaml", objs, genall.WithTransform(genall.TransformRemoveCreationTimestamp)) } diff --git a/pkg/rbac/testdata/role.yaml b/pkg/rbac/testdata/role.yaml index 892f09d65..3c3d01a81 100644 --- a/pkg/rbac/testdata/role.yaml +++ b/pkg/rbac/testdata/role.yaml @@ -3,7 +3,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - creationTimestamp: null name: manager-role rules: - apiGroups: @@ -58,7 +57,6 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - creationTimestamp: null name: manager-role namespace: park rules: @@ -73,7 +71,6 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - creationTimestamp: null name: manager-role namespace: zoo rules: diff --git a/pkg/webhook/parser.go b/pkg/webhook/parser.go index a76dcdcbb..a809cca5c 100644 --- a/pkg/webhook/parser.go +++ b/pkg/webhook/parser.go @@ -412,7 +412,7 @@ func (Generator) Generate(ctx *genall.GenerationContext) error { } else { fileName = fmt.Sprintf("manifests.%s.yaml", k) } - if err := ctx.WriteYAML(fileName, v); err != nil { + if err := ctx.WriteYAML(fileName, v, genall.WithTransform(genall.TransformRemoveCreationTimestamp)); err != nil { return err } } diff --git a/pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/manifests.yaml b/pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/manifests.yaml index 059794d6d..cdd9689a7 100644 --- a/pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/manifests.yaml +++ b/pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/manifests.yaml @@ -2,7 +2,6 @@ apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: - creationTimestamp: null name: mutating-webhook-configuration webhooks: - admissionReviewVersions: @@ -31,7 +30,6 @@ webhooks: apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: - creationTimestamp: null name: validating-webhook-configuration webhooks: - admissionReviewVersions: diff --git a/pkg/webhook/testdata/invalid-sideEffects/manifests.yaml b/pkg/webhook/testdata/invalid-sideEffects/manifests.yaml index 059794d6d..cdd9689a7 100644 --- a/pkg/webhook/testdata/invalid-sideEffects/manifests.yaml +++ b/pkg/webhook/testdata/invalid-sideEffects/manifests.yaml @@ -2,7 +2,6 @@ apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: - creationTimestamp: null name: mutating-webhook-configuration webhooks: - admissionReviewVersions: @@ -31,7 +30,6 @@ webhooks: apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: - creationTimestamp: null name: validating-webhook-configuration webhooks: - admissionReviewVersions: diff --git a/pkg/webhook/testdata/invalid-v1beta1NotSupported/manifests.yaml b/pkg/webhook/testdata/invalid-v1beta1NotSupported/manifests.yaml index 059794d6d..cdd9689a7 100644 --- a/pkg/webhook/testdata/invalid-v1beta1NotSupported/manifests.yaml +++ b/pkg/webhook/testdata/invalid-v1beta1NotSupported/manifests.yaml @@ -2,7 +2,6 @@ apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: - creationTimestamp: null name: mutating-webhook-configuration webhooks: - admissionReviewVersions: @@ -31,7 +30,6 @@ webhooks: apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: - creationTimestamp: null name: validating-webhook-configuration webhooks: - admissionReviewVersions: diff --git a/pkg/webhook/testdata/manifests.yaml b/pkg/webhook/testdata/manifests.yaml index ab4fdc85f..18e13ab72 100644 --- a/pkg/webhook/testdata/manifests.yaml +++ b/pkg/webhook/testdata/manifests.yaml @@ -2,7 +2,6 @@ apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: - creationTimestamp: null name: mutating-webhook-configuration webhooks: - admissionReviewVersions: @@ -32,7 +31,6 @@ webhooks: apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: - creationTimestamp: null name: validating-webhook-configuration webhooks: - admissionReviewVersions: diff --git a/pkg/webhook/testdata/valid/manifests.yaml b/pkg/webhook/testdata/valid/manifests.yaml index ce3836ddd..6c7329a0f 100644 --- a/pkg/webhook/testdata/valid/manifests.yaml +++ b/pkg/webhook/testdata/valid/manifests.yaml @@ -2,7 +2,6 @@ apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: - creationTimestamp: null name: mutating-webhook-configuration webhooks: - admissionReviewVersions: @@ -32,7 +31,6 @@ webhooks: apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: - creationTimestamp: null name: validating-webhook-configuration webhooks: - admissionReviewVersions: