From 6f13dfa9bc47aa1f15b9b1250e58a9bfddb14957 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Tue, 19 Jan 2021 14:11:21 +0530 Subject: [PATCH 1/5] Ignore serviceUID and configUID labels in service export result While exporting the service using `service export` command, ignore the service labels with keys 'configUID' and `configUID` see https://github.com/knative/serving/pull/10539 for further details. --- pkg/kn/commands/service/export.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/kn/commands/service/export.go b/pkg/kn/commands/service/export.go index 55326677b0..b175ba63f8 100644 --- a/pkg/kn/commands/service/export.go +++ b/pkg/kn/commands/service/export.go @@ -45,6 +45,13 @@ var IGNORED_REVISION_ANNOTATIONS = []string{ "serving.knative.dev/routingStateModified", } +// IGNORED_SERVICE_LABELS defines the label keys which should be removed +// from service labels before exporting it +var IGNORED_SERVICE_LABELS = []string{ + "serving.knative.dev/configUID", + "serving.knative.dev/serviceUID", +} + // NewServiceExportCommand returns a new command for exporting a service. func NewServiceExportCommand(p *commands.KnParams) *cobra.Command { @@ -161,6 +168,7 @@ func exportLatestService(latestSvc *servingv1.Service, withRoutes bool) *serving } stripIgnoredAnnotationsFromService(&exportedSvc) + stripIgnoredLabelsFromService(&exportedSvc) return &exportedSvc } @@ -333,3 +341,9 @@ func stripIgnoredAnnotationsFromRevision(revision *servingv1.Revision) { delete(revision.ObjectMeta.Annotations, annotation) } } + +func stripIgnoredLabelsFromService(svc *servingv1.Service) { + for _, label := range IGNORED_SERVICE_LABELS { + delete(svc.ObjectMeta.Labels, label) + } +} From cc37a7bca41e098a0007eea6008f3b8241b2902f Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Tue, 19 Jan 2021 14:24:50 +0530 Subject: [PATCH 2/5] Fix the var names per golint recommendation --- pkg/kn/commands/service/export.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/kn/commands/service/export.go b/pkg/kn/commands/service/export.go index b175ba63f8..d2fc2ff938 100644 --- a/pkg/kn/commands/service/export.go +++ b/pkg/kn/commands/service/export.go @@ -34,20 +34,25 @@ import ( servingv1 "knative.dev/serving/pkg/apis/serving/v1" ) -var IGNORED_SERVICE_ANNOTATIONS = []string{ +// IgnoredServiceAnnotations defines the annotation keys which should be +// removed from service annotations before export +var IgnoredServiceAnnotations = []string{ "serving.knative.dev/creator", "serving.knative.dev/lastModifier", "kubectl.kubernetes.io/last-applied-configuration", } -var IGNORED_REVISION_ANNOTATIONS = []string{ + +// IgnoredRevisionAnnotations defines the annotation keys which should be +// removed from revision annotations before export +var IgnoredRevisionAnnotations = []string{ "serving.knative.dev/lastPinned", "serving.knative.dev/creator", "serving.knative.dev/routingStateModified", } -// IGNORED_SERVICE_LABELS defines the label keys which should be removed -// from service labels before exporting it -var IGNORED_SERVICE_LABELS = []string{ +// IgnoredServiceLabels defines the label keys which should be removed +// from service labels before export +var IgnoredServiceLabels = []string{ "serving.knative.dev/configUID", "serving.knative.dev/serviceUID", } @@ -331,19 +336,19 @@ func revisionListSortFunc(revisionList *servingv1.RevisionList) func(i int, j in } func stripIgnoredAnnotationsFromService(svc *servingv1.Service) { - for _, annotation := range IGNORED_SERVICE_ANNOTATIONS { + for _, annotation := range IgnoredServiceAnnotations { delete(svc.ObjectMeta.Annotations, annotation) } } func stripIgnoredAnnotationsFromRevision(revision *servingv1.Revision) { - for _, annotation := range IGNORED_REVISION_ANNOTATIONS { + for _, annotation := range IgnoredRevisionAnnotations { delete(revision.ObjectMeta.Annotations, annotation) } } func stripIgnoredLabelsFromService(svc *servingv1.Service) { - for _, label := range IGNORED_SERVICE_LABELS { + for _, label := range IgnoredServiceLabels { delete(svc.ObjectMeta.Labels, label) } } From ceaadfc146142b8a5441aebb0a3acfaa04f6f173 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Tue, 19 Jan 2021 15:23:19 +0530 Subject: [PATCH 3/5] Ignore the serviceUID and configUID labels from revision labels --- pkg/kn/commands/service/export.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/kn/commands/service/export.go b/pkg/kn/commands/service/export.go index d2fc2ff938..f8e92b0bbd 100644 --- a/pkg/kn/commands/service/export.go +++ b/pkg/kn/commands/service/export.go @@ -57,6 +57,13 @@ var IgnoredServiceLabels = []string{ "serving.knative.dev/serviceUID", } +// IgnoredRevisionLabels defines the label keys which should be removed +// from revision labels before export +var IgnoredRevisionLabels = []string{ + "serving.knative.dev/configUID", + "serving.knative.dev/serviceUID", +} + // NewServiceExportCommand returns a new command for exporting a service. func NewServiceExportCommand(p *commands.KnParams) *cobra.Command { @@ -174,7 +181,6 @@ func exportLatestService(latestSvc *servingv1.Service, withRoutes bool) *serving stripIgnoredAnnotationsFromService(&exportedSvc) stripIgnoredLabelsFromService(&exportedSvc) - return &exportedSvc } @@ -190,6 +196,7 @@ func exportRevision(revision *servingv1.Revision) servingv1.Revision { exportedRevision.Spec = revision.Spec stripIgnoredAnnotationsFromRevision(&exportedRevision) + stripIgnoredLabelsFromRevision(&exportedRevision) return exportedRevision } @@ -352,3 +359,9 @@ func stripIgnoredLabelsFromService(svc *servingv1.Service) { delete(svc.ObjectMeta.Labels, label) } } + +func stripIgnoredLabelsFromRevision(rev *servingv1.Revision) { + for _, label := range IgnoredRevisionLabels { + delete(rev.ObjectMeta.Labels, label) + } +} From b5aee52edcb2622030687af000504874e88286a9 Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Tue, 19 Jan 2021 17:45:40 +0530 Subject: [PATCH 4/5] Add e2e for verifying configUID and serviceUID labels are absent --- test/e2e/service_export_test.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/e2e/service_export_test.go b/test/e2e/service_export_test.go index d15a9bd9d4..f17c9766f2 100644 --- a/test/e2e/service_export_test.go +++ b/test/e2e/service_export_test.go @@ -226,9 +226,30 @@ func TestServiceExport(t *testing.T) { test.WithRevisionEnv(corev1.EnvVar{Name: "a", Value: "mouse"}), ))), ), "--with-revisions", "--mode", "export", "-o", "yaml") + + t.Log("create and export service 'foo' and verify that serviceUID and configUID labels are absent") + serviceCreateWithOptions(r, "foo") + output := serviceExportOutput(r, "foo", "-o", "json") + actSvc := servingv1.Service{} + err = json.Unmarshal([]byte(output), &actSvc) + assert.NilError(t, err) + _, ok := actSvc.Labels["serving.knative.dev/serviceUID"] + assert.Equal(t, ok, false) + _, ok = actSvc.Labels["serving.knative.dev/configUID"] + assert.Equal(t, ok, false) + _, ok = actSvc.Spec.ConfigurationSpec.Template.Labels["serving.knative.dev/servingUID"] + assert.Equal(t, ok, false) + _, ok = actSvc.Spec.ConfigurationSpec.Template.Labels["serving.knative.dev/configUID"] + assert.Equal(t, ok, false) } -// Private methods +// serviceExportOutput returns the export output of given service +func serviceExportOutput(r *test.KnRunResultCollector, serviceName string, options ...string) string { + command := []string{"service", "export", serviceName} + command = append(command, options...) + out := r.KnTest().Kn().Run(command...) + return out.Stdout +} func serviceExport(r *test.KnRunResultCollector, serviceName string, expService *servingv1.Service, options ...string) { command := []string{"service", "export", serviceName} @@ -254,8 +275,6 @@ func serviceExportWithRevisionList(r *test.KnRunResultCollector, serviceName str r.AssertNoError(out) } -// Private functions - func validateExportedService(t *testing.T, it *test.KnTest, out string, expService *servingv1.Service) { actSvc := servingv1.Service{} err := json.Unmarshal([]byte(out), &actSvc) From 75b214fcd351270be36505854c595a699a9d270c Mon Sep 17 00:00:00 2001 From: Navid Shaikh Date: Tue, 19 Jan 2021 18:44:59 +0530 Subject: [PATCH 5/5] Add CHANGELOG --- CHANGELOG.adoc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 755c28fd6d..7cef303949 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -12,6 +12,16 @@ | https://github.com/knative/client/pull/[#] //// +## Unreleased +[cols="1,10,3", options="header", width="100%"] +|=== +| | Description | PR + +| 🐣 +| Do not print serviceUID and configUID labels in service export result +| https://github.com/knative/client/pull/1194[#1194] +|=== + ## v0.20.0 (2021-01-14) [cols="1,10,3", options="header", width="100%"] |===