diff --git a/ingress/alb.go b/ingress/alb.go index a16816b762..b9837edb76 100644 --- a/ingress/alb.go +++ b/ingress/alb.go @@ -6,8 +6,8 @@ import ( "strings" "github.com/sirupsen/logrus" - extensionsv1beta1 "k8s.io/api/extensions/v1beta1" + "k8s.io/utils/pointer" "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" ingressutil "github.com/argoproj/argo-rollouts/utils/ingress" @@ -87,7 +87,7 @@ func getResetALBActionStr(ingress *extensionsv1beta1.Ingress, action string) (st { ServiceName: service, ServicePort: port, - Weight: int64(100), + Weight: pointer.Int64Ptr(int64(100)), }, }, }, diff --git a/rollout/trafficrouting/alb/alb.go b/rollout/trafficrouting/alb/alb.go index 3149cb173d..1608e7f8a7 100644 --- a/rollout/trafficrouting/alb/alb.go +++ b/rollout/trafficrouting/alb/alb.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/kubernetes" extensionslisters "k8s.io/client-go/listers/extensions/v1beta1" "k8s.io/client-go/tools/record" + "k8s.io/utils/pointer" "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" "github.com/argoproj/argo-rollouts/utils/diff" @@ -117,11 +118,11 @@ func getForwardActionString(r *v1alpha1.Rollout, port int32, desiredWeight int32 { ServiceName: stableService, ServicePort: portStr, - Weight: 100 - int64(desiredWeight), + Weight: pointer.Int64Ptr(100 - int64(desiredWeight)), }, { ServiceName: canaryService, ServicePort: portStr, - Weight: int64(desiredWeight), + Weight: pointer.Int64Ptr(int64(desiredWeight)), }, }, }, diff --git a/rollout/trafficrouting/alb/alb_test.go b/rollout/trafficrouting/alb/alb_test.go index a7b728ae25..b89e2ceffc 100644 --- a/rollout/trafficrouting/alb/alb_test.go +++ b/rollout/trafficrouting/alb/alb_test.go @@ -224,6 +224,14 @@ func TestUpdateDesiredWeight(t *testing.T) { assert.Len(t, client.Actions(), 1) } +// TestGetForwardActionStringMarshalsZeroCorrectly ensures that the annotation does not omit default value zero when marshalling +// the forward action +func TestGetForwardActionStringMarshalsZeroCorrectly(t *testing.T) { + r := fakeRollout("stable", "canary", "ingress", 443) + forwardAction := getForwardActionString(r, 443, 0) + assert.Contains(t, forwardAction, `"Weight":0`) +} + func TestErrorPatching(t *testing.T) { ro := fakeRollout("stable-svc", "canary-svc", "ingress", 443) i := ingress("ingress", "stable-svc", "canary-svc", 443, 5, ro.Name) @@ -248,7 +256,3 @@ func TestErrorPatching(t *testing.T) { assert.Error(t, err, "some error occurred") assert.Len(t, client.Actions(), 1) } - -/* - TestInvalidDesiredAnnotations (invalidManagedALBActions -*/ diff --git a/utils/ingress/ingress.go b/utils/ingress/ingress.go index 7487099281..6109142a83 100644 --- a/utils/ingress/ingress.go +++ b/utils/ingress/ingress.go @@ -39,7 +39,7 @@ type ALBTargetGroup struct { // the K8s service port ServicePort string `json:"ServicePort,omitempty"` // The weight. The range is 0 to 999. - Weight int64 `json:"Weight,omitempty"` + Weight *int64 `json:"Weight,omitempty"` } // GetRolloutIngressKeys returns ingresses keys (namespace/ingressName) which are referenced by specified rollout