Skip to content

Commit

Permalink
Make golangcilint happy
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan West <[email protected]>
  • Loading branch information
jgwest committed Sep 6, 2024
1 parent 447c175 commit 0cc706d
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package webhooks

import (
"context"
"errors"
"fmt"
"net/url"

Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"errors"
"fmt"

logutil "github.com/redhat-appstudio/managed-gitops/backend-shared/util/log"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"errors"
"fmt"
"net/url"

Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"errors"
"fmt"
"net/url"

Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"errors"
"fmt"

logutil "github.com/redhat-appstudio/managed-gitops/backend-shared/util/log"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion backend-shared/util/operations/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package operations

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion backend-shared/util/test_task_retry_loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"context"
"errors"
"fmt"
"math/rand"
"sync"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion backend-shared/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"context"
"errors"
"fmt"
"math/rand"
"os"
Expand Down Expand Up @@ -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:
}
Expand Down
4 changes: 2 additions & 2 deletions backend/condition/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package application_event_loop
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -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))

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package application_event_loop

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/eventloop/db_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package application_info_cache

import (
"context"
"errors"
"fmt"
"math/rand"
"time"
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eventloop
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eventloop
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
},
}

Expand Down
Loading

0 comments on commit 0cc706d

Please sign in to comment.