From cafaa761ec553896acf760c383f4a96dd7307c69 Mon Sep 17 00:00:00 2001 From: pashakostohrys Date: Fri, 27 Sep 2024 11:55:32 +0300 Subject: [PATCH] remove secrets and cm usage, also fix issue with latest revision as change one --- acr_controller/controller/controller.go | 5 +-- acr_controller/server.go | 46 ++++--------------------- reposerver/repository/repository.go | 13 ------- util/git/client.go | 5 +++ util/git/client_test.go | 14 ++++++++ 5 files changed, 26 insertions(+), 57 deletions(-) diff --git a/acr_controller/controller/controller.go b/acr_controller/controller/controller.go index b0c1944d6608f..61be564b7a02b 100644 --- a/acr_controller/controller/controller.go +++ b/acr_controller/controller/controller.go @@ -15,7 +15,6 @@ import ( appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" applisters "github.com/argoproj/argo-cd/v2/pkg/client/listers/application/v1alpha1" servercache "github.com/argoproj/argo-cd/v2/server/cache" - "github.com/argoproj/argo-cd/v2/util/settings" ) var watchAPIBufferSize = 1000 @@ -25,7 +24,6 @@ type ACRController interface { } type applicationChangeRevisionController struct { - settingsMgr *settings.SettingsManager appBroadcaster Broadcaster cache *servercache.Cache appLister applisters.ApplicationLister @@ -34,7 +32,7 @@ type applicationChangeRevisionController struct { applicationClientset appclientset.Interface } -func NewApplicationChangeRevisionController(appInformer cache.SharedIndexInformer, cache *servercache.Cache, settingsMgr *settings.SettingsManager, applicationServiceClient appclient.ApplicationClient, appLister applisters.ApplicationLister, applicationClientset appclientset.Interface) ACRController { +func NewApplicationChangeRevisionController(appInformer cache.SharedIndexInformer, cache *servercache.Cache, applicationServiceClient appclient.ApplicationClient, appLister applisters.ApplicationLister, applicationClientset appclientset.Interface) ACRController { appBroadcaster := NewBroadcaster() _, err := appInformer.AddEventHandler(appBroadcaster) if err != nil { @@ -43,7 +41,6 @@ func NewApplicationChangeRevisionController(appInformer cache.SharedIndexInforme return &applicationChangeRevisionController{ appBroadcaster: appBroadcaster, cache: cache, - settingsMgr: settingsMgr, applicationServiceClient: applicationServiceClient, appLister: appLister, applicationClientset: applicationClientset, diff --git a/acr_controller/server.go b/acr_controller/server.go index b79302216e506..9e0bfeb4a4988 100644 --- a/acr_controller/server.go +++ b/acr_controller/server.go @@ -6,13 +6,8 @@ import ( "fmt" "net" "net/http" - "strings" "time" - appclient "github.com/argoproj/argo-cd/v2/acr_controller/application" - acr_controller "github.com/argoproj/argo-cd/v2/acr_controller/controller" - "github.com/argoproj/argo-cd/v2/event_reporter/reporter" - "github.com/redis/go-redis/v9" log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -20,21 +15,17 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" + appclient "github.com/argoproj/argo-cd/v2/acr_controller/application" + acr_controller "github.com/argoproj/argo-cd/v2/acr_controller/controller" + appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned" appinformer "github.com/argoproj/argo-cd/v2/pkg/client/informers/externalversions" applisters "github.com/argoproj/argo-cd/v2/pkg/client/listers/application/v1alpha1" servercache "github.com/argoproj/argo-cd/v2/server/cache" - "github.com/argoproj/argo-cd/v2/util/db" - errorsutil "github.com/argoproj/argo-cd/v2/util/errors" "github.com/argoproj/argo-cd/v2/util/healthz" settings_util "github.com/argoproj/argo-cd/v2/util/settings" ) -const ( - // catches corrupted informer state; see https://github.com/argoproj/argo-cd/issues/4960 for more information - notObjectErrMsg = "object does not implement the Object interfaces" -) - var backoff = wait.Backoff{ Steps: 5, Duration: 500 * time.Millisecond, @@ -47,16 +38,13 @@ type ACRServer struct { settings *settings_util.ArgoCDSettings log *log.Entry - settingsMgr *settings_util.SettingsManager appInformer cache.SharedIndexInformer appLister applisters.ApplicationLister applicationClientset appclientset.Interface - db db.ArgoDB // stopCh is the channel which when closed, will shutdown the Event Reporter server - stopCh chan struct{} - serviceSet *ACRServerSet - featureManager *reporter.FeatureManager + stopCh chan struct{} + serviceSet *ACRServerSet } type ACRServerSet struct{} @@ -106,13 +94,6 @@ func (s *handlerSwitcher) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (a *ACRServer) healthCheck(r *http.Request) error { - if val, ok := r.URL.Query()["full"]; ok && len(val) > 0 && val[0] == "true" { - argoDB := db.NewDB(a.Namespace, a.settingsMgr, a.KubeClientset) - _, err := argoDB.ListClusters(r.Context()) - if err != nil && strings.Contains(err.Error(), notObjectErrMsg) { - return err - } - } return nil } @@ -124,7 +105,7 @@ func (a *ACRServer) Init(ctx context.Context) { } func (a *ACRServer) RunController(ctx context.Context) { - controller := acr_controller.NewApplicationChangeRevisionController(a.appInformer, a.Cache, a.settingsMgr, a.ApplicationServiceClient, a.appLister, a.applicationClientset) + controller := acr_controller.NewApplicationChangeRevisionController(a.appInformer, a.Cache, a.ApplicationServiceClient, a.appLister, a.applicationClientset) go controller.Run(ctx) } @@ -201,10 +182,6 @@ func (a *ACRServer) Run(ctx context.Context, lns *Listeners) { // NewServer returns a new instance of the Event Reporter server func NewApplicationChangeRevisionServer(ctx context.Context, opts ACRServerOpts) *ACRServer { - settingsMgr := settings_util.NewSettingsManager(ctx, opts.KubeClientset, opts.Namespace) - settings, err := settingsMgr.InitializeSettings(true) - errorsutil.CheckError(err) - appInformerNs := opts.Namespace if len(opts.ApplicationNamespaces) > 0 { appInformerNs = "" @@ -214,25 +191,14 @@ func NewApplicationChangeRevisionServer(ctx context.Context, opts ACRServerOpts) appInformer := appFactory.Argoproj().V1alpha1().Applications().Informer() appLister := appFactory.Argoproj().V1alpha1().Applications().Lister() - dbInstance := db.NewDB(opts.Namespace, settingsMgr, opts.KubeClientset) - server := &ACRServer{ ACRServerOpts: opts, log: log.NewEntry(log.StandardLogger()), - settings: settings, - settingsMgr: settingsMgr, appInformer: appInformer, appLister: appLister, - db: dbInstance, - featureManager: reporter.NewFeatureManager(settingsMgr), applicationClientset: opts.AppClientset, } - if err != nil { - // Just log. It's not critical. - log.Warnf("Failed to log in-cluster warnings: %v", err) - } - return server } diff --git a/reposerver/repository/repository.go b/reposerver/repository/repository.go index 16a184581ad97..1bcac2a51554b 100644 --- a/reposerver/repository/repository.go +++ b/reposerver/repository/repository.go @@ -3140,19 +3140,6 @@ func (s *Service) GetChangeRevision(ctx context.Context, request *apiclient.Chan return nil, status.Errorf(codes.Internal, "unable to checkout git repo %s with revision %s: %v", repo.Repo, revision, err) } defer io.Close(closer) - - files, err := gitClient.ChangedFiles(previousRevision, revision) - if err != nil { - return nil, status.Errorf(codes.Internal, "unable to get changed files for repo %s with revision %s: %v", repo.Repo, revision, err) - } - - changed := apppathutil.AppFilesHaveChanged(refreshPaths, files) - - if !changed { - logCtx.Debugf("no changes found for application %s in repo %s from revision %s to revision %s", request.AppName, repo.Repo, previousRevision, revision) - return &apiclient.ChangeRevisionResponse{}, nil - } - revisions, err := gitClient.ListRevisions(previousRevision, revision) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get revisions %s..%s", previousRevision, revision) diff --git a/util/git/client.go b/util/git/client.go index 19c83c15d8912..44a30993f3c75 100644 --- a/util/git/client.go +++ b/util/git/client.go @@ -910,6 +910,11 @@ func (m *nativeGitClient) ListRevisions(revision string, targetRevision string) if !IsCommitSHA(revision) || !IsCommitSHA(targetRevision) { return nil, fmt.Errorf("invalid revision provided, must be SHA") } + + if revision == targetRevision { + return []string{revision}, nil + } + out, err := m.runCmd("rev-list", "--ancestry-path", fmt.Sprintf("%s..%s", revision, targetRevision)) if err != nil { return nil, err diff --git a/util/git/client_test.go b/util/git/client_test.go index c5817fae34081..2603d2ee2d38e 100644 --- a/util/git/client_test.go +++ b/util/git/client_test.go @@ -296,3 +296,17 @@ func Test_IsRevisionPresent(t *testing.T) { revisionPresent = client.IsRevisionPresent("invalid-revision") assert.False(t, revisionPresent) } + +func Test_ListOfRevisionsContainSameRevision(t *testing.T) { + tempDir := t.TempDir() + + client, err := NewClientExt(fmt.Sprintf("file://%s", tempDir), tempDir, NopCreds{}, true, false, "") + require.NoError(t, err) + + err = client.Init() + require.NoError(t, err) + + revs, err := client.ListRevisions("15a9e18218d74c033d411316e6cbe5e45565875a", "15a9e18218d74c033d411316e6cbe5e45565875a") + require.NoError(t, err) + require.Equal(t, []string{"15a9e18218d74c033d411316e6cbe5e45565875a"}, revs) +}