From 0657778ce8037d32e81cc2a4b18c84670d48297e Mon Sep 17 00:00:00 2001 From: oleksandr-codefresh Date: Fri, 16 May 2025 12:41:26 +0300 Subject: [PATCH 1/2] chore: sync all codefresh code changes into v3.0.2 without event-reporter related changes Signed-off-by: oleksandr-codefresh --- acr_controller/application/client.go | 8 +++-- acr_controller/controller/controller.go | 2 ++ acr_controller/server.go | 16 +++++++++- acr_controller/service/acr_service_test.go | 8 ++--- .../application_change_revision_controller.go | 4 +++ .../application_rollout_rollback.go | 32 +++++++++---------- .../application_validate_src_and_dest.go | 4 +-- server/application/cf_application.go | 4 +-- util/kustomize/repospec.go | 2 +- util/kustomize/repospec_test.go | 2 +- 10 files changed, 52 insertions(+), 30 deletions(-) diff --git a/acr_controller/application/client.go b/acr_controller/application/client.go index 08021c3148c53..bd2a23cda7ede 100644 --- a/acr_controller/application/client.go +++ b/acr_controller/application/client.go @@ -23,6 +23,7 @@ type httpApplicationClient struct { httpClient *http.Client baseURL string token string + rootpath string } func NewHTTPApplicationClient(token string, address string, rootpath string) ApplicationClient { @@ -46,13 +47,14 @@ func NewHTTPApplicationClient(token string, address string, rootpath string) App TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, }, - baseURL: address, - token: token, + baseURL: address, + token: token, + rootpath: rootpath, } } func (c *httpApplicationClient) execute(ctx context.Context, url string, result any) error { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return err } diff --git a/acr_controller/controller/controller.go b/acr_controller/controller/controller.go index b880b94f01243..fec5685567ebf 100644 --- a/acr_controller/controller/controller.go +++ b/acr_controller/controller/controller.go @@ -13,6 +13,8 @@ import ( appclientset "github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned" appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" + applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1" + servercache "github.com/argoproj/argo-cd/v3/server/cache" ) var watchAPIBufferSize = 1000 diff --git a/acr_controller/server.go b/acr_controller/server.go index 12bfc9bd8739d..0d78b2abd5c4b 100644 --- a/acr_controller/server.go +++ b/acr_controller/server.go @@ -2,11 +2,14 @@ package acr_controller import ( "context" + "crypto/tls" "fmt" "net" "net/http" "time" + applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1" + settings_util "github.com/argoproj/argo-cd/v3/util/settings" "github.com/redis/go-redis/v9" log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -33,11 +36,15 @@ var backoff = wait.Backoff{ type ACRServer struct { ACRServerOpts + settings *settings_util.ArgoCDSettings + log *log.Entry appInformer cache.SharedIndexInformer + appLister applisters.ApplicationLister applicationClientset appclientset.Interface // stopCh is the channel which when closed, will shutdown the Event Reporter server - stopCh chan struct{} + stopCh chan struct{} + serviceSet *ACRServerSet } type ACRServerSet struct{} @@ -156,6 +163,10 @@ func (a *ACRServer) Listen() (*Listeners, error) { // golang/protobuf). func (a *ACRServer) Run(ctx context.Context, lns *Listeners) { httpS := a.newHTTPServer(ctx, a.ListenPort) + tlsConfig := tls.Config{} + tlsConfig.GetCertificate = func(_ *tls.ClientHelloInfo) (*tls.Certificate, error) { + return a.settings.Certificate, nil + } go func() { a.checkServeErr("httpS", httpS.Serve(lns.Main)) }() go a.RunController(ctx) @@ -176,10 +187,13 @@ func NewApplicationChangeRevisionServer(_ context.Context, opts ACRServerOpts) * appFactory := appinformer.NewSharedInformerFactoryWithOptions(opts.AppClientset, 0, appinformer.WithNamespace(appInformerNs), appinformer.WithTweakListOptions(func(_ *metav1.ListOptions) {})) appInformer := appFactory.Argoproj().V1alpha1().Applications().Informer() + appLister := appFactory.Argoproj().V1alpha1().Applications().Lister() server := &ACRServer{ ACRServerOpts: opts, + log: log.NewEntry(log.StandardLogger()), appInformer: appInformer, + appLister: appLister, applicationClientset: opts.AppClientset, } diff --git a/acr_controller/service/acr_service_test.go b/acr_controller/service/acr_service_test.go index f1a451a89f995..4ca8dbc60ff2f 100644 --- a/acr_controller/service/acr_service_test.go +++ b/acr_controller/service/acr_service_test.go @@ -229,22 +229,22 @@ func Test_getRevisions(r *testing.T) { r.Run("history list is empty", func(t *testing.T) { acrService := newTestACRService(&mocks.ApplicationClient{}) current, previous := acrService.getRevisions(r.Context(), createTestApp(fakeApp)) - assert.Empty(t, current) - assert.Empty(t, previous) + assert.Equal(t, "", current) + assert.Equal(t, "", previous) }) r.Run("history list is empty, but operation happens right now", func(t *testing.T) { acrService := newTestACRService(&mocks.ApplicationClient{}) current, previous := acrService.getRevisions(r.Context(), createTestApp(fakeAppWithOperation)) assert.Equal(t, "c732f4d2ef24c7eeb900e9211ff98f90bb646505", current) - assert.Empty(t, previous) + assert.Equal(t, "", previous) }) r.Run("history list contains only one element, also sync result is here", func(t *testing.T) { acrService := newTestACRService(&mocks.ApplicationClient{}) current, previous := acrService.getRevisions(r.Context(), createTestApp(syncedAppWithSingleHistory)) assert.Equal(t, "c732f4d2ef24c7eeb900e9211ff98f90bb646505", current) - assert.Empty(t, previous) + assert.Equal(t, "", previous) }) r.Run("application is synced", func(t *testing.T) { diff --git a/cmd/application-change-revision-controller/commands/application_change_revision_controller.go b/cmd/application-change-revision-controller/commands/application_change_revision_controller.go index 28df2ed3da87a..433aab91a6ff6 100644 --- a/cmd/application-change-revision-controller/commands/application_change_revision_controller.go +++ b/cmd/application-change-revision-controller/commands/application_change_revision_controller.go @@ -128,9 +128,13 @@ func NewCommand() *cobra.Command { lns, err := changeRevisionServer.Listen() errors.CheckError(err) for { + var closer func() ctx, cancel := context.WithCancel(ctx) changeRevisionServer.Run(ctx, lns) cancel() + if closer != nil { + closer() + } } }, } diff --git a/server/application/application_rollout_rollback.go b/server/application/application_rollout_rollback.go index 2168b14cf85c8..ad2dc24017107 100644 --- a/server/application/application_rollout_rollback.go +++ b/server/application/application_rollout_rollback.go @@ -78,22 +78,22 @@ func (s *Server) getRsOfSpecificRevision(ctx context.Context, config *rest.Confi if err != nil { return nil, fmt.Errorf("error getting resource: %w", err) } - v := resource.GetRevision(rsliveObj) - switch toRevision { - case 0: - if latestRevision < v { - // newest one we've seen so far - previousRevision = latestRevision - previousReplicaSet = latestReplicaSet - latestRevision = v - latestReplicaSet = rsliveObj - } else if previousRevision < v { - // second newest one we've seen so far - previousRevision = v - previousReplicaSet = rsliveObj + if v := resource.GetRevision(rsliveObj); err == nil { + if toRevision == 0 { + if latestRevision < v { + // newest one we've seen so far + previousRevision = latestRevision + previousReplicaSet = latestReplicaSet + latestRevision = v + latestReplicaSet = rsliveObj + } else if previousRevision < v { + // second newest one we've seen so far + previousRevision = v + previousReplicaSet = rsliveObj + } + } else if toRevision == v { + return rsliveObj, nil } - case v: - return rsliveObj, nil } } @@ -138,7 +138,7 @@ func (s *Server) getReplicaSetForRolloutRollack(ctx context.Context, config *res rolloutGVK := getRolloutGVK() foundRolloutNode := tree.FindNode(rolloutGVK.Group, rolloutGVK.Kind, q.GetRolloutNamespace(), q.GetRolloutName()) - if foundRolloutNode == nil || foundRolloutNode.UID == "" { + if foundRolloutNode == nil || foundRolloutNode.ResourceRef.UID == "" { return nil, status.Errorf(codes.InvalidArgument, "%s %s %s not found as part of application %s", rolloutGVK.Kind, rolloutGVK.Group, q.GetRolloutName(), q.GetName()) } diff --git a/server/application/application_validate_src_and_dest.go b/server/application/application_validate_src_and_dest.go index d79a26ede132e..87fb2ddb137e4 100644 --- a/server/application/application_validate_src_and_dest.go +++ b/server/application/application_validate_src_and_dest.go @@ -37,7 +37,7 @@ func (s *Server) ValidateSrcAndDst(ctx context.Context, requset *application.App if err := validateDestination(ctx, &app.Spec.Destination, s.db); err != nil { entity := destinationEntity - errMsg := fmt.Sprintf("application destination spec for %s is invalid: %s", app.Name, err.Error()) + errMsg := fmt.Sprintf("application destination spec for %s is invalid: %s", app.ObjectMeta.Name, err.Error()) return &application.ApplicationValidateResponse{ Error: &errMsg, Entity: &entity, @@ -55,7 +55,7 @@ func (s *Server) ValidateSrcAndDst(ctx context.Context, requset *application.App } if len(conditions) > 0 { entity := sourceEntity - errMsg := fmt.Sprintf("application spec for %s is invalid: %s", app.Name, argo.FormatAppConditions(conditions)) + errMsg := fmt.Sprintf("application spec for %s is invalid: %s", app.ObjectMeta.Name, argo.FormatAppConditions(conditions)) return &application.ApplicationValidateResponse{ Error: &errMsg, Entity: &entity, diff --git a/server/application/cf_application.go b/server/application/cf_application.go index 40d04210dd5e2..7f6785885539b 100644 --- a/server/application/cf_application.go +++ b/server/application/cf_application.go @@ -12,7 +12,7 @@ import ( appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/reposerver/apiclient" "github.com/argoproj/argo-cd/v3/util/app/path" - utilio "github.com/argoproj/argo-cd/v3/util/io" + ioutil "github.com/argoproj/argo-cd/v3/util/io" ) const ( @@ -41,7 +41,7 @@ func (s *Server) GetChangeRevision(ctx context.Context, in *application.ChangeRe if err != nil { return nil, fmt.Errorf("error creating repo server client: %w", err) } - defer utilio.Close(closer) + defer ioutil.Close(closer) response, err := client.GetChangeRevision(ctx, &apiclient.ChangeRevisionRequest{ AppName: in.GetAppName(), diff --git a/util/kustomize/repospec.go b/util/kustomize/repospec.go index 3fa38cdc443f2..839483795ee86 100644 --- a/util/kustomize/repospec.go +++ b/util/kustomize/repospec.go @@ -34,7 +34,7 @@ func parseGitURL(n string) ( index := strings.Index(n, gitSuffix) orgRepo = n[0:index] n = n[index+len(gitSuffix):] - if n != "" && n[0] == '/' { + if len(n) > 0 && n[0] == '/' { n = n[1:] } path, gitRef = peelQuery(n) diff --git a/util/kustomize/repospec_test.go b/util/kustomize/repospec_test.go index 34d586e5d00a6..1a18064071033 100644 --- a/util/kustomize/repospec_test.go +++ b/util/kustomize/repospec_test.go @@ -43,7 +43,7 @@ var hostNamesRawAndNormalized = [][]string{ } func makeURL(hostFmt, orgRepo, path, href string) string { - if path != "" { + if len(path) > 0 { orgRepo = filepath.Join(orgRepo, path) } url := hostFmt + orgRepo From 65558c0314bed27f2242786bc562095ce4b61066 Mon Sep 17 00:00:00 2001 From: Patroklos Papapetrou Date: Wed, 29 Oct 2025 17:59:08 +0200 Subject: [PATCH 2/2] fix validateDestination --- acr_controller/application/client.go | 8 ++--- acr_controller/controller/controller.go | 2 -- acr_controller/server.go | 16 +--------- acr_controller/service/acr_service_test.go | 8 ++--- .../application_change_revision_controller.go | 4 --- .../application_rollout_rollback.go | 32 +++++++++---------- .../application_validate_src_and_dest.go | 25 ++------------- server/application/cf_application.go | 4 +-- util/kustomize/repospec.go | 2 +- util/kustomize/repospec_test.go | 2 +- 10 files changed, 31 insertions(+), 72 deletions(-) diff --git a/acr_controller/application/client.go b/acr_controller/application/client.go index bd2a23cda7ede..08021c3148c53 100644 --- a/acr_controller/application/client.go +++ b/acr_controller/application/client.go @@ -23,7 +23,6 @@ type httpApplicationClient struct { httpClient *http.Client baseURL string token string - rootpath string } func NewHTTPApplicationClient(token string, address string, rootpath string) ApplicationClient { @@ -47,14 +46,13 @@ func NewHTTPApplicationClient(token string, address string, rootpath string) App TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, }, - baseURL: address, - token: token, - rootpath: rootpath, + baseURL: address, + token: token, } } func (c *httpApplicationClient) execute(ctx context.Context, url string, result any) error { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody) if err != nil { return err } diff --git a/acr_controller/controller/controller.go b/acr_controller/controller/controller.go index fec5685567ebf..b880b94f01243 100644 --- a/acr_controller/controller/controller.go +++ b/acr_controller/controller/controller.go @@ -13,8 +13,6 @@ import ( appclientset "github.com/argoproj/argo-cd/v3/pkg/client/clientset/versioned" appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" - applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1" - servercache "github.com/argoproj/argo-cd/v3/server/cache" ) var watchAPIBufferSize = 1000 diff --git a/acr_controller/server.go b/acr_controller/server.go index 0d78b2abd5c4b..12bfc9bd8739d 100644 --- a/acr_controller/server.go +++ b/acr_controller/server.go @@ -2,14 +2,11 @@ package acr_controller import ( "context" - "crypto/tls" "fmt" "net" "net/http" "time" - applisters "github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1" - settings_util "github.com/argoproj/argo-cd/v3/util/settings" "github.com/redis/go-redis/v9" log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -36,15 +33,11 @@ var backoff = wait.Backoff{ type ACRServer struct { ACRServerOpts - settings *settings_util.ArgoCDSettings - log *log.Entry appInformer cache.SharedIndexInformer - appLister applisters.ApplicationLister applicationClientset appclientset.Interface // stopCh is the channel which when closed, will shutdown the Event Reporter server - stopCh chan struct{} - serviceSet *ACRServerSet + stopCh chan struct{} } type ACRServerSet struct{} @@ -163,10 +156,6 @@ func (a *ACRServer) Listen() (*Listeners, error) { // golang/protobuf). func (a *ACRServer) Run(ctx context.Context, lns *Listeners) { httpS := a.newHTTPServer(ctx, a.ListenPort) - tlsConfig := tls.Config{} - tlsConfig.GetCertificate = func(_ *tls.ClientHelloInfo) (*tls.Certificate, error) { - return a.settings.Certificate, nil - } go func() { a.checkServeErr("httpS", httpS.Serve(lns.Main)) }() go a.RunController(ctx) @@ -187,13 +176,10 @@ func NewApplicationChangeRevisionServer(_ context.Context, opts ACRServerOpts) * appFactory := appinformer.NewSharedInformerFactoryWithOptions(opts.AppClientset, 0, appinformer.WithNamespace(appInformerNs), appinformer.WithTweakListOptions(func(_ *metav1.ListOptions) {})) appInformer := appFactory.Argoproj().V1alpha1().Applications().Informer() - appLister := appFactory.Argoproj().V1alpha1().Applications().Lister() server := &ACRServer{ ACRServerOpts: opts, - log: log.NewEntry(log.StandardLogger()), appInformer: appInformer, - appLister: appLister, applicationClientset: opts.AppClientset, } diff --git a/acr_controller/service/acr_service_test.go b/acr_controller/service/acr_service_test.go index 4ca8dbc60ff2f..f1a451a89f995 100644 --- a/acr_controller/service/acr_service_test.go +++ b/acr_controller/service/acr_service_test.go @@ -229,22 +229,22 @@ func Test_getRevisions(r *testing.T) { r.Run("history list is empty", func(t *testing.T) { acrService := newTestACRService(&mocks.ApplicationClient{}) current, previous := acrService.getRevisions(r.Context(), createTestApp(fakeApp)) - assert.Equal(t, "", current) - assert.Equal(t, "", previous) + assert.Empty(t, current) + assert.Empty(t, previous) }) r.Run("history list is empty, but operation happens right now", func(t *testing.T) { acrService := newTestACRService(&mocks.ApplicationClient{}) current, previous := acrService.getRevisions(r.Context(), createTestApp(fakeAppWithOperation)) assert.Equal(t, "c732f4d2ef24c7eeb900e9211ff98f90bb646505", current) - assert.Equal(t, "", previous) + assert.Empty(t, previous) }) r.Run("history list contains only one element, also sync result is here", func(t *testing.T) { acrService := newTestACRService(&mocks.ApplicationClient{}) current, previous := acrService.getRevisions(r.Context(), createTestApp(syncedAppWithSingleHistory)) assert.Equal(t, "c732f4d2ef24c7eeb900e9211ff98f90bb646505", current) - assert.Equal(t, "", previous) + assert.Empty(t, previous) }) r.Run("application is synced", func(t *testing.T) { diff --git a/cmd/application-change-revision-controller/commands/application_change_revision_controller.go b/cmd/application-change-revision-controller/commands/application_change_revision_controller.go index 433aab91a6ff6..28df2ed3da87a 100644 --- a/cmd/application-change-revision-controller/commands/application_change_revision_controller.go +++ b/cmd/application-change-revision-controller/commands/application_change_revision_controller.go @@ -128,13 +128,9 @@ func NewCommand() *cobra.Command { lns, err := changeRevisionServer.Listen() errors.CheckError(err) for { - var closer func() ctx, cancel := context.WithCancel(ctx) changeRevisionServer.Run(ctx, lns) cancel() - if closer != nil { - closer() - } } }, } diff --git a/server/application/application_rollout_rollback.go b/server/application/application_rollout_rollback.go index ad2dc24017107..2168b14cf85c8 100644 --- a/server/application/application_rollout_rollback.go +++ b/server/application/application_rollout_rollback.go @@ -78,22 +78,22 @@ func (s *Server) getRsOfSpecificRevision(ctx context.Context, config *rest.Confi if err != nil { return nil, fmt.Errorf("error getting resource: %w", err) } - if v := resource.GetRevision(rsliveObj); err == nil { - if toRevision == 0 { - if latestRevision < v { - // newest one we've seen so far - previousRevision = latestRevision - previousReplicaSet = latestReplicaSet - latestRevision = v - latestReplicaSet = rsliveObj - } else if previousRevision < v { - // second newest one we've seen so far - previousRevision = v - previousReplicaSet = rsliveObj - } - } else if toRevision == v { - return rsliveObj, nil + v := resource.GetRevision(rsliveObj) + switch toRevision { + case 0: + if latestRevision < v { + // newest one we've seen so far + previousRevision = latestRevision + previousReplicaSet = latestReplicaSet + latestRevision = v + latestReplicaSet = rsliveObj + } else if previousRevision < v { + // second newest one we've seen so far + previousRevision = v + previousReplicaSet = rsliveObj } + case v: + return rsliveObj, nil } } @@ -138,7 +138,7 @@ func (s *Server) getReplicaSetForRolloutRollack(ctx context.Context, config *res rolloutGVK := getRolloutGVK() foundRolloutNode := tree.FindNode(rolloutGVK.Group, rolloutGVK.Kind, q.GetRolloutNamespace(), q.GetRolloutName()) - if foundRolloutNode == nil || foundRolloutNode.ResourceRef.UID == "" { + if foundRolloutNode == nil || foundRolloutNode.UID == "" { return nil, status.Errorf(codes.InvalidArgument, "%s %s %s not found as part of application %s", rolloutGVK.Kind, rolloutGVK.Group, q.GetRolloutName(), q.GetName()) } diff --git a/server/application/application_validate_src_and_dest.go b/server/application/application_validate_src_and_dest.go index 87fb2ddb137e4..94eb1f8033242 100644 --- a/server/application/application_validate_src_and_dest.go +++ b/server/application/application_validate_src_and_dest.go @@ -5,8 +5,6 @@ import ( "errors" "fmt" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" apierrors "k8s.io/apimachinery/pkg/api/errors" "github.com/argoproj/argo-cd/v3/pkg/apiclient/application" @@ -37,7 +35,7 @@ func (s *Server) ValidateSrcAndDst(ctx context.Context, requset *application.App if err := validateDestination(ctx, &app.Spec.Destination, s.db); err != nil { entity := destinationEntity - errMsg := fmt.Sprintf("application destination spec for %s is invalid: %s", app.ObjectMeta.Name, err.Error()) + errMsg := fmt.Sprintf("application destination spec for %s is invalid: %s", app.Name, err.Error()) return &application.ApplicationValidateResponse{ Error: &errMsg, Entity: &entity, @@ -55,7 +53,7 @@ func (s *Server) ValidateSrcAndDst(ctx context.Context, requset *application.App } if len(conditions) > 0 { entity := sourceEntity - errMsg := fmt.Sprintf("application spec for %s is invalid: %s", app.ObjectMeta.Name, argo.FormatAppConditions(conditions)) + errMsg := fmt.Sprintf("application spec for %s is invalid: %s", app.Name, argo.FormatAppConditions(conditions)) return &application.ApplicationValidateResponse{ Error: &errMsg, Entity: &entity, @@ -73,22 +71,5 @@ func validateDestination(ctx context.Context, dest *appv1.ApplicationDestination return errors.New("no destination defined in app spec") } _, err := argo.GetDestinationCluster(ctx, *dest, db) - if err != nil { - return err - } - - if dest.Server != "" { - // Ensure the k8s cluster the app is referencing, is configured in Argo CD - _, err := db.GetCluster(ctx, dest.Server) - if err != nil { - if errStatus, ok := status.FromError(err); ok && errStatus.Code() == codes.NotFound { - return fmt.Errorf("cluster '%s' has not been configured", dest.Server) - } - return err - } - } else if dest.Server == "" { - return errors.New("destination server missing from app spec") - } - - return nil + return err } diff --git a/server/application/cf_application.go b/server/application/cf_application.go index 7f6785885539b..40d04210dd5e2 100644 --- a/server/application/cf_application.go +++ b/server/application/cf_application.go @@ -12,7 +12,7 @@ import ( appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" "github.com/argoproj/argo-cd/v3/reposerver/apiclient" "github.com/argoproj/argo-cd/v3/util/app/path" - ioutil "github.com/argoproj/argo-cd/v3/util/io" + utilio "github.com/argoproj/argo-cd/v3/util/io" ) const ( @@ -41,7 +41,7 @@ func (s *Server) GetChangeRevision(ctx context.Context, in *application.ChangeRe if err != nil { return nil, fmt.Errorf("error creating repo server client: %w", err) } - defer ioutil.Close(closer) + defer utilio.Close(closer) response, err := client.GetChangeRevision(ctx, &apiclient.ChangeRevisionRequest{ AppName: in.GetAppName(), diff --git a/util/kustomize/repospec.go b/util/kustomize/repospec.go index 839483795ee86..3fa38cdc443f2 100644 --- a/util/kustomize/repospec.go +++ b/util/kustomize/repospec.go @@ -34,7 +34,7 @@ func parseGitURL(n string) ( index := strings.Index(n, gitSuffix) orgRepo = n[0:index] n = n[index+len(gitSuffix):] - if len(n) > 0 && n[0] == '/' { + if n != "" && n[0] == '/' { n = n[1:] } path, gitRef = peelQuery(n) diff --git a/util/kustomize/repospec_test.go b/util/kustomize/repospec_test.go index 1a18064071033..34d586e5d00a6 100644 --- a/util/kustomize/repospec_test.go +++ b/util/kustomize/repospec_test.go @@ -43,7 +43,7 @@ var hostNamesRawAndNormalized = [][]string{ } func makeURL(hostFmt, orgRepo, path, href string) string { - if len(path) > 0 { + if path != "" { orgRepo = filepath.Join(orgRepo, path) } url := hostFmt + orgRepo