Skip to content

Commit

Permalink
Add upgrade test for new defaults (#6165)
Browse files Browse the repository at this point in the history
* Add upgrade test for new defaults

This adds a new test using BYO Revision name to make sure that the
immutability contract is not violated by adding new defaults to the
Service template.

Fixes #6077

* CR comments
  • Loading branch information
Dan Gerdesmeier authored and knative-prow-robot committed Dec 5, 2019
1 parent ca12f57 commit 5c1e198
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
28 changes: 26 additions & 2 deletions test/upgrade/service_postupgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import (
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/ptr"
ptest "knative.dev/pkg/test"
"knative.dev/serving/pkg/apis/serving/v1"
serviceresourcenames "knative.dev/serving/pkg/reconciler/service/resources/names"
"knative.dev/serving/test"
"knative.dev/serving/test/e2e"
v1test "knative.dev/serving/test/v1"
v1a1test "knative.dev/serving/test/v1alpha1"
)

Expand All @@ -39,11 +42,32 @@ func TestRunLatestServicePostUpgradeFromScaleToZero(t *testing.T) {
updateService(scaleToZeroServiceName, t)
}

// TestBYORevisionPostUpgrade attempts to update the RouteSpec of a Service using BYO Revision name. This
// test is meant to catch new defaults that break the immutability of BYO Revision name.
func TestBYORevisionPostUpgrade(t *testing.T) {
t.Parallel()
clients := e2e.Setup(t)
names := test.ResourceNames{
Service: byoServiceName,
}

if _, err := v1test.UpdateServiceRouteSpec(t, clients, names, v1.RouteSpec{
Traffic: []v1.TrafficTarget{{
Tag: "example-tag",
RevisionName: byoRevName,
Percent: ptr.Int64(100),
}},
}); err != nil {
t.Fatalf("Failed to update Service: %v", err)
}
}

func updateService(serviceName string, t *testing.T) {
t.Helper()
clients := e2e.Setup(t)
var names test.ResourceNames
names.Service = serviceName
names := test.ResourceNames{
Service: serviceName,
}

t.Logf("Getting service %q", names.Service)
svc, err := clients.ServingAlphaClient.Services.Get(names.Service, metav1.GetOptions{})
Expand Down
21 changes: 21 additions & 0 deletions test/upgrade/service_preupgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (
"testing"

"knative.dev/serving/pkg/apis/autoscaling"
"knative.dev/serving/pkg/apis/serving/v1"
revisionresourcenames "knative.dev/serving/pkg/reconciler/revision/resources/names"
rtesting "knative.dev/serving/pkg/testing/v1alpha1"
"knative.dev/serving/test"
"knative.dev/serving/test/e2e"
v1test "knative.dev/serving/test/v1"
v1a1test "knative.dev/serving/test/v1alpha1"
)

Expand Down Expand Up @@ -72,3 +74,22 @@ func TestRunLatestServicePreUpgradeAndScaleToZero(t *testing.T) {
t.Fatalf("Could not scale to zero: %v", err)
}
}

// TestBYORevisionUpgrade creates a Service that uses the BYO Revision name functionality. This test
// is meant to catch new defaults that break bring your own revision name immutability.
func TestBYORevisionPreUpgrade(t *testing.T) {
t.Parallel()
clients := e2e.Setup(t)
names := test.ResourceNames{
Service: byoServiceName,
Image: test.PizzaPlanet1,
}

_, err := v1test.CreateServiceReady(t, clients, &names,
func(svc *v1.Service) {
svc.Spec.ConfigurationSpec.Template.Name = byoRevName
})
if err != nil {
t.Fatalf("Failed to create Service: %v", err)
}
}
2 changes: 2 additions & 0 deletions test/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
// multiple "go test" invocations.
serviceName = "pizzaplanet-upgrade-service"
scaleToZeroServiceName = "scale-to-zero-upgrade-service"
byoServiceName = "byo-revision-name-upgrade-test"
byoRevName = byoServiceName + "-" + "rev1"
)

// Shamelessly cribbed from conformance/service_test.
Expand Down

0 comments on commit 5c1e198

Please sign in to comment.