Skip to content

Commit

Permalink
test deployment failures don't drop traffic on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Jan 28, 2024
1 parent f1bd929 commit 8f5284e
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/upgrade/continual.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import pkgupgrade "knative.dev/pkg/test/upgrade"
func ContinualTests() []pkgupgrade.BackgroundOperation {
return []pkgupgrade.BackgroundOperation{
ProbeTest(),
DeploymentFailureProbeTest(),
AutoscaleSustainingTest(),
AutoscaleSustainingWithTBCTest(),
}
Expand Down
122 changes: 122 additions & 0 deletions test/upgrade/deployment_failure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
Copyright 2024 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Check failure on line 8 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: test/upgrade/deployment_failure.go:8: found mismatched boilerplate lines: {[]string}[0]: -: " http://www.apache.org/licenses/LICENSE-2.0" +: "\thttp://www.apache.org/licenses/LICENSE-2.0" {[]string}[8]: -: "" +: "package upgrade"
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package upgrade

import (
"context"

admissionv1 "k8s.io/api/admissionregistration/v1"

Check failure on line 21 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'k8s.io/api/admissionregistration/v1' is not allowed from list 'Main' (depguard)
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Check failure on line 22 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'k8s.io/apimachinery/pkg/apis/meta/v1' is not allowed from list 'Main' (depguard)
"knative.dev/pkg/ptr"

Check failure on line 23 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/pkg/ptr' is not allowed from list 'Main' (depguard)
"knative.dev/pkg/test/helpers"

Check failure on line 24 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/pkg/test/helpers' is not allowed from list 'Main' (depguard)
logstream "knative.dev/pkg/test/logstream/v2"

Check failure on line 25 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/pkg/test/logstream/v2' is not allowed from list 'Main' (depguard)
pkgupgrade "knative.dev/pkg/test/upgrade"

Check failure on line 26 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/pkg/test/upgrade' is not allowed from list 'Main' (depguard)
"knative.dev/serving/pkg/apis/autoscaling"

Check failure on line 27 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/serving/pkg/apis/autoscaling' is not allowed from list 'Main' (depguard)
v1 "knative.dev/serving/pkg/apis/serving/v1"

Check failure on line 28 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/serving/pkg/apis/serving/v1' is not allowed from list 'Main' (depguard)
"knative.dev/serving/test"

Check failure on line 29 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/serving/test' is not allowed from list 'Main' (depguard)
"knative.dev/serving/test/e2e"

Check failure on line 30 in test/upgrade/deployment_failure.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

import 'knative.dev/serving/test/e2e' is not allowed from list 'Main' (depguard)
v1test "knative.dev/serving/test/v1"
)

func DeploymentFailureProbeTest() pkgupgrade.BackgroundOperation {
var clients *test.Clients
var names *test.ResourceNames
var prober test.Prober
var canceler logstream.Canceler = func() {}

return pkgupgrade.NewBackgroundVerification("DeploymentFailureProbeTest", func(c pkgupgrade.Context) {
c.T.Log("Creating Service")
ctx := context.Background()

clients = e2e.Setup(c.T) // This one uses the default namespace `test.ServingFlags.TestNamespace`
names = &test.ResourceNames{
Service: "deployment-upgrade-failure",
Image: test.HelloWorld,
}

if !test.ServingFlags.DisableLogStream {
canceler = streamLogs(c.T, clients, names.Service)
}

resources, err := v1test.CreateServiceReady(c.T, clients, names, func(s *v1.Service) {
s.Spec.Template.Labels = map[string]string{
autoscaling.MinScaleAnnotation.Key(): "1",
autoscaling.MaxScaleAnnotation.Key(): "1",
}
})

if err != nil {
c.T.Fatal("Failed to create Service:", err)
}

url := resources.Service.Status.URL.URL()
// This polls until we get a 200 with the right body.
assertServiceResourcesUpdated(c.T, clients, *names, url, test.PizzaPlanetText1)

transport := test.AddRootCAtoTransport(context.Background(), c.T.Logf, clients, test.ServingFlags.HTTPS)
prober = test.RunRouteProber(c.T.Logf, clients, url, transport)

// Setup webhook that fails when deployment is updated
// Failing to update the Deployment shouldn't cause a traffic drop
// note: the deployment is only updated if the controllers change the spec
// and this happens when the queue proxy image is changed when upgrading
c.T.Log("Creating Failing Webhook")
noSideEffects := admissionv1.SideEffectClassNone

selector := &metav1.LabelSelector{
MatchLabels: map[string]string{
"serving.knative.dev/service": names.Service,
},
}

// Create a broken webhook that breaks scheduling Pods
_, err = clients.KubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().Create(
ctx,
&admissionv1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "broken-webhook",
},
Webhooks: []admissionv1.MutatingWebhook{{
AdmissionReviewVersions: []string{"v1"},
Name: "webhook.non-existing.dev",
ClientConfig: admissionv1.WebhookClientConfig{
Service: &admissionv1.ServiceReference{
Name: helpers.AppendRandomString("non-existing"),
Namespace: helpers.AppendRandomString("non-existing"),
},
},
ObjectSelector: selector,
TimeoutSeconds: ptr.Int32(5),
SideEffects: &noSideEffects,
Rules: []admissionv1.RuleWithOperations{{
Operations: []admissionv1.OperationType{"CREATE"},
Rule: admissionv1.Rule{
APIGroups: []string{""}, // core
APIVersions: []string{"v1"},
Resources: []string{"pods"},
},
}},
}},
},
metav1.CreateOptions{},
)
}, func(c pkgupgrade.Context) {
// Verify
test.EnsureTearDown(c.T, clients, names)
test.AssertProberSLO(c.T, prober, *successFraction)
c.T.Cleanup(canceler)
})
}

0 comments on commit 8f5284e

Please sign in to comment.