Skip to content

Commit

Permalink
fix: Fix service export annotations (knative#1004)
Browse files Browse the repository at this point in the history
* fix: Fix service export annotations

* fix: Regen code

* fix: Skip test until 0.18 is available

* fix: Skip on specific version only
  • Loading branch information
dsimansk authored and rhuss committed Oct 5, 2020
1 parent 22ffd28 commit 89124ea
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/kn/commands/service/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var IGNORED_SERVICE_ANNOTATIONS = []string{
var IGNORED_REVISION_ANNOTATIONS = []string{
"serving.knative.dev/lastPinned",
"serving.knative.dev/creator",
"serving.knative.dev/routingStateModified",
}

// NewServiceExportCommand returns a new command for exporting a service.
Expand Down
45 changes: 38 additions & 7 deletions test/e2e/service_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package e2e

import (
"encoding/json"
"os"
"strings"
"testing"

"gotest.tools/assert"
Expand All @@ -43,6 +45,10 @@ type expectedKNExportOption func(*clientv1alpha1.Export)
type podSpecOption func(*corev1.PodSpec)

func TestServiceExport(t *testing.T) {
//FIXME: enable once 0.18 is available
if strings.HasPrefix(os.Getenv("KNATIVE_SERVING_VERSION"), "0.17") {
t.Skip("The test is skipped on Serving version 0.17")
}
t.Parallel()
it, err := test.NewKnTest()
assert.NilError(t, err)
Expand All @@ -60,7 +66,9 @@ func TestServiceExport(t *testing.T) {
serviceExport(r, "hello", getServiceWithOptions(
withServiceName("hello"),
withServiceRevisionName("hello-rev1"),
withConfigurationAnnotations(),
withConfigurationAnnotations(map[string]string{
"client.knative.dev/user-image": pkgtest.ImagePath("helloworld"),
}),
withServicePodSpecOption(withContainer()),
), "-o", "json")

Expand Down Expand Up @@ -107,7 +115,10 @@ func TestServiceExport(t *testing.T) {
withServices(
withServiceName("hello"),
withServiceRevisionName("hello-rev1"),
withConfigurationAnnotations(),
withConfigurationAnnotations(map[string]string{
"client.knative.dev/user-image": pkgtest.ImagePath("helloworld"),
"serving.knative.dev/routes": "hello",
}),
withServicePodSpecOption(
withContainer(),
),
Expand Down Expand Up @@ -138,12 +149,14 @@ func TestServiceExport(t *testing.T) {
withRevisionAnnotations(
map[string]string{
"client.knative.dev/user-image": pkgtest.ImagePath("helloworld"),
"serving.knative.dev/routes": "hello",
}),
withRevisionLabels(
map[string]string{
"serving.knative.dev/configuration": "hello",
"serving.knative.dev/configurationGeneration": "1",
"serving.knative.dev/route": "hello",
"serving.knative.dev/routingState": "active",
"serving.knative.dev/service": "hello",
}),
withRevisionPodSpecOption(
Expand All @@ -160,7 +173,10 @@ func TestServiceExport(t *testing.T) {
serviceExportWithServiceList(r, "hello", getServiceListWithOptions(
withServices(
withServiceName("hello"),
withConfigurationAnnotations(),
withConfigurationAnnotations(map[string]string{
"client.knative.dev/user-image": pkgtest.ImagePath("helloworld"),
"serving.knative.dev/routes": "hello",
}),
withServiceRevisionName("hello-rev1"),
withServicePodSpecOption(
withContainer(),
Expand All @@ -169,6 +185,9 @@ func TestServiceExport(t *testing.T) {
withServices(
withServiceName("hello"),
withServiceRevisionName("hello-rev2"),
withConfigurationAnnotations(map[string]string{
"serving.knative.dev/routes": "hello",
}),
withServicePodSpecOption(
withContainer(),
withEnv([]corev1.EnvVar{{Name: "a", Value: "mouse"}}),
Expand Down Expand Up @@ -200,12 +219,14 @@ func TestServiceExport(t *testing.T) {
withRevisionAnnotations(
map[string]string{
"client.knative.dev/user-image": pkgtest.ImagePath("helloworld"),
"serving.knative.dev/routes": "hello",
}),
withRevisionLabels(
map[string]string{
"serving.knative.dev/configuration": "hello",
"serving.knative.dev/configurationGeneration": "1",
"serving.knative.dev/route": "hello",
"serving.knative.dev/routingState": "active",
"serving.knative.dev/service": "hello",
}),
withRevisionPodSpecOption(
Expand All @@ -214,11 +235,16 @@ func TestServiceExport(t *testing.T) {
),
withRevisions(
withRevisionName("hello-rev2"),
withRevisionAnnotations(
map[string]string{
"serving.knative.dev/routes": "hello",
}),
withRevisionLabels(
map[string]string{
"serving.knative.dev/configuration": "hello",
"serving.knative.dev/configurationGeneration": "2",
"serving.knative.dev/route": "hello",
"serving.knative.dev/routingState": "active",
"serving.knative.dev/service": "hello",
}),
withRevisionPodSpecOption(
Expand All @@ -236,6 +262,9 @@ func TestServiceExport(t *testing.T) {
withServices(
withServiceName("hello"),
withServiceRevisionName("hello-rev2"),
withConfigurationAnnotations(map[string]string{
"serving.knative.dev/routes": "hello",
}),
withServicePodSpecOption(
withContainer(),
withEnv([]corev1.EnvVar{{Name: "a", Value: "mouse"}}),
Expand Down Expand Up @@ -264,11 +293,15 @@ func TestServiceExport(t *testing.T) {
), getKNExportWithOptions(
withRevisions(
withRevisionName("hello-rev2"),
withRevisionAnnotations(map[string]string{
"serving.knative.dev/routes": "hello",
}),
withRevisionLabels(
map[string]string{
"serving.knative.dev/configuration": "hello",
"serving.knative.dev/configurationGeneration": "2",
"serving.knative.dev/route": "hello",
"serving.knative.dev/routingState": "active",
"serving.knative.dev/service": "hello",
}),
withRevisionPodSpecOption(
Expand Down Expand Up @@ -397,11 +430,9 @@ func withConfigurationLabels(labels map[string]string) expectedServiceOption {
svc.Spec.Template.ObjectMeta.Labels = labels
}
}
func withConfigurationAnnotations() expectedServiceOption {
func withConfigurationAnnotations(annotations map[string]string) expectedServiceOption {
return func(svc *servingv1.Service) {
svc.Spec.Template.ObjectMeta.Annotations = map[string]string{
"client.knative.dev/user-image": pkgtest.ImagePath("helloworld"),
}
svc.Spec.Template.ObjectMeta.Annotations = annotations
}
}
func withServiceRevisionName(name string) expectedServiceOption {
Expand Down

0 comments on commit 89124ea

Please sign in to comment.