Skip to content

Commit 9cb1a0a

Browse files
committed
Assert against Revision generation annotation instead of config spec
In #475 I removed assertions against Configuration.Spec.Generation b/c it is a hack and not part of the knative spec. In #600 I updated the conformance tests to assert against the Revision annotation which contains the generation. BUT THEN in #778 when I completely re-wrote the tests to no longer use Ginkgo, I accidentally until both of those changes, so this commit puts them back 😅. BONUS: I hit a case where the length of the loadbalancer ingresses was 0 and got a panic, so if that happens again we'll get an informative error instead.
1 parent 9aea1ed commit 9cb1a0a

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

test/conformance/route_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"encoding/json"
2929

30+
"github.com/knative/serving/pkg/apis/serving"
3031
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
3132
"github.com/knative/serving/test"
3233
"github.com/mattbaird/jsonpatch"
@@ -61,17 +62,14 @@ func updateConfigWithImage(clients *test.Clients, names test.ResourceNames, imag
6162
},
6263
}
6364
patchBytes, err := json.Marshal(patches)
64-
newConfig, err := clients.Configs.Patch(names.Config, types.JSONPatchType, patchBytes, "")
65+
_, err = clients.Configs.Patch(names.Config, types.JSONPatchType, patchBytes, "")
6566
if err != nil {
6667
return err
6768
}
68-
if newConfig.Spec.Generation != int64(2) {
69-
return fmt.Errorf("The spec was updated so the Generation should be 2 but it was actually %d", newConfig.Spec.Generation)
70-
}
7169
return nil
7270
}
7371

74-
func assertResourcesUpdatedWhenRevisionIsReady(t *testing.T, logger *zap.SugaredLogger, clients *test.Clients, names test.ResourceNames, expectedText string) {
72+
func assertResourcesUpdatedWhenRevisionIsReady(t *testing.T, logger *zap.SugaredLogger, clients *test.Clients, names test.ResourceNames, expectedGeneration, expectedText string) {
7573
logger.Infof("When the Route reports as Ready, everything should be ready.")
7674
if err := test.WaitForRouteState(clients.Routes, names.Route, test.IsRouteReady, "RouteIsReady"); err != nil {
7775
t.Fatalf("The Route %s was not marked as Ready to serve traffic to Revision %s: %v", names.Route, names.Revision, err)
@@ -95,6 +93,16 @@ func assertResourcesUpdatedWhenRevisionIsReady(t *testing.T, logger *zap.Sugared
9593
if err != nil {
9694
t.Fatalf("Revision %s did not become ready to serve traffic: %v", names.Revision, err)
9795
}
96+
logger.Infof("The Revision will be annotated with the generation")
97+
err = test.CheckRevisionState(clients.Revisions, names.Revision, func(r *v1alpha1.Revision) (bool, error) {
98+
if a, ok := r.Annotations[serving.ConfigurationGenerationAnnotationKey]; ok {
99+
if a != expectedGeneration {
100+
return true, fmt.Errorf("Expected Revision %s to be annotated with generation %s but was %s instead", names.Revision, expectedGeneration, a)
101+
}
102+
return true, nil
103+
}
104+
return true, fmt.Errorf("Expected Revision %s to be annotated with generation %s but there was no annotation", names.Revision, expectedGeneration)
105+
})
98106
logger.Infof("Updates the Configuration that the Revision is ready")
99107
err = test.CheckConfigurationState(clients.Configs, names.Config, func(c *v1alpha1.Configuration) (bool, error) {
100108
return c.Status.LatestReadyRevisionName == names.Revision, nil
@@ -175,7 +183,7 @@ func TestRouteCreation(t *testing.T) {
175183
}
176184
names.Revision = revisionName
177185

178-
assertResourcesUpdatedWhenRevisionIsReady(t, logger, clients, names, "What a spaceport!")
186+
assertResourcesUpdatedWhenRevisionIsReady(t, logger, clients, names, "1", "What a spaceport!")
179187

180188
logger.Infof("Updating the Configuration to use a different image")
181189
err = updateConfigWithImage(clients, names, imagePaths)
@@ -190,5 +198,5 @@ func TestRouteCreation(t *testing.T) {
190198
}
191199
names.Revision = revisionName
192200

193-
assertResourcesUpdatedWhenRevisionIsReady(t, logger, clients, names, "Re-energize yourself with a slice of pepperoni!")
201+
assertResourcesUpdatedWhenRevisionIsReady(t, logger, clients, names, "2", "Re-energize yourself with a slice of pepperoni!")
194202
}

test/conformance/service_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525
"testing"
2626

27+
"github.com/knative/serving/pkg/apis/serving"
2728
"github.com/knative/serving/pkg/apis/serving/v1alpha1"
2829
serviceresourcenames "github.com/knative/serving/pkg/controller/service/resources/names"
2930
"github.com/knative/serving/test"
@@ -52,18 +53,15 @@ func updateServiceWithImage(clients *test.Clients, names test.ResourceNames, ima
5253
if err != nil {
5354
return err
5455
}
55-
newService, err := clients.Services.Patch(names.Service, types.JSONPatchType, patchBytes, "")
56+
_, err = clients.Services.Patch(names.Service, types.JSONPatchType, patchBytes, "")
5657
if err != nil {
5758
return err
5859
}
59-
if newService.Spec.Generation != int64(2) {
60-
return fmt.Errorf("The spec was updated so the Generation should be 2 but it was actually %d", newService.Spec.Generation)
61-
}
6260
return nil
6361
}
6462

6563
// Shamelessly cribbed from route_test. We expect the Route and Configuration to be ready if the Service is ready.
66-
func assertServiceResourcesUpdated(t *testing.T, logger *zap.SugaredLogger, clients *test.Clients, names test.ResourceNames, routeDomain, expectedText string) {
64+
func assertServiceResourcesUpdated(t *testing.T, logger *zap.SugaredLogger, clients *test.Clients, names test.ResourceNames, routeDomain, expectedGeneration, expectedText string) {
6765
// TODO(#1178): Remove "Wait" from all checks below this point.
6866
err := test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, routeDomain, test.EventuallyMatchesBody(expectedText), "WaitForEndpointToServeText")
6967
if err != nil {
@@ -75,7 +73,16 @@ func assertServiceResourcesUpdated(t *testing.T, logger *zap.SugaredLogger, clie
7573
if err := test.CheckRevisionState(clients.Revisions, names.Revision, test.IsRevisionReady); err != nil {
7674
t.Fatalf("Revision %s did not become ready to serve traffic: %v", names.Revision, err)
7775
}
78-
76+
logger.Infof("The Revision will be annotated with the generation")
77+
err = test.CheckRevisionState(clients.Revisions, names.Revision, func(r *v1alpha1.Revision) (bool, error) {
78+
if a, ok := r.Annotations[serving.ConfigurationGenerationAnnotationKey]; ok {
79+
if a != expectedGeneration {
80+
return true, fmt.Errorf("Expected Revision %s to be annotated with generation %s but was %s instead", names.Revision, expectedGeneration, a)
81+
}
82+
return true, nil
83+
}
84+
return true, fmt.Errorf("Expected Revision %s to be annotated with generation %s but there was no annotation", names.Revision, expectedGeneration)
85+
})
7986
logger.Info("The Service's latestReadyRevisionName should match the Configuration's")
8087
err = test.CheckConfigurationState(clients.Configs, names.Config, func(c *v1alpha1.Configuration) (bool, error) {
8188
return c.Status.LatestReadyRevisionName == names.Revision, nil
@@ -163,7 +170,7 @@ func TestRunLatestService(t *testing.T) {
163170
if err := test.WaitForServiceState(clients.Services, names.Service, test.IsServiceReady, "ServiceIsReady"); err != nil {
164171
t.Fatalf("The Service %s was not marked as Ready to serve traffic to Revision %s: %v", names.Service, names.Revision, err)
165172
}
166-
assertServiceResourcesUpdated(t, logger, clients, names, routeDomain, "What a spaceport!")
173+
assertServiceResourcesUpdated(t, logger, clients, names, routeDomain, "1", "What a spaceport!")
167174

168175
logger.Info("Updating the Service to use a different image")
169176
if err := updateServiceWithImage(clients, names, imagePaths[1]); err != nil {
@@ -181,7 +188,7 @@ func TestRunLatestService(t *testing.T) {
181188
if err := test.WaitForServiceState(clients.Services, names.Service, test.IsServiceReady, "ServiceIsReady"); err != nil {
182189
t.Fatalf("The Service %s was not marked as Ready to serve traffic to Revision %s: %v", names.Service, names.Revision, err)
183190
}
184-
assertServiceResourcesUpdated(t, logger, clients, names, routeDomain, "Re-energize yourself with a slice of pepperoni!")
191+
assertServiceResourcesUpdated(t, logger, clients, names, routeDomain, "2", "Re-energize yourself with a slice of pepperoni!")
185192
}
186193

187194
// TODO(jonjohnsonjr): LatestService roads less traveled.

test/spoof/spoof.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ func New(kubeClientset *kubernetes.Clientset, logger *zap.SugaredLogger, domain
103103
return nil, err
104104
}
105105

106+
if len(ingress.Status.LoadBalancer.Ingress) != 1 {
107+
return nil, fmt.Errorf("Expected exactly one ingress load balancer, instead had %d: %s", len(ingress.Status.LoadBalancer.Ingress), ingress.Status.LoadBalancer.Ingress)
108+
}
109+
106110
if ingress.Status.LoadBalancer.Ingress[0].IP == "" {
107111
return nil, fmt.Errorf("Expected ingress loadbalancer IP for %s to be set, instead was empty", ingressName)
108112
}

0 commit comments

Comments
 (0)