Skip to content

Commit

Permalink
feat: better error handling for IngressWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
leoluz committed Sep 30, 2021
1 parent be512ab commit e26b2af
Show file tree
Hide file tree
Showing 17 changed files with 605 additions and 245 deletions.
3 changes: 2 additions & 1 deletion cmd/rollouts-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ func newCommand() *cobra.Command {

k8sRequestProvider := &metrics.K8sRequestsCountProvider{}
kubeclientmetrics.AddMetricsTransportWrapper(config, k8sRequestProvider.IncKubernetesRequest)
ingressWrapper := ingressutil.NewIngressWrapper(ingressutil.IngressModeExtensions, kubeClient, kubeInformerFactory)
ingressWrapper, err := ingressutil.NewIngressWrapper(ingressutil.IngressModeExtensions, kubeClient, kubeInformerFactory)
checkError(err)

cm := controller.NewManager(
namespace,
Expand Down
12 changes: 6 additions & 6 deletions ingress/alb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestInvalidManagedALBActions(t *testing.T) {
ing := newALBIngress("test-ingress", 80, "stable-service", rollout.Name)
ing.Annotations[ingressutil.ManagedActionsAnnotation] = "invalid-managed-by"

ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, rollout)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, rollout)

err := ctrl.syncIngress("default/test-ingress")
assert.Nil(t, err)
Expand All @@ -113,7 +113,7 @@ func TestInvalidPreviousALBActionAnnotationValue(t *testing.T) {
ing := newALBIngress("test-ingress", 80, "stable-service", "not-existing-rollout")
ing.Annotations[albActionAnnotation("stable-service")] = "{"

ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, nil)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, nil)

err := ctrl.syncIngress("default/test-ingress")
assert.Nil(t, err)
Expand All @@ -124,7 +124,7 @@ func TestInvalidPreviousALBActionAnnotationValue(t *testing.T) {
func TestInvalidPreviousALBActionAnnotationKey(t *testing.T) {
ing := newALBIngress("test-ingress", 80, "stable-service", "not-existing-rollout")
ing.Annotations[ingressutil.ManagedActionsAnnotation] = "invalid-action-key"
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, nil)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, nil)

err := ctrl.syncIngress("default/test-ingress")
assert.Nil(t, err)
Expand All @@ -136,7 +136,7 @@ func TestResetActionFailureFindNoPort(t *testing.T) {
ing := newALBIngress("test-ingress", 80, "stable-service", "not-existing-rollout")
ing.Annotations[albActionAnnotation("stable-service")] = "{}"

ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, nil)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, nil)

err := ctrl.syncIngress("default/test-ingress")
assert.Nil(t, err)
Expand All @@ -148,7 +148,7 @@ func TestALBIngressNoModifications(t *testing.T) {
rollout := rollout("rollout", "stable-service", "test-ingress")
ing := newALBIngress("test-ingress", 80, "stable-service", rollout.Name)

ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, rollout)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, rollout)

err := ctrl.syncIngress("default/test-ingress")
assert.Nil(t, err)
Expand All @@ -159,7 +159,7 @@ func TestALBIngressNoModifications(t *testing.T) {
func TestALBIngressResetAction(t *testing.T) {
ing := newALBIngress("test-ingress", 80, "stable-service", "non-existing-rollout")

ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, nil)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, nil)
err := ctrl.syncIngress("default/test-ingress")
assert.Nil(t, err)
assert.Len(t, enqueuedObjects, 0)
Expand Down
16 changes: 10 additions & 6 deletions ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func newNginxIngress(name string, port int, serviceName string) *extensionsv1bet
}
}

func newFakeIngressController(ing *extensionsv1beta1.Ingress, rollout *v1alpha1.Rollout) (*Controller, *k8sfake.Clientset, map[string]int) {
func newFakeIngressController(t *testing.T, ing *extensionsv1beta1.Ingress, rollout *v1alpha1.Rollout) (*Controller, *k8sfake.Clientset, map[string]int) {
t.Helper()
client := fake.NewSimpleClientset()
if rollout != nil {
client = fake.NewSimpleClientset(rollout)
Expand All @@ -65,7 +66,10 @@ func newFakeIngressController(ing *extensionsv1beta1.Ingress, rollout *v1alpha1.
}
i := informers.NewSharedInformerFactory(client, 0)
k8sI := kubeinformers.NewSharedInformerFactory(kubeclient, 0)
ingressWrap := ingressutil.NewIngressWrapper(ingressutil.IngressModeExtensions, kubeclient, k8sI)
ingressWrap, err := ingressutil.NewIngressWrapper(ingressutil.IngressModeExtensions, kubeclient, k8sI)
if err != nil {
t.Fatal(err)
}

rolloutWorkqueue := workqueue.NewNamedRateLimitingQueue(queue.DefaultArgoRolloutsRateLimiter(), "Rollouts")
ingressWorkqueue := workqueue.NewNamedRateLimitingQueue(queue.DefaultArgoRolloutsRateLimiter(), "Ingresses")
Expand Down Expand Up @@ -112,7 +116,7 @@ func newFakeIngressController(ing *extensionsv1beta1.Ingress, rollout *v1alpha1.
}

func TestSyncMissingIngress(t *testing.T) {
ctrl, _, _ := newFakeIngressController(nil, nil)
ctrl, _, _ := newFakeIngressController(t, nil, nil)

err := ctrl.syncIngress("default/test-ingress")
assert.NoError(t, err)
Expand All @@ -121,7 +125,7 @@ func TestSyncMissingIngress(t *testing.T) {
func TestSyncIngressNotReferencedByRollout(t *testing.T) {
ing := newNginxIngress("test-stable-ingress", 80, "test-stable-service")

ctrl, kubeclient, _ := newFakeIngressController(ing, nil)
ctrl, kubeclient, _ := newFakeIngressController(t, ing, nil)

err := ctrl.syncIngress("default/test-stable-ingress")
assert.NoError(t, err)
Expand Down Expand Up @@ -152,7 +156,7 @@ func TestSyncIngressReferencedByRollout(t *testing.T) {
},
}

ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, rollout)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, rollout)

err := ctrl.syncIngress("default/test-stable-ingress")
assert.NoError(t, err)
Expand Down Expand Up @@ -184,7 +188,7 @@ func TestSkipIngressWithNoAnnotations(t *testing.T) {
},
}

ctrl, kubeclient, enqueuedObjects := newFakeIngressController(ing, rollout)
ctrl, kubeclient, enqueuedObjects := newFakeIngressController(t, ing, rollout)

err := ctrl.syncIngress("default/test-stable-ingress")
assert.NoError(t, err)
Expand Down
Loading

0 comments on commit e26b2af

Please sign in to comment.