diff --git a/backend/eventloop/application_event_loop/application_event_runner_deployments.go b/backend/eventloop/application_event_loop/application_event_runner_deployments.go index 36ff2d9b07..17188c9794 100644 --- a/backend/eventloop/application_event_loop/application_event_runner_deployments.go +++ b/backend/eventloop/application_event_loop/application_event_runner_deployments.go @@ -244,10 +244,10 @@ func (a applicationEventLoopRunner_Action) handleNewGitOpsDeplEvent(ctx context. isWorkspaceTarget := gitopsDeployment.Spec.Destination.Environment == "" managedEnv, engineInstance, destinationName, err := a.reconcileManagedEnvironmentOfGitOpsDeployment(ctx, gitopsDeployment, gitopsDeplNamespace, isWorkspaceTarget) - if err != nil { + if err != nil || managedEnv == nil { userError := "Unable to reconcile the ManagedEnvironment. Verify that the ManagedEnvironment and Secret are correctly defined, and have valid credentials" - devError := fmt.Errorf("unable to get or create managed environment, isworkspacetarget:%v: %v", isWorkspaceTarget, err) + devError := fmt.Errorf("unable to get or create managed environment, isworkspacetarget:%v: %w", isWorkspaceTarget, err) return nil, nil, deploymentModifiedResult_Failed, gitopserrors.NewUserDevError(userError, devError) diff --git a/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv.go b/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv.go index 073651502b..fa9a184279 100644 --- a/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv.go +++ b/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv.go @@ -254,8 +254,12 @@ func internalProcessMessage_internalReconcileSharedManagedEnv(ctx context.Contex func getManagedEnvironmentCRs(ctx context.Context, managedEnvironmentCRName string, managedEnvironmentCRNamespace string, - workspaceClient client.Client, workspaceNamespace corev1.Namespace, k8sClientFactory SRLK8sClientFactory, dbQueries db.DatabaseQueries, - clusterUser db.ClusterUser, log logr.Logger) (managedgitopsv1alpha1.GitOpsDeploymentManagedEnvironment, corev1.Secret, bool, error) { + workspaceClient client.Client, + workspaceNamespace corev1.Namespace, + k8sClientFactory SRLK8sClientFactory, + dbQueries db.DatabaseQueries, + clusterUser db.ClusterUser, + log logr.Logger) (managedgitopsv1alpha1.GitOpsDeploymentManagedEnvironment, corev1.Secret, bool, error) { const ( resourceDoesNotExist = true diff --git a/tests-e2e/core/gitopsdeployment_resource_test.go b/tests-e2e/core/gitopsdeployment_resource_test.go index 7dfe39a4f6..948845f9de 100644 --- a/tests-e2e/core/gitopsdeployment_resource_test.go +++ b/tests-e2e/core/gitopsdeployment_resource_test.go @@ -21,6 +21,7 @@ var _ = Describe("GitOpsDeployment Condition Tests", func() { gitOpsDeploymentResource := gitopsDeplFixture.BuildGitOpsDeploymentResource("managed-environment-gitops-depl", fixture.RepoURL, fixture.GitopsDeploymentPath, managedgitopsv1alpha1.GitOpsDeploymentSpecType_Automated) + gitOpsDeploymentResource.Spec.Destination = managedgitopsv1alpha1.ApplicationDestination{ Environment: "does-not-exist", // This is the invalid value, which should return a condition error Namespace: "", @@ -29,13 +30,12 @@ var _ = Describe("GitOpsDeployment Condition Tests", func() { k8sClient, err := fixture.GetE2ETestUserWorkspaceKubeClient() Expect(err).To(Succeed()) - err = k8s.Create(&gitOpsDeploymentResource, k8sClient) - Expect(err).To(Succeed()) + Expect(k8s.Create(&gitOpsDeploymentResource, k8sClient)).To(Succeed()) expectedConditions := []managedgitopsv1alpha1.GitOpsDeploymentCondition{ { Type: managedgitopsv1alpha1.GitOpsDeploymentConditionErrorOccurred, - Message: "an unknown error occurred", + Message: "Unable to reconcile the ManagedEnvironment. Verify that the ManagedEnvironment and Secret are correctly defined, and have valid credentials", Status: managedgitopsv1alpha1.GitOpsConditionStatusTrue, Reason: managedgitopsv1alpha1.GitopsDeploymentReasonErrorOccurred, }, @@ -48,8 +48,7 @@ var _ = Describe("GitOpsDeployment Condition Tests", func() { ) By("delete the GitOpsDeployment resource") - err = k8s.Delete(&gitOpsDeploymentResource, k8sClient) - Expect(err).To(Succeed()) + Expect(k8s.Delete(&gitOpsDeploymentResource, k8sClient)).To(Succeed()) }) }) })