Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <[email protected]>
  • Loading branch information
crenshaw-dev committed Oct 8, 2024
1 parent 87a3ffe commit f5e91ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
4 changes: 1 addition & 3 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ type ApplicationController struct {
statusRefreshJitter time.Duration
selfHealTimeout time.Duration
repoClientset apiclient.Clientset
commitClientset commitclient.Clientset
db db.ArgoDB
settingsMgr *settings_util.SettingsManager
refreshRequestedApps map[string]CompareWith
Expand Down Expand Up @@ -196,7 +195,6 @@ func NewApplicationController(
kubectl: kubectl,
applicationClientset: applicationClientset,
repoClientset: repoClientset,
commitClientset: commitClientset,
appRefreshQueue: workqueue.NewTypedRateLimitingQueueWithConfig(ratelimiter.NewCustomAppControllerRateLimiter[string](rateLimiterConfig), workqueue.TypedRateLimitingQueueConfig[string]{Name: "app_reconciliation_queue"}),
appOperationQueue: workqueue.NewTypedRateLimitingQueueWithConfig(ratelimiter.NewCustomAppControllerRateLimiter[string](rateLimiterConfig), workqueue.TypedRateLimitingQueueConfig[string]{Name: "app_operation_processing_queue"}),
projectRefreshQueue: workqueue.NewTypedRateLimitingQueueWithConfig(ratelimiter.NewCustomAppControllerRateLimiter[string](rateLimiterConfig), workqueue.TypedRateLimitingQueueConfig[string]{Name: "project_reconciliation_queue"}),
Expand All @@ -219,7 +217,7 @@ func NewApplicationController(
ignoreNormalizerOpts: ignoreNormalizerOpts,
}
if hydratorEnabled {
ctrl.hydrator = hydrator.NewHydrator(&ctrl, appResyncPeriod)
ctrl.hydrator = hydrator.NewHydrator(&ctrl, appResyncPeriod, commitClientset)
}
if kubectlParallelismLimit > 0 {
ctrl.kubectlSemaphore = semaphore.NewWeighted(kubectlParallelismLimit)
Expand Down
17 changes: 8 additions & 9 deletions controller/hydrator/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
argoio "github.com/argoproj/argo-cd/v2/util/io"
log "github.com/sirupsen/logrus"
"io"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"time"
Expand All @@ -28,22 +27,22 @@ type Dependencies interface {
GetWriteCredentials(ctx context.Context, repoURL string) (*appv1.Repository, error)
ResolveGitRevision(repoURL, targetRevision string) (string, error)
RequestAppRefresh(appName string)
// TODO: remove this and instantiate the client and hydrator in the app controller command
GetCommitServerClient() (io.Closer, commitclient.CommitServiceClient, error)
// TODO: only allow access to the hydrator status
PersistAppStatus(orig *appv1.Application, newStatus *appv1.ApplicationStatus)
PersistAppHydratorStatus(orig *appv1.Application, newStatus *appv1.SourceHydratorStatus)
AddHydrationQueueItem(key HydrationQueueKey)
}

type Hydrator struct {
dependencies Dependencies
statusRefreshTimeout time.Duration
commitClientset commitclient.Clientset
}

func NewHydrator(dependencies Dependencies, statusRefreshTimeout time.Duration) *Hydrator {
func NewHydrator(dependencies Dependencies, statusRefreshTimeout time.Duration, commitClientset commitclient.Clientset) *Hydrator {
return &Hydrator{
dependencies: dependencies,
statusRefreshTimeout: statusRefreshTimeout,
commitClientset: commitClientset,
}
}

Expand Down Expand Up @@ -85,7 +84,7 @@ func (h *Hydrator) ProcessAppHydrateQueueItem(origApp *appv1.Application) {
Phase: appv1.HydrateOperationPhaseHydrating,
SourceHydrator: *app.Spec.SourceHydrator,
}
h.dependencies.PersistAppStatus(origApp, &app.Status)
h.dependencies.PersistAppHydratorStatus(origApp, &app.Status.SourceHydrator)
origApp.Status.SourceHydrator = app.Status.SourceHydrator
h.dependencies.AddHydrationQueueItem(getHydrationQueueKey(app))

Expand Down Expand Up @@ -136,7 +135,7 @@ func (h *Hydrator) ProcessHydrationQueueItem(hydrationKey HydrationQueueKey) (pr
failedAt := metav1.Now()
app.Status.SourceHydrator.CurrentOperation.FinishedAt = &failedAt
app.Status.SourceHydrator.CurrentOperation.Message = fmt.Sprintf("Failed to hydrated revision %s: %v", drySHA, err.Error())
h.dependencies.PersistAppStatus(origApp, &app.Status)
h.dependencies.PersistAppHydratorStatus(origApp, &app.Status.SourceHydrator)
logCtx.Errorf("Failed to hydrate app: %v", err)
}
return
Expand All @@ -160,7 +159,7 @@ func (h *Hydrator) ProcessHydrationQueueItem(hydrationKey HydrationQueueKey) (pr
HydratedSHA: hydratedSHA,
SourceHydrator: app.Status.SourceHydrator.CurrentOperation.SourceHydrator,
}
h.dependencies.PersistAppStatus(origApp, &app.Status)
h.dependencies.PersistAppHydratorStatus(origApp, &app.Status.SourceHydrator)
// Request a refresh since we pushed a new commit.
h.dependencies.RequestAppRefresh(app.QualifiedName())
}
Expand Down Expand Up @@ -304,7 +303,7 @@ func (h *Hydrator) hydrate(apps []*appv1.Application, revision string) (string,
Paths: paths,
}

closer, commitService, err := h.dependencies.GetCommitServerClient()
closer, commitService, err := h.commitClientset.NewCommitServerClient()
if err != nil {
return "", fmt.Errorf("failed to create commit service: %w", err)
}
Expand Down
13 changes: 4 additions & 9 deletions controller/hydrator_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package controller
import (
"context"
"fmt"
"io"

commitclient "github.com/argoproj/argo-cd/v2/commitserver/apiclient"
"github.com/argoproj/argo-cd/v2/controller/hydrator"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
Expand Down Expand Up @@ -65,12 +62,10 @@ func (ctrl *ApplicationController) RequestAppRefresh(appName string) {
ctrl.requestAppRefresh(appName, CompareWithLatest.Pointer(), nil)
}

func (ctrl *ApplicationController) GetCommitServerClient() (io.Closer, commitclient.CommitServiceClient, error) {
return ctrl.commitClientset.NewCommitServerClient()
}

func (ctrl *ApplicationController) PersistAppStatus(orig *appv1.Application, newStatus *appv1.ApplicationStatus) {
ctrl.persistAppStatus(orig, newStatus)
func (ctrl *ApplicationController) PersistAppHydratorStatus(orig *appv1.Application, newStatus *appv1.SourceHydratorStatus) {
status := orig.Status.DeepCopy()
status.SourceHydrator = *newStatus
ctrl.persistAppStatus(orig, status)
}

func (ctrl *ApplicationController) AddHydrationQueueItem(key hydrator.HydrationQueueKey) {
Expand Down

0 comments on commit f5e91ef

Please sign in to comment.