Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-37668: [release-4.17]: Fix operator quick restart for SNO #1001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/utils/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func updateValidatingWebhook(c *kubernetes.Clientset) {
webhook, err := validatingWebhookClient.Get(context.TODO(), consts.OperatorWebHookName, metav1.GetOptions{})
if err != nil {
shutdownLog.Error(err, "Error getting webhook")
return
}
webhook.Webhooks[0].FailurePolicy = &failurePolicyIgnore
_, err = validatingWebhookClient.Update(context.TODO(), webhook, metav1.UpdateOptions{})
Expand Down
22 changes: 19 additions & 3 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ var _ = Describe("[sriov] operator", func() {
})
})

It("should gracefully restart quickly", func() {
DescribeTable("should gracefully restart quickly", func(webookEnabled bool) {
DeferCleanup(setSriovOperatorSpecFlag(operatorNetworkInjectorFlag, webookEnabled))
DeferCleanup(setSriovOperatorSpecFlag(operatorWebhookFlag, webookEnabled))

// This test case ensure leader election process runs smoothly when the operator's pod is restarted.
oldLease, err := clients.CoordinationV1Interface.Leases(operatorNamespace).Get(context.Background(), consts.LeaderElectionID, metav1.GetOptions{})
if k8serrors.IsNotFound(err) {
Expand All @@ -268,7 +271,10 @@ var _ = Describe("[sriov] operator", func() {

g.Expect(newLease.Spec.HolderIdentity).ToNot(Equal(oldLease.Spec.HolderIdentity))
}, 30*time.Second, 5*time.Second).Should(Succeed())
})
},
Entry("webhooks enabled", true),
Entry("webhooks disabled", true),
)

Context("SriovNetworkMetricsExporter", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -2029,26 +2035,34 @@ func defaultFilterPolicy(policy sriovv1.SriovNetworkNodePolicy) bool {
return policy.Spec.DeviceType == "netdevice"
}

func setSriovOperatorSpecFlag(flagName string, flagValue bool) {
func setSriovOperatorSpecFlag(flagName string, flagValue bool) func() {
cfg := sriovv1.SriovOperatorConfig{}
err := clients.Get(context.TODO(), runtimeclient.ObjectKey{
Name: "default",
Namespace: operatorNamespace,
}, &cfg)

ret := func() {}

Expect(err).ToNot(HaveOccurred())
if flagName == operatorNetworkInjectorFlag && cfg.Spec.EnableInjector != flagValue {
cfg.Spec.EnableInjector = flagValue
err = clients.Update(context.TODO(), &cfg)
Expect(err).ToNot(HaveOccurred())
Expect(cfg.Spec.EnableInjector).To(Equal(flagValue))
ret = func() {
setSriovOperatorSpecFlag(flagName, !flagValue)
}
}

if flagName == operatorWebhookFlag && cfg.Spec.EnableOperatorWebhook != flagValue {
cfg.Spec.EnableOperatorWebhook = flagValue
clients.Update(context.TODO(), &cfg)
Expect(err).ToNot(HaveOccurred())
Expect(cfg.Spec.EnableOperatorWebhook).To(Equal(flagValue))
ret = func() {
setSriovOperatorSpecFlag(flagName, !flagValue)
}
}

if flagValue {
Expand All @@ -2064,6 +2078,8 @@ func setSriovOperatorSpecFlag(flagName string, flagValue bool) {
}
}, 1*time.Minute, 10*time.Second).WithOffset(1).Should(Succeed())
}

return ret
}

func setOperatorConfigLogLevel(level int) {
Expand Down