Skip to content
Open
9 changes: 4 additions & 5 deletions controllers/argocd/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,17 @@ func (r *ReconcileArgoCD) reconcileApplicationSetDeployment(cr *argoproj.ArgoCD,
AddSeccompProfileForOpenShift(r.Client, podSpec)

if deplExists {
// Add Kubernetes-specific labels/annotations from the live object in the source to preserve metadata.
addKubernetesData(deploy.Spec.Template.Labels, existing.Spec.Template.Labels)
addKubernetesData(deploy.Spec.Template.Annotations, existing.Spec.Template.Annotations)
//Check if annotations have changed
UpdateMapValues(&existing.Spec.Template.Annotations, deploy.Spec.Template.Annotations)

// If the Deployment already exists, make sure the values we care about are up-to-date
deploymentsDifferent := identifyDeploymentDifference(*existing, *deploy)
if len(deploymentsDifferent) > 0 {
existing.Spec.Template.Spec.Containers = podSpec.Containers
existing.Spec.Template.Spec.Volumes = podSpec.Volumes
existing.Spec.Template.Spec.ServiceAccountName = podSpec.ServiceAccountName
existing.Labels = deploy.Labels
existing.Spec.Template.Labels = deploy.Spec.Template.Labels
UpdateMapValues(&existing.Labels, deploy.Labels)
UpdateMapValues(&existing.Spec.Template.Labels, deploy.Spec.Template.Labels)
existing.Spec.Selector = deploy.Spec.Selector
existing.Spec.Template.Spec.NodeSelector = deploy.Spec.Template.Spec.NodeSelector
existing.Spec.Template.Spec.Tolerations = deploy.Spec.Template.Spec.Tolerations
Expand Down
3 changes: 3 additions & 0 deletions controllers/argocd/argocd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ func (r *ReconcileArgoCD) internalReconcile(ctx context.Context, request ctrl.Re
}
}

// Process DropMetadata for namespace-based label cleanup
r.processDropMetadataForCleanup(argocd)

if err := r.reconcileResources(argocd, argoCDStatus); err != nil {
// Error reconciling ArgoCD sub-resources - requeue the request.
return reconcile.Result{}, argocd, argoCDStatus, err
Expand Down
25 changes: 25 additions & 0 deletions controllers/argocd/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,25 @@ func (r *ReconcileArgoCD) reconcileConfigMaps(cr *argoproj.ArgoCD, useTLSForRedi
// This ConfigMap holds the CA Certificate data for client use.
func (r *ReconcileArgoCD) reconcileCAConfigMap(cr *argoproj.ArgoCD) error {
cm := newConfigMapWithName(getCAConfigMapName(cr), cr)
existingCM := &corev1.ConfigMap{}
exists, err := argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, existingCM)
if err != nil {
return err
}
if exists {
changed := false
//Check if labels have changed
if UpdateMapValues(&existingCM.Labels, cm.GetLabels()) {
argoutil.LogResourceUpdate(log, existingCM, "updating", "CAConfigMap labels")
changed = true
if changed {
if err := r.Update(context.TODO(), existingCM); err != nil {
log.Error(err, "failed to update service object")
}
}
}

}

configMapExists, err := argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm)
if err != nil {
Expand Down Expand Up @@ -535,6 +554,12 @@ func (r *ReconcileArgoCD) reconcileArgoConfigMap(cr *argoproj.ArgoCD) error {
}

changed := false
//Check if labels have changed
if UpdateMapValues(&existingCM.Labels, cm.GetLabels()) {
argoutil.LogResourceUpdate(log, existingCM, "updating", "ConfigMap labels")
changed = true
}

if !reflect.DeepEqual(cm.Data, existingCM.Data) {
existingCM.Data = cm.Data
changed = true
Expand Down
10 changes: 5 additions & 5 deletions controllers/argocd/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,9 @@ func (r *ReconcileArgoCD) reconcileServerDeployment(cr *argoproj.ArgoCD, useTLSF
}
}

// Add Kubernetes-specific labels/annotations from the live object in the source to preserve metadata.
addKubernetesData(deploy.Spec.Template.Labels, existing.Spec.Template.Labels)
addKubernetesData(deploy.Spec.Template.Annotations, existing.Spec.Template.Annotations)
//Check if labels/annotations have changed
UpdateMapValues(&existing.Spec.Template.Labels, deploy.Spec.Template.Labels)
UpdateMapValues(&existing.Spec.Template.Annotations, deploy.Spec.Template.Annotations)

if !reflect.DeepEqual(deploy.Spec.Template.Annotations, existing.Spec.Template.Annotations) {
existing.Spec.Template.Annotations = deploy.Spec.Template.Annotations
Expand All @@ -1269,8 +1269,8 @@ func (r *ReconcileArgoCD) reconcileServerDeployment(cr *argoproj.ArgoCD, useTLSF
explanation += "annotations"
changed = true
}
if !reflect.DeepEqual(deploy.Spec.Template.Labels, existing.Spec.Template.Labels) {
existing.Spec.Template.Labels = deploy.Spec.Template.Labels
// Preserve non-operator labels in the existing deployment.
if UpdateMapValues(&existing.Spec.Template.Labels, deploy.Spec.Template.Labels) {
if changed {
explanation += ", "
}
Expand Down
6 changes: 2 additions & 4 deletions controllers/argocd/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,15 @@ func (r *ReconcileArgoCD) reconcileNotificationsDeployment(cr *argoproj.ArgoCD,
deploymentChanged = true
}

if !reflect.DeepEqual(existingDeployment.Labels, desiredDeployment.Labels) {
existingDeployment.Labels = desiredDeployment.Labels
if UpdateMapValues(&existingDeployment.Labels, desiredDeployment.Labels) {
if deploymentChanged {
explanation = ", "
}
explanation += "labels"
deploymentChanged = true
}

if !reflect.DeepEqual(existingDeployment.Spec.Template.Labels, desiredDeployment.Spec.Template.Labels) {
existingDeployment.Spec.Template.Labels = desiredDeployment.Spec.Template.Labels
if UpdateMapValues(&existingDeployment.Spec.Template.Labels, desiredDeployment.Spec.Template.Labels) {
if deploymentChanged {
explanation = ", "
}
Expand Down
7 changes: 3 additions & 4 deletions controllers/argocd/repo_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ func (r *ReconcileArgoCD) reconcileRepoDeployment(cr *argocdoperatorv1beta1.Argo
}

// Add Kubernetes-specific labels/annotations from the live object in the source to preserve metadata.
addKubernetesData(deploy.Spec.Template.Labels, existing.Spec.Template.Labels)
addKubernetesData(deploy.Spec.Template.Annotations, existing.Spec.Template.Annotations)
UpdateMapValues(&existing.Spec.Template.Labels, deploy.Spec.Template.Labels)
UpdateMapValues(&existing.Spec.Template.Annotations, deploy.Spec.Template.Annotations)

if !reflect.DeepEqual(deploy.Spec.Template.Annotations, existing.Spec.Template.Annotations) {
existing.Spec.Template.Annotations = deploy.Spec.Template.Annotations
Expand All @@ -533,8 +533,7 @@ func (r *ReconcileArgoCD) reconcileRepoDeployment(cr *argocdoperatorv1beta1.Argo
changed = true
}

if !reflect.DeepEqual(deploy.Spec.Template.Labels, existing.Spec.Template.Labels) {
existing.Spec.Template.Labels = deploy.Spec.Template.Labels
if UpdateMapValues(&existing.Spec.Template.Labels, deploy.Spec.Template.Labels) {
if changed {
explanation += ", "
}
Expand Down
6 changes: 2 additions & 4 deletions controllers/argocd/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,7 @@ func matchAggregatedClusterRoleFields(expectedClusterRole *v1.ClusterRole, exist

// if ClusterRole is for View permissions then compare Labels
if name == common.ArgoCDApplicationControllerComponentView {
if !reflect.DeepEqual(existingClusterRole.Labels, expectedClusterRole.Labels) {
existingClusterRole.Labels = expectedClusterRole.Labels
if UpdateMapValues(&existingClusterRole.Labels, expectedClusterRole.Labels) {
if changed {
explanation += ", "
}
Expand All @@ -535,8 +534,7 @@ func matchAggregatedClusterRoleFields(expectedClusterRole *v1.ClusterRole, exist
changed = true
}

if !reflect.DeepEqual(existingClusterRole.Labels, expectedClusterRole.Labels) {
existingClusterRole.Labels = expectedClusterRole.Labels
if UpdateMapValues(&existingClusterRole.Labels, expectedClusterRole.Labels) {
if changed {
explanation += ", "
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/argocd/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,9 @@ func (r *ReconcileArgoCD) reconcileApplicationControllerStatefulSet(cr *argoproj
changed = true
}

// Add Kubernetes-specific labels/annotations from the live object in the source to preserve metadata.
addKubernetesData(ss.Spec.Template.Labels, existing.Spec.Template.Labels)
addKubernetesData(ss.Spec.Template.Annotations, existing.Spec.Template.Annotations)
//Check if labels/annotations have changed
UpdateMapValues(&existing.Spec.Template.Labels, ss.Spec.Template.Labels)
UpdateMapValues(&existing.Spec.Template.Annotations, ss.Spec.Template.Annotations)

if !reflect.DeepEqual(ss.Spec.Template.Annotations, existing.Spec.Template.Annotations) {
existing.Spec.Template.Annotations = ss.Spec.Template.Annotations
Expand Down
Loading