Skip to content
Open
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
4 changes: 4 additions & 0 deletions controllers/argorollouts_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type RolloutManagerReconciler struct {
client.Client
Scheme *runtime.Scheme
OpenShiftRoutePluginLocation string
//ArgoRolloutsCustumLabel is used to set custom labels on Argo Rollouts resources
// This is used to set the label on the ConfigMap and Secrets created by the controller for now.
// The label is used to identify the resources created by the RolloutManager.
ArgoRolloutsCustomLabel map[string]string

// NamespaceScopedArgoRolloutsController is used to configure scope of Argo Rollouts controller
// If value is true then deploy namespace-scoped Argo Rollouts controller else cluster-scoped
Expand Down
3 changes: 3 additions & 0 deletions controllers/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (r *RolloutManagerReconciler) reconcileConfigMap(ctx context.Context, cr ro
}

setRolloutsLabelsAndAnnotationsToObject(&desiredConfigMap.ObjectMeta, cr)
if r.ArgoRolloutsCustomLabel != nil {
setCustomLabels(&desiredConfigMap.ObjectMeta, r.ArgoRolloutsCustomLabel)
}

trafficRouterPluginsMap := map[string]pluginItem{
OpenShiftRolloutPluginName: {
Expand Down
31 changes: 31 additions & 0 deletions controllers/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,37 @@ var _ = Describe("ConfigMap Test", func() {

})

It("verifies that the custom labels are added to the ConfigMap", func() {
expectedConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: DefaultRolloutsConfigMapName,
Labels: map[string]string{
"custom1": "value",
"app.kubernetes.io/component": DefaultArgoRolloutsResourceName,
"app.kubernetes.io/name": DefaultArgoRolloutsResourceName,
"app.kubernetes.io/part-of": DefaultArgoRolloutsResourceName,
},
},
}

By("Call reconcileConfigMap")
Expect(r.reconcileConfigMap(ctx, a)).To(Succeed())

By("Verify that the fetched ConfigMap matches the desired one")

fetchedConfigMap := &corev1.ConfigMap{}
Expect(fetchObject(ctx, r.Client, a.Namespace, expectedConfigMap.Name, fetchedConfigMap)).To(Succeed())

Expect(fetchedConfigMap.Labels).To(Equal(expectedConfigMap.Labels))

By("Call reconcileConfigMap again")
Expect(r.reconcileConfigMap(ctx, a)).To(Succeed())

By("verifying that the data is still present")
Expect(fetchedConfigMap.Labels).To(Equal(expectedConfigMap.Labels))

})

It("verifies traffic and metric plugin creation/modification and ensures OpenShiftRolloutPlugin existence", func() {
By("Add a pod that matches the deployment's selector")
addTestPodToFakeClient(r, a.Namespace, existingDeployment)
Expand Down
3 changes: 3 additions & 0 deletions controllers/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,9 @@ func (r *RolloutManagerReconciler) reconcileRolloutsSecrets(ctx context.Context,
}

setRolloutsLabelsAndAnnotationsToObject(&expectedSecret.ObjectMeta, cr)
if r.ArgoRolloutsCustomLabel != nil {
setCustomLabels(&expectedSecret.ObjectMeta, r.ArgoRolloutsCustomLabel)
}

// If the Secret doesn't exist (or an unrelated error occurred)....
liveSecret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: expectedSecret.Name, Namespace: expectedSecret.Namespace}}
Expand Down
20 changes: 20 additions & 0 deletions controllers/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,26 @@ var _ = Describe("Resource creation and cleanup tests", func() {
Expect(secret.ObjectMeta.Annotations["keyannotation"]).To(Equal(a.Spec.AdditionalMetadata.Annotations["keyannotation"]))
})

It("Test for Custom Labels for secrets created by Rollouts Manager function", func() {
Expect(r.reconcileRolloutsSecrets(ctx, a)).To(Succeed())
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: DefaultRolloutsNotificationSecretName,
Namespace: a.Namespace,
Labels: map[string]string{
"app.kubernetes.io/component": "argo-rollouts",
"app.kubernetes.io/name": "argo-rollouts",
"app.kubernetes.io/part-of": "argo-rollouts",
"custom1": "value",
"keylabel": "valuelabel",
},
},
}
fetchedSecret := &corev1.Secret{}
Expect(fetchObject(ctx, r.Client, a.Namespace, secret.Name, fetchedSecret)).To(Succeed())
Expect(fetchedSecret.ObjectMeta.Labels).To(Equal(secret.ObjectMeta.Labels))
})

It("test for removeClusterScopedResourcesIfApplicable function", func() {

By("creating default cluster-scoped ClusterRole/ClusterRoleBinding. These should be deleted by the call to removeClusterScopedResourcesIfApplicable")
Expand Down
11 changes: 11 additions & 0 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ func setRolloutsLabelsAndAnnotations(obj *metav1.ObjectMeta) {
obj.Labels["app.kubernetes.io/component"] = DefaultArgoRolloutsResourceName
}

func setCustomLabels(obj *metav1.ObjectMeta, customLabels map[string]string) {
if obj.Labels == nil {
obj.Labels = map[string]string{}
}

for k, v := range customLabels {
obj.Labels[k] = v
}

}

// fetchObject will retrieve the object with the given namespace and name using the Kubernetes API.
// The result will be stored in the given object.
func fetchObject(ctx context.Context, client client.Client, namespace string, name string, obj client.Object) error {
Expand Down
7 changes: 5 additions & 2 deletions controllers/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,11 @@ func makeTestReconciler(obj ...client.Object) *RolloutManagerReconciler {
cl := fake.NewClientBuilder().WithScheme(s).WithStatusSubresource(obj...).WithObjects(obj...).Build()

return &RolloutManagerReconciler{
Client: cl,
Scheme: s,
Client: cl,
Scheme: s,
ArgoRolloutsCustomLabel: map[string]string{
"custom1": "value",
},
OpenShiftRoutePluginLocation: "file://non-empty-test-url", // Set a non-real, non-empty value for unit tests: override this to test a specific value
}
}
Expand Down
Loading