diff --git a/controllers/applicationsnapshotenvironmentbinding_controller.go b/controllers/applicationsnapshotenvironmentbinding_controller.go index ccc441500..eb011cbb0 100644 --- a/controllers/applicationsnapshotenvironmentbinding_controller.go +++ b/controllers/applicationsnapshotenvironmentbinding_controller.go @@ -158,6 +158,7 @@ func (r *SnapshotEnvironmentBindingReconciler) Reconcile(ctx context.Context, re var tempDir string clone := true + appSnapshotEnvBinding.Status.Components = []appstudiov1alpha1.BindingComponentStatus{} for _, component := range components { componentName := component.Name @@ -278,14 +279,6 @@ func (r *SnapshotEnvironmentBindingReconciler) Reconcile(ctx context.Context, re return ctrl.Result{}, err } - isStatusUpdated := false - for _, bindingStatusComponent := range appSnapshotEnvBinding.Status.Components { - if bindingStatusComponent.Name == componentName { - isStatusUpdated = true - break - } - } - if clone { // Create a temp folder to create the gitops resources in tempDir, err = ioutils.CreateTempPath(appSnapshotEnvBinding.Name, r.AppFS) @@ -371,30 +364,29 @@ func (r *SnapshotEnvironmentBindingReconciler) Reconcile(ctx context.Context, re return ctrl.Result{}, err } - if !isStatusUpdated { - componentStatus := appstudiov1alpha1.BindingComponentStatus{ - Name: componentName, - GitOpsRepository: appstudiov1alpha1.BindingComponentGitOpsRepository{ - URL: hasComponent.Status.GitOps.RepositoryURL, - Branch: gitOpsBranch, - Path: filepath.Join(gitOpsContext, "components", componentName, "overlays", environmentName), - CommitID: commitID, - }, - } - - // On OpenShift, we generate a unique route name for each Component, so include that in the status - if !isKubernetesCluster { - componentStatus.GeneratedRouteName = routeName - log.Info(fmt.Sprintf("added RouteName %s for Component %s to status", routeName, componentName)) - } + // Set the BindingComponent status + componentStatus := appstudiov1alpha1.BindingComponentStatus{ + Name: componentName, + GitOpsRepository: appstudiov1alpha1.BindingComponentGitOpsRepository{ + URL: hasComponent.Status.GitOps.RepositoryURL, + Branch: gitOpsBranch, + Path: filepath.Join(gitOpsContext, "components", componentName, "overlays", environmentName), + CommitID: commitID, + }, + } - if _, ok := componentGeneratedResources[componentName]; ok { - componentStatus.GitOpsRepository.GeneratedResources = componentGeneratedResources[componentName] - } + // On OpenShift, we generate a unique route name for each Component, so include that in the status + if !isKubernetesCluster { + componentStatus.GeneratedRouteName = routeName + log.Info(fmt.Sprintf("added RouteName %s for Component %s to status", routeName, componentName)) + } - appSnapshotEnvBinding.Status.Components = append(appSnapshotEnvBinding.Status.Components, componentStatus) + if _, ok := componentGeneratedResources[componentName]; ok { + componentStatus.GitOpsRepository.GeneratedResources = componentGeneratedResources[componentName] } + appSnapshotEnvBinding.Status.Components = append(appSnapshotEnvBinding.Status.Components, componentStatus) + // Set the clone to false, since we dont want to clone the repo again for the other components clone = false }