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

fix: nginx traffic router patching wrong ingress resource #1655

Merged
merged 1 commit into from
Nov 12, 2021
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
2 changes: 1 addition & 1 deletion rollout/trafficrouting/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (r *Reconciler) SetWeight(desiredWeight int32, additionalDestinations ...v1
r.log.WithField(logutil.IngressKey, canaryIngressName).WithField("desiredWeight", desiredWeight).Info("updating canary Ingress")
r.cfg.Recorder.Eventf(r.cfg.Rollout, record.EventOptions{EventReason: "PatchingCanaryIngress"}, "Updating Ingress `%s` to desiredWeight '%d'", canaryIngressName, desiredWeight)

_, err = r.cfg.Client.ExtensionsV1beta1().Ingresses(r.cfg.Rollout.Namespace).Patch(ctx, canaryIngressName, types.MergePatchType, patch, metav1.PatchOptions{})
_, err = r.cfg.IngressWrapper.Patch(ctx, r.cfg.Rollout.Namespace, canaryIngressName, types.MergePatchType, patch, metav1.PatchOptions{})
if err != nil {
r.log.WithField(logutil.IngressKey, canaryIngressName).WithField("err", err.Error()).Error("error patching canary ingress")
return fmt.Errorf("error patching canary ingress `%s`: %v", canaryIngressName, err)
Expand Down
42 changes: 41 additions & 1 deletion rollout/trafficrouting/nginx/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func networkingIngress(name string, port int, serviceName string) *networkingv1.
return &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: "some-namespace",
Namespace: metav1.NamespaceDefault,
Annotations: map[string]string{
"annotation-key1": "annotation-value1",
},
Expand Down Expand Up @@ -511,6 +511,46 @@ func TestReconcileStableAndCanaryIngressFoundPatch(t *testing.T) {
}
}

func TestReconcileWillInvokeNetworkingIngress(t *testing.T) {
// given
rollout := fakeRollout("stable-service", "canary-service", "stable-ingress")
stableIngress := networkingIngress("stable-ingress", 80, "stable-service")
canaryIngress := networkingIngress("rollout-stable-ingress-canary", 80, "canary-service")
canaryIngress.SetAnnotations(map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-weight": "15",
})
canaryIngress.SetOwnerReferences([]metav1.OwnerReference{*metav1.NewControllerRef(rollout, schema.GroupVersionKind{Group: "argoproj.io", Version: "v1alpha1", Kind: "Rollout"})})
client := fake.NewSimpleClientset(stableIngress, canaryIngress)
k8sI := kubeinformers.NewSharedInformerFactory(client, 0)
k8sI.Networking().V1().Ingresses().Informer().GetIndexer().Add(stableIngress)
k8sI.Networking().V1().Ingresses().Informer().GetIndexer().Add(canaryIngress)
ingressWrapper, err := ingressutil.NewIngressWrapper(ingressutil.IngressModeNetworking, client, k8sI)
if err != nil {
t.Fatal(err)
}
r := NewReconciler(ReconcilerConfig{
Rollout: rollout,
Client: client,
Recorder: record.NewFakeEventRecorder(),
ControllerKind: schema.GroupVersionKind{Group: "foo", Version: "v1", Kind: "Bar"},
IngressWrapper: ingressWrapper,
})

// when
err = r.SetWeight(10)

// then
assert.Nil(t, err, "Reconcile returns no error")
actions := client.Actions()
assert.Len(t, actions, 1)
if !t.Failed() {
// Avoid "index out of range" errors
assert.Equal(t, "patch", actions[0].GetVerb(), "action: patch canary ingress")
assert.Equal(t, schema.GroupVersionResource{Group: "networking.k8s.io", Version: "v1", Resource: "ingresses"}, actions[0].GetResource(), "action: patch canary ingress")
}
}

func TestReconcileStableAndCanaryIngressFoundNoChange(t *testing.T) {
rollout := fakeRollout("stable-service", "canary-service", "stable-ingress")
stableIngress := extensionsIngress("stable-ingress", 80, "stable-service")
Expand Down