diff --git a/appstudio-controller/controllers/webhooks/environment_webhook.go b/appstudio-controller/controllers/webhooks/environment_webhook.go index ea06f7edce..f8423e8ea4 100644 --- a/appstudio-controller/controllers/webhooks/environment_webhook.go +++ b/appstudio-controller/controllers/webhooks/environment_webhook.go @@ -18,6 +18,7 @@ package webhooks import ( "context" + "errors" "fmt" "net/url" @@ -108,7 +109,7 @@ func validateEnvironment(r *appstudiov1alpha1.Environment) error { if r.Spec.UnstableConfigurationFields != nil && r.Spec.UnstableConfigurationFields.KubernetesClusterCredentials.APIURL != "" { if _, err := url.ParseRequestURI(r.Spec.UnstableConfigurationFields.KubernetesClusterCredentials.APIURL); err != nil { - return fmt.Errorf(err.Error() + appstudiov1alpha1.InvalidAPIURL) + return errors.New(err.Error() + appstudiov1alpha1.InvalidAPIURL) } } diff --git a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeployment_webhook.go b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeployment_webhook.go index 2e2a96386d..6e0326a7ba 100644 --- a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeployment_webhook.go +++ b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeployment_webhook.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1 import ( + "errors" "fmt" logutil "github.com/redhat-appstudio/managed-gitops/backend-shared/util/log" @@ -100,7 +101,7 @@ func (r *GitOpsDeployment) validateGitOpsDeployment() error { // Check whether Type is manual or automated if !(r.Spec.Type == GitOpsDeploymentSpecType_Automated || r.Spec.Type == GitOpsDeploymentSpecType_Manual) { - return fmt.Errorf(error_invalid_spec_type) + return errors.New(error_invalid_spec_type) } // Check whether sync options are valid @@ -109,14 +110,14 @@ func (r *GitOpsDeployment) validateGitOpsDeployment() error { if !(syncOptionString == SyncOptions_CreateNamespace_true || syncOptionString == SyncOptions_CreateNamespace_false) { - return fmt.Errorf(error_invalid_sync_option) + return errors.New(error_invalid_sync_option) } } } if r.Spec.Destination.Environment == "" && r.Spec.Destination.Namespace != "" { - return fmt.Errorf(error_nonempty_namespace_empty_environment) + return errors.New(error_nonempty_namespace_empty_environment) } return nil diff --git a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentmanagedenvironment_webhook.go b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentmanagedenvironment_webhook.go index e307850c5c..6703b9740d 100644 --- a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentmanagedenvironment_webhook.go +++ b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentmanagedenvironment_webhook.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1 import ( + "errors" "fmt" "net/url" @@ -99,11 +100,11 @@ func (r *GitOpsDeploymentManagedEnvironment) ValidateGitOpsDeploymentManagedEnv( if r.Spec.APIURL != "" { apiURL, err := url.ParseRequestURI(r.Spec.APIURL) if err != nil { - return fmt.Errorf(err.Error()) + return errors.New(err.Error()) } if apiURL.Scheme != "https" { - return fmt.Errorf(error_invalid_cluster_api_url) + return errors.New(error_invalid_cluster_api_url) } } diff --git a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentrepositorycredential_webhook.go b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentrepositorycredential_webhook.go index e1cd8f1bdf..32f4aa76a4 100644 --- a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentrepositorycredential_webhook.go +++ b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentrepositorycredential_webhook.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1 import ( + "errors" "fmt" "net/url" @@ -98,11 +99,11 @@ func (r *GitOpsDeploymentRepositoryCredential) ValidateGitOpsDeploymentRepoCred( if r.Spec.Repository != "" { apiURL, err := url.ParseRequestURI(r.Spec.Repository) if err != nil { - return fmt.Errorf(err.Error()) + return err } if !(apiURL.Scheme == "https" || apiURL.Scheme == "ssh") { - return fmt.Errorf(error_invalid_repository) + return errors.New(error_invalid_repository) } } diff --git a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentsyncrun_webhook.go b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentsyncrun_webhook.go index 0c65f0e52b..6769d558f7 100644 --- a/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentsyncrun_webhook.go +++ b/backend-shared/apis/managed-gitops/v1alpha1/gitopsdeploymentsyncrun_webhook.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1 import ( + "errors" "fmt" logutil "github.com/redhat-appstudio/managed-gitops/backend-shared/util/log" @@ -66,7 +67,7 @@ func (r *GitOpsDeploymentSyncRun) ValidateCreate() error { log.V(logutil.LogLevel_Debug).Info("validate create") if r.Name == invalid_name { - err := fmt.Errorf(error_invalid_name) + err := errors.New(error_invalid_name) log.Info("webhook rejected invalid create", "error", fmt.Sprintf("%v", err)) return err } diff --git a/backend-shared/util/operations/types.go b/backend-shared/util/operations/types.go index 12a7fb5e0a..6d8a0aee39 100644 --- a/backend-shared/util/operations/types.go +++ b/backend-shared/util/operations/types.go @@ -2,6 +2,7 @@ package operations import ( "context" + "errors" "fmt" "time" @@ -114,7 +115,7 @@ func createOperationInternal(ctx context.Context, waitForOperation bool, dbOpera if operationNamespace != gitopsEngineInstance.Namespace_name { mismatchedNamespace := "OperationNS: " + operationNamespace + " " + "GitopsEngineInstanceNS: " + gitopsEngineInstance.Namespace_name - return nil, nil, fmt.Errorf("namespace mismatched in given OperationCR and existing GitopsEngineInstance " + mismatchedNamespace) + return nil, nil, errors.New("namespace mismatched in given OperationCR and existing GitopsEngineInstance " + mismatchedNamespace) } var dbOperationList []db.Operation diff --git a/backend-shared/util/test_task_retry_loop_test.go b/backend-shared/util/test_task_retry_loop_test.go index c712259806..a67111b9d9 100644 --- a/backend-shared/util/test_task_retry_loop_test.go +++ b/backend-shared/util/test_task_retry_loop_test.go @@ -2,6 +2,7 @@ package util import ( "context" + "errors" "fmt" "math/rand" "sync" @@ -241,7 +242,7 @@ func (event *mockTestTaskEvent) PerformTask(taskContext context.Context) (bool, if event.shouldReturnError { wg.Done() - return false, fmt.Errorf(event.errorReturned) + return false, errors.New(event.errorReturned) } time.Sleep(1 * time.Millisecond) diff --git a/backend-shared/util/util.go b/backend-shared/util/util.go index 95f063f50a..22fc8daf9c 100644 --- a/backend-shared/util/util.go +++ b/backend-shared/util/util.go @@ -2,6 +2,7 @@ package util import ( "context" + "errors" "fmt" "math/rand" "os" @@ -108,7 +109,7 @@ outer: // We only return if the context was cancelled. select { case <-ctx.Done(): - err = fmt.Errorf(taskDescription + ": context cancelled") + err = errors.New(taskDescription + ": context cancelled") break outer default: } diff --git a/backend/condition/conditions_test.go b/backend/condition/conditions_test.go index 0ce1723702..002f09108b 100644 --- a/backend/condition/conditions_test.go +++ b/backend/condition/conditions_test.go @@ -41,7 +41,7 @@ var _ = Describe("ConditionManager", func() { obj = getFirst(sut) Expect((sut)).To(HaveLen(1)) - Expect(obj.LastProbeTime).NotTo(Equal(probe)) + Expect(obj.LastProbeTime).NotTo(Equal(*probe)) Expect(obj.LastTransitionTime).To(Equal(transition)) Expect(obj.Message).To(Equal(message)) Expect(obj.Reason).To(Equal(reason)) @@ -71,7 +71,7 @@ var _ = Describe("ConditionManager", func() { Expect(obj.Reason).To(Equal(gitopsv1alpha1.GitOpsDeploymentReasonType("DummyResolved"))) Expect(obj.Status).To(Equal(status)) Expect(obj.LastProbeTime).NotTo(Equal(now)) - Expect(obj.LastTransitionTime).NotTo(Equal(now)) + Expect(*obj.LastTransitionTime).NotTo(Equal(now)) }) }) 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 033f3d606e..1239260839 100644 --- a/backend/eventloop/application_event_loop/application_event_runner_deployments.go +++ b/backend/eventloop/application_event_loop/application_event_runner_deployments.go @@ -3,6 +3,7 @@ package application_event_loop import ( "context" "encoding/json" + "errors" "fmt" "reflect" "strings" @@ -115,12 +116,12 @@ func (a *applicationEventLoopRunner_Action) applicationEventRunner_handleDeploym if gitopsDeployment.Spec.Source.Path == "" { userError := managedgitopsv1alpha1.GitOpsDeploymentUserError_PathIsRequired return signalledShutdown_false, nil, nil, deploymentModifiedResult_Failed, - gitopserrors.NewUserDevError(userError, fmt.Errorf(userError)) + gitopserrors.NewUserDevError(userError, errors.New(userError)) } else if gitopsDeployment.Spec.Source.Path == "/" { userError := managedgitopsv1alpha1.GitOpsDeploymentUserError_InvalidPathSlash return signalledShutdown_false, nil, nil, deploymentModifiedResult_Failed, - gitopserrors.NewUserDevError(userError, fmt.Errorf(userError)) + gitopserrors.NewUserDevError(userError, errors.New(userError)) } } diff --git a/backend/eventloop/application_event_loop/application_event_runner_syncruns.go b/backend/eventloop/application_event_loop/application_event_runner_syncruns.go index 9e1e329d52..dcdffe848c 100644 --- a/backend/eventloop/application_event_loop/application_event_runner_syncruns.go +++ b/backend/eventloop/application_event_loop/application_event_runner_syncruns.go @@ -2,6 +2,7 @@ package application_event_loop import ( "context" + "errors" "fmt" "time" @@ -290,7 +291,7 @@ func (a *applicationEventLoopRunner_Action) applicationEventRunner_handleSyncRun // return an error if 'Automated' sync policy is enabled. Argo CD doesn't allow syncing an Application with automated sync policy. if gitopsDepl.Spec.Type != managedgitopsv1alpha1.GitOpsDeploymentSpecType_Manual { userErr := fmt.Sprintf("invalid GitOpsDeploymentSyncRun '%s'. Syncing a GitOpsDeployment with Automated sync policy is not allowed", syncRunCR.Name) - devErr := fmt.Errorf(userErr) + devErr := errors.New(userErr) log.Error(devErr, "failed to process GitOpsDeploymentSyncRun") return gitopserrors.NewUserDevError(userErr, devErr) } @@ -635,13 +636,13 @@ func (a *applicationEventLoopRunner_Action) handleUpdatedGitOpsDeplSyncRunEvent( log.Info("Received GitOpsDeploymentSyncRun event for an existing GitOpsDeploymentSyncRun resource") if syncOperation.DeploymentNameField != syncRunCR.Spec.GitopsDeploymentName { - err := fmt.Errorf(ErrDeploymentNameIsImmutable) + err := errors.New(ErrDeploymentNameIsImmutable) log.Error(err, ErrDeploymentNameIsImmutable) return gitopserrors.NewUserDevError(ErrDeploymentNameIsImmutable, err) } if syncOperation.Revision != syncRunCR.Spec.RevisionID { - err := fmt.Errorf(ErrRevisionIsImmutable) + err := errors.New(ErrRevisionIsImmutable) log.Error(err, ErrRevisionIsImmutable) return gitopserrors.NewUserDevError(ErrRevisionIsImmutable, err) } diff --git a/backend/eventloop/db_reconciler.go b/backend/eventloop/db_reconciler.go index 6442987444..d18aa5f7b5 100644 --- a/backend/eventloop/db_reconciler.go +++ b/backend/eventloop/db_reconciler.go @@ -1094,7 +1094,7 @@ func cleanOrphanedEntriesfromTable_Operation(ctx context.Context, dbQueries db.D } if err := dbQueries.GetGitopsEngineInstanceById(ctx, &gitopsEngineInstance); err != nil { - log.Error(err, fmt.Sprintf("error occurred in cleanOrphanedEntriesfromTable_Operation while fetching gitopsEngineInstance: "+gitopsEngineInstance.Gitopsengineinstance_id)) + log.Error(err, fmt.Sprintf("error occurred in cleanOrphanedEntriesfromTable_Operation while fetching gitopsEngineInstance: %s", gitopsEngineInstance.Gitopsengineinstance_id)) if res == nil { res = fmt.Errorf("error occurred in cleanOrphanedEntriesfromTable_Operation while fetching gitopsEngineInstance: %w", err) diff --git a/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv_test.go b/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv_test.go index 6ae98875e8..78d3bb4a42 100644 --- a/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv_test.go +++ b/backend/eventloop/shared_resource_loop/sharedresourceloop_managedenv_test.go @@ -235,7 +235,7 @@ var _ = Describe("SharedResourceEventLoop ManagedEnvironment-related Test", func By("Verifying that the API CR to database mapping has been removed.") for _, mapping := range mappings { - Expect(mapping.APIResourceUID).ToNot(Equal(managedEnv.UID)) + Expect(mapping.APIResourceUID).ToNot(Equal(string(managedEnv.UID))) } }, diff --git a/cluster-agent/controllers/argoproj.io/application_info_cache/application_info_cache.go b/cluster-agent/controllers/argoproj.io/application_info_cache/application_info_cache.go index 1fb7f68e18..8465242d4c 100644 --- a/cluster-agent/controllers/argoproj.io/application_info_cache/application_info_cache.go +++ b/cluster-agent/controllers/argoproj.io/application_info_cache/application_info_cache.go @@ -2,6 +2,7 @@ package application_info_cache import ( "context" + "errors" "fmt" "math/rand" "time" @@ -344,7 +345,7 @@ func processGetAppStateMessage(dbQueries db.DatabaseQueries, req applicationInfo } if db.IsEmpty(req.primaryKey) { - err := fmt.Errorf("SEVERE: PrimaryKey should not be nil: " + req.primaryKey + " not found") + err := errors.New("SEVERE: PrimaryKey should not be nil: " + req.primaryKey + " not found") log.Error(err, "") req.responseChannel <- applicationInfoCacheResponse{ applicationState: db.ApplicationState{}, @@ -406,7 +407,7 @@ func processGetAppMessage(dbQueries db.DatabaseQueries, req applicationInfoCache } if db.IsEmpty(req.primaryKey) { - err := fmt.Errorf("SEVERE: PrimaryKey should not be nil: " + req.primaryKey + " not found") + err := errors.New("SEVERE: PrimaryKey should not be nil: " + req.primaryKey + " not found") log.Error(err, "") req.responseChannel <- applicationInfoCacheResponse{ application: db.Application{}, diff --git a/cluster-agent/controllers/argoproj.io/namespace_reconciler.go b/cluster-agent/controllers/argoproj.io/namespace_reconciler.go index d3fdd9637e..3fbde5ee44 100644 --- a/cluster-agent/controllers/argoproj.io/namespace_reconciler.go +++ b/cluster-agent/controllers/argoproj.io/namespace_reconciler.go @@ -556,7 +556,7 @@ func cleanOrphanedCRsfromCluster_Operation(ctx context.Context, dbQueries db.Dat // Delete the CR since it doesn't point to a DB entry, hence it is an orphaned CR. deleteCr = true } else { - log.Error(err, fmt.Sprintf("error occurred in cleanOrphanedCRsfromCluster_Operation while fetching Operation: "+dbOperation.Operation_id+" from DB.")) + log.Error(err, "error occurred in cleanOrphanedCRsfromCluster_Operation while fetching Operation: "+dbOperation.Operation_id+" from DB.") if res == nil { res = fmt.Errorf("error occurred in cleanOrphanedCRsfromCluster_Operation while fetching Operation: %w", err) } diff --git a/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop.go b/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop.go index 3573ae53f0..49544741c9 100644 --- a/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop.go +++ b/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop.go @@ -3,6 +3,7 @@ package eventloop import ( "context" "encoding/json" + "errors" "fmt" "reflect" "strings" @@ -352,7 +353,7 @@ func (task *processOperationEventTask) internalPerformTask(taskContext context.C if operationCR.Namespace != dbGitopsEngineInstance.Namespace_name { mismatchedNamespace := "OperationNS: " + operationCR.Namespace + " " + "GitopsEngineInstanceNS: " + dbGitopsEngineInstance.Namespace_name - err := fmt.Errorf("OperationCR namespace did not match with existing namespace of GitopsEngineInstance " + mismatchedNamespace) + err := errors.New("OperationCR namespace did not match with existing namespace of GitopsEngineInstance " + mismatchedNamespace) log.Error(err, "Invalid Operation Detected") return nil, shouldRetryFalse, err } @@ -517,7 +518,7 @@ func processOperation_SyncOperation(ctx context.Context, dbOperation db.Operatio // Sanity checks if dbOperation.Resource_id == "" { - return shouldRetryFalse, fmt.Errorf("resource id was nil while processing operation: " + crOperation.Name) + return shouldRetryFalse, errors.New("resource id was nil while processing operation: " + crOperation.Name) } // 1) Retrieve the SyncOperation DB entry pointed to by the Operation DB entry @@ -835,7 +836,7 @@ const ( func processOperation_Application(ctx context.Context, dbOperation db.Operation, crOperation operation.Operation, opConfig operationConfig) (bool, error) { // Sanity check if dbOperation.Resource_id == "" { - return shouldRetryTrue, fmt.Errorf("resource id was nil while processing operation: " + crOperation.Name) + return shouldRetryTrue, errors.New("resource id was nil while processing operation: " + crOperation.Name) } dbApplication := &db.Application{ @@ -1126,7 +1127,7 @@ func createOrUpdateAppProjectWithValidation(ctx context.Context, dbOperation db. func processOperation_GitOpsEngineInstance(ctx context.Context, dbOperation db.Operation, crOperation operation.Operation, opConfig operationConfig) (bool, error) { if dbOperation.Resource_id == "" { - return shouldRetryTrue, fmt.Errorf("resource id was nil while processing operation: " + crOperation.Name) + return shouldRetryTrue, errors.New("resource id was nil while processing operation: " + crOperation.Name) } dbGitopsEngineInstance := &db.GitopsEngineInstance{ diff --git a/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop_test.go b/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop_test.go index 3bf4836ae4..6361a1b7b6 100644 --- a/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop_test.go +++ b/cluster-agent/controllers/managed-gitops/eventloop/operation_event_loop_test.go @@ -3,6 +3,7 @@ package eventloop import ( "context" "encoding/json" + "errors" "fmt" "time" @@ -607,7 +608,7 @@ var _ = Describe("Operation Controller", func() { By("'kube-system' namespace has a UID that is not found in a corresponding row in GitOpsEngineCluster database") _, _, _, gitopsEngineInstance, _, err := db.CreateSampleData(dbQueries) Expect(err).ToNot(HaveOccurred()) - Expect(kubesystemNamespace.UID).ToNot(Equal(gitopsEngineInstance.Namespace_uid)) + Expect(string(kubesystemNamespace.UID)).ToNot(Equal(gitopsEngineInstance.Namespace_uid)) By("creating Operation row in database") operationDB := &db.Operation{ @@ -2365,7 +2366,7 @@ var _ = Describe("Operation Controller", func() { expectedErr := "sync failed due to xyz reason" task.syncFuncs = &syncFuncs{ appSync: func(ctx context.Context, s1, s2, s3 string, c client.Client, cs *utils.CredentialService, b bool) error { - return fmt.Errorf(expectedErr) + return errors.New(expectedErr) }, refreshApp: refreshApplication, } @@ -2550,7 +2551,7 @@ var _ = Describe("Operation Controller", func() { expectedErr := "unable to terminate sync due to xyz reason" task.syncFuncs = &syncFuncs{ terminateOperation: func(ctx context.Context, s string, n corev1.Namespace, cs *utils.CredentialService, c client.Client, d time.Duration, l logr.Logger) error { - return fmt.Errorf(expectedErr) + return errors.New(expectedErr) }, } diff --git a/cluster-agent/utils/argocd_login_credentials.go b/cluster-agent/utils/argocd_login_credentials.go index 492e49bbdf..cc349bcb4e 100644 --- a/cluster-agent/utils/argocd_login_credentials.go +++ b/cluster-agent/utils/argocd_login_credentials.go @@ -2,6 +2,7 @@ package utils import ( "context" + "errors" "fmt" "strings" @@ -217,7 +218,7 @@ func (cs *CredentialService) getCredentialsFromNamespace(req credentialRequest, } if len(argoCDAdminPasswords) == 0 { - return nil, nil, fmt.Errorf("no Argo CD admin passwords found in " + req.namespaceName) + return nil, nil, errors.New("no Argo CD admin passwords found in " + req.namespaceName) } // Retrieve the Argo CD host name from the Route @@ -249,7 +250,7 @@ func (cs *CredentialService) getCredentialsFromNamespace(req credentialRequest, } } if serverHostName == "" { - return nil, nil, fmt.Errorf("Unable to locate Route in " + req.namespaceName) + return nil, nil, errors.New("Unable to locate Route in " + req.namespaceName) } acdClient, err := cs.acdClientGenerator.generateClientForServerAddress(serverHostName, "", skipTLSTest) @@ -258,7 +259,7 @@ func (cs *CredentialService) getCredentialsFromNamespace(req credentialRequest, } if acdClient == nil { - return nil, nil, fmt.Errorf("argo CD client was nil") + return nil, nil, errors.New("argo CD client was nil") } // Attempt to login with every password we found, skipping failures @@ -288,7 +289,7 @@ func (cs *CredentialService) getCredentialsFromNamespace(req credentialRequest, } } - return nil, nil, fmt.Errorf("unable to log in to Argo CD instance in " + req.namespaceName) + return nil, nil, errors.New("unable to log in to Argo CD instance in " + req.namespaceName) } diff --git a/tests-e2e/fixture/environment/fixture.go b/tests-e2e/fixture/environment/fixture.go index 92216955b5..64319f1ae9 100644 --- a/tests-e2e/fixture/environment/fixture.go +++ b/tests-e2e/fixture/environment/fixture.go @@ -47,7 +47,7 @@ func HaveEmptyEnvironmentConditions() matcher.GomegaMatcher { fmt.Println("EmptyEnvironmentConditions, env.Status.Conditions is:", env.Status.Conditions) - return env.Status.Conditions == nil || len(env.Status.Conditions) == 0 + return len(env.Status.Conditions) == 0 }) }