Skip to content

Commit

Permalink
Merge branch 'release-2.12' of github.com:codefresh-io/argo-cd into C…
Browse files Browse the repository at this point in the history
…R-23842-revisions-info-reporting
  • Loading branch information
oleksandr-codefresh committed Sep 27, 2024
2 parents a9c0b2c + 931199e commit 7e1f1c2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 57 deletions.
5 changes: 1 addition & 4 deletions acr_controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +24,6 @@ type ACRController interface {
}

type applicationChangeRevisionController struct {
settingsMgr *settings.SettingsManager
appBroadcaster Broadcaster
cache *servercache.Cache
appLister applisters.ApplicationLister
Expand All @@ -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 {
Expand All @@ -43,7 +41,6 @@ func NewApplicationChangeRevisionController(appInformer cache.SharedIndexInforme
return &applicationChangeRevisionController{
appBroadcaster: appBroadcaster,
cache: cache,
settingsMgr: settingsMgr,
applicationServiceClient: applicationServiceClient,
appLister: appLister,
applicationClientset: applicationClientset,
Expand Down
46 changes: 6 additions & 40 deletions acr_controller/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,26 @@ 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"
"k8s.io/apimachinery/pkg/util/wait"
"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,
Expand All @@ -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{}
Expand Down Expand Up @@ -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
}

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

Expand Down Expand Up @@ -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 = ""
Expand All @@ -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
}

Expand Down
13 changes: 0 additions & 13 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions util/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions util/git/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 7e1f1c2

Please sign in to comment.