Skip to content

Commit

Permalink
Add HA support for Argo Rollouts
Browse files Browse the repository at this point in the history
Signed-off-by: Rizwana777 <[email protected]>
  • Loading branch information
Rizwana777 committed Oct 1, 2024
1 parent 62c8867 commit 41b3ba8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 72 deletions.
14 changes: 0 additions & 14 deletions controllers/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,32 +340,18 @@ func (r *RolloutManagerReconciler) removeClusterScopedResourcesIfApplicable(ctx
}

// List of ClusterRoles '*aggregate*' to delete
<<<<<<< HEAD
clusterRoleSuffixes := []string{"aggregate-to-admin", "aggregate-to-edit", "aggregate-to-view"}

// Iterate over each ClusterRole '*aggregate*' and delete if it exists
for _, suffix := range clusterRoleSuffixes {
roleName := fmt.Sprintf("%s-%s", DefaultArgoRolloutsResourceName, suffix)

=======
clusterRoles := []string{
"argo-rollouts-aggregate-to-admin",
"argo-rollouts-aggregate-to-edit",
"argo-rollouts-aggregate-to-view",
}

// Iterate over each ClusterRole '*aggregate*' and delete if it exists
for _, roleName := range clusterRoles {
>>>>>>> 46e3c9c (Fix merge conflicts)
clusterRole := &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: roleName,
},
}
<<<<<<< HEAD

=======
>>>>>>> 46e3c9c (Fix merge conflicts)
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(clusterRole), clusterRole); err != nil {
if !apierrors.IsNotFound(err) {
log.Error(err, "error on retrieving ClusterRole", "name", roleName)
Expand Down
58 changes: 0 additions & 58 deletions tests/e2e/cluster-scoped/cluster_scoped_rollouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

controllers "github.com/argoproj-labs/argo-rollouts-manager/controllers"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -365,62 +364,5 @@ var _ = Describe("Cluster-scoped RolloutManager tests", func() {
Eventually(clusterRoleView, "1m", "1s").ShouldNot((k8s.ExistByName(k8sClient)))
Eventually(clusterRoleEdit, "1m", "1s").ShouldNot((k8s.ExistByName(k8sClient)))
})

It("should contain two replicas and the '--leader-elect' argument set to true, and verify that the anti-affinity rule is added by default when HA is enabled", func() {
By("Create cluster-scoped RolloutManager in a namespace.")

rolloutsManager := rmv1alpha1.RolloutManager{
ObjectMeta: metav1.ObjectMeta{
Name: "test-rollouts-manager",
Namespace: fixture.TestE2ENamespace,
},
Spec: rmv1alpha1.RolloutManagerSpec{
NamespaceScoped: false,
HA: rmv1alpha1.RolloutManagerHASpec{
Enabled: true,
},
},
}

err := k8sClient.Create(ctx, &rolloutsManager)
Expect(err).To(Not(HaveOccurred()))

By("Verify that RolloutManager is successfully created.")
Eventually(rolloutsManager, "1m", "1s").Should(rmFixture.HavePhase(rmv1alpha1.PhaseAvailable))

By("Verify that Status.Condition is having success condition.")
Eventually(rolloutsManager, "1m", "1s").Should(rmFixture.HaveSuccessCondition())

depl := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: controllers.DefaultArgoRolloutsResourceName,
Namespace: fixture.TestE2ENamespace,
},
}
Eventually(&depl, "10s", "1s").Should(k8s.ExistByName(k8sClient))

replicas := int32(2)
Expect(depl.Spec.Replicas).To(Equal(&replicas))
Expect(depl.Spec.Template.Spec.Containers[0].Args).To(ContainElements("--leader-elect", "true"))

By("verifying that the anti-affinity rules are set correctly")
affinity := depl.Spec.Template.Spec.Affinity
Expect(affinity).NotTo(BeNil())
Expect(affinity.PodAntiAffinity).NotTo(BeNil())

By("Verify PreferredDuringSchedulingIgnoredDuringExecution")
preferred := affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution
Expect(preferred).To(HaveLen(1))
Expect(preferred[0].Weight).To(Equal(int32(100)))
Expect(preferred[0].PodAffinityTerm.TopologyKey).To(Equal(controllers.TopologyKubernetesZoneLabel))
Expect(preferred[0].PodAffinityTerm.LabelSelector.MatchLabels).To(Equal(depl.Spec.Selector.MatchLabels))

By("Verify RequiredDuringSchedulingIgnoredDuringExecution")
required := affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution
Expect(required).To(HaveLen(1))
Expect(required[0].TopologyKey).To(Equal(controllers.KubernetesHostnameLabel))
Expect(required[0].LabelSelector.MatchLabels).To(Equal(depl.Spec.Selector.MatchLabels))
})

})
})
51 changes: 51 additions & 0 deletions tests/e2e/rollout_tests_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/argoproj-labs/argo-rollouts-manager/api/v1alpha1"
rolloutsmanagerv1alpha1 "github.com/argoproj-labs/argo-rollouts-manager/api/v1alpha1"

controllers "github.com/argoproj-labs/argo-rollouts-manager/controllers"
Expand Down Expand Up @@ -595,5 +596,55 @@ func RunRolloutsTests(namespaceScopedParam bool) {

})
})

It("should contain two replicas and the '--leader-elect' argument set to true, and verify that the anti-affinity rule is added by default when HA is enabled", func() {
By("Create cluster-scoped RolloutManager in a namespace.")

rolloutsManager := v1alpha1.RolloutManager{
ObjectMeta: metav1.ObjectMeta{
Name: "test-rollouts-manager",
Namespace: fixture.TestE2ENamespace,
},
Spec: v1alpha1.RolloutManagerSpec{
NamespaceScoped: namespaceScopedParam,
HA: v1alpha1.RolloutManagerHASpec{
Enabled: true,
},
},
}

Expect(k8sClient.Create(ctx, &rolloutsManager)).To(Succeed())

depl := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: controllers.DefaultArgoRolloutsResourceName,
Namespace: fixture.TestE2ENamespace,
},
}

Eventually(&depl, "1m", "1s").Should(k8s.ExistByName(k8sClient))

replicas := int32(2)
Expect(depl.Spec.Replicas).To(Equal(&replicas))
Expect(depl.Spec.Template.Spec.Containers[0].Args).To(ContainElements("--leader-elect", "true"))

By("verifying that the anti-affinity rules are set correctly")
affinity := depl.Spec.Template.Spec.Affinity
Expect(affinity).NotTo(BeNil())
Expect(affinity.PodAntiAffinity).NotTo(BeNil())

By("Verify PreferredDuringSchedulingIgnoredDuringExecution")
preferred := affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution
Expect(preferred).To(HaveLen(1))
Expect(preferred[0].Weight).To(Equal(int32(100)))
Expect(preferred[0].PodAffinityTerm.TopologyKey).To(Equal(controllers.TopologyKubernetesZoneLabel))
Expect(preferred[0].PodAffinityTerm.LabelSelector.MatchLabels).To(Equal(depl.Spec.Selector.MatchLabels))

By("Verify RequiredDuringSchedulingIgnoredDuringExecution")
required := affinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution
Expect(required).To(HaveLen(1))
Expect(required[0].TopologyKey).To(Equal(controllers.KubernetesHostnameLabel))
Expect(required[0].LabelSelector.MatchLabels).To(Equal(depl.Spec.Selector.MatchLabels))
})
})
}

0 comments on commit 41b3ba8

Please sign in to comment.