Skip to content

Commit

Permalink
feat: version support (#293)
Browse files Browse the repository at this point in the history
* Revert "fix: revert version config (#292)"

This reverts commit 54e24b1.

* add changelog
  • Loading branch information
pasha-codefresh authored Feb 29, 2024
1 parent d252c10 commit 0f82ce2
Show file tree
Hide file tree
Showing 34 changed files with 735 additions and 828 deletions.
2 changes: 2 additions & 0 deletions changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Features
- feat(event_reporter): report chart version as part of manifest for environment feature
55 changes: 36 additions & 19 deletions cmd/argocd-repo-server/commands/argocd_repo_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

cmdutil "github.com/argoproj/argo-cd/v2/cmd/util"
"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/pkg/codefresh"
"github.com/argoproj/argo-cd/v2/reposerver"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/argoproj/argo-cd/v2/reposerver/askpass"
Expand Down Expand Up @@ -48,25 +49,29 @@ var (

func NewCommand() *cobra.Command {
var (
parallelismLimit int64
listenPort int
listenHost string
metricsPort int
metricsHost string
otlpAddress string
otlpAttrs []string
cacheSrc func() (*reposervercache.Cache, error)
tlsConfigCustomizer tls.ConfigCustomizer
tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error)
redisClient *redis.Client
disableTLS bool
maxCombinedDirectoryManifestsSize string
cmpTarExcludedGlobs []string
allowOutOfBoundsSymlinks bool
streamedManifestMaxTarSize string
streamedManifestMaxExtractedSize string
helmManifestMaxExtractedSize string
disableManifestMaxExtractedSize bool
parallelismLimit int64
listenPort int
listenHost string
metricsPort int
metricsHost string
otlpAddress string
otlpAttrs []string
cacheSrc func() (*reposervercache.Cache, error)
tlsConfigCustomizer tls.ConfigCustomizer
tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error)
redisClient *redis.Client
disableTLS bool
maxCombinedDirectoryManifestsSize string
cmpTarExcludedGlobs []string
allowOutOfBoundsSymlinks bool
streamedManifestMaxTarSize string
streamedManifestMaxExtractedSize string
helmManifestMaxExtractedSize string
disableManifestMaxExtractedSize bool
codefreshUrl string
codefreshToken string
codefreshApplicationVersioningEnabled bool
codefreshUseApplicationConfiguration bool
)
var command = cobra.Command{
Use: cliName,
Expand Down Expand Up @@ -123,6 +128,12 @@ func NewCommand() *cobra.Command {
StreamedManifestMaxExtractedSize: streamedManifestMaxExtractedSizeQuantity.ToDec().Value(),
StreamedManifestMaxTarSize: streamedManifestMaxTarSizeQuantity.ToDec().Value(),
HelmManifestMaxExtractedSize: helmManifestMaxExtractedSizeQuantity.ToDec().Value(),
CodefreshApplicationVersioningEnabled: codefreshApplicationVersioningEnabled,
CodefreshUseApplicationConfiguration: codefreshUseApplicationConfiguration,
CodefreshConfig: codefresh.CodefreshConfig{
BaseURL: codefreshUrl,
AuthToken: codefreshToken,
},
}, askPassServer)
errors.CheckError(err)

Expand Down Expand Up @@ -188,6 +199,12 @@ func NewCommand() *cobra.Command {
return nil
},
}
// *** CF specific variables ***
command.Flags().StringVar(&codefreshUrl, "codefresh-url", env.StringFromEnv("CODEFRESH_URL", "https://g.codefresh.io"), "Codefresh API URL")
command.Flags().StringVar(&codefreshToken, "codefresh-token", env.StringFromEnv("CODEFRESH_TOKEN", ""), "Codefresh token")
command.Flags().BoolVar(&codefreshApplicationVersioningEnabled, "codefresh-application-version-enabled", env.ParseBoolFromEnv("CODEFRESH_APPVERSION_ENABLED", true), "Allow Codefresh application versioning")
command.Flags().BoolVar(&codefreshUseApplicationConfiguration, "codefresh-application-version-use-appconfig", env.ParseBoolFromEnv("CODEFRESH_APPVERSION_USE_APPCONFIG", true), "Allow getting application configuration from the Codefresh API")

command.Flags().StringVar(&cmdutil.LogFormat, "logformat", env.StringFromEnv("ARGOCD_REPO_SERVER_LOGFORMAT", "text"), "Set the logging format. One of: text|json")
command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", env.StringFromEnv("ARGOCD_REPO_SERVER_LOGLEVEL", "info"), "Set the logging level. One of: debug|info|warn|error")
command.Flags().Int64Var(&parallelismLimit, "parallelismlimit", int64(env.ParseNumFromEnv("ARGOCD_REPO_SERVER_PARALLELISM_LIMIT", 0, 0, math.MaxInt32)), "Limit on number of concurrent manifests generate requests. Any value less the 1 means no limit.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/argoproj/argo-cd/v2/event_reporter"
appclient "github.com/argoproj/argo-cd/v2/event_reporter/application"
"github.com/argoproj/argo-cd/v2/event_reporter/codefresh"
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
"github.com/argoproj/argo-cd/v2/pkg/codefresh"

"github.com/argoproj/pkg/stats"
"github.com/redis/go-redis/v9"
Expand Down
44 changes: 22 additions & 22 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,28 @@ func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, sources []v1alp
ts.AddCheckpoint("version_ms")
log.Debugf("Generating Manifest for source %s revision %s, cache %t, revisionCache %t", source, revisions[i], !noCache, noRevisionCache)
manifestInfo, err := repoClient.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
Repo: repo,
Repos: permittedHelmRepos,
Revision: revisions[i],
NoCache: noCache,
NoRevisionCache: noRevisionCache,
AppLabelKey: appLabelKey,
AppName: app.InstanceName(m.namespace),
Namespace: app.Spec.Destination.Namespace,
ApplicationSource: &source,
KustomizeOptions: kustomizeOptions,
KubeVersion: serverVersion,
ApiVersions: argo.APIResourcesToStrings(apiResources, true),
VerifySignature: verifySignature,
HelmRepoCreds: permittedHelmCredentials,
TrackingMethod: string(argo.GetTrackingMethod(m.settingsMgr)),
EnabledSourceTypes: enabledSourceTypes,
HelmOptions: helmOptions,
HasMultipleSources: app.Spec.HasMultipleSources(),
RefSources: refSources,
ProjectName: proj.Name,
ProjectSourceRepos: proj.Spec.SourceRepos,
VersionConfig: apiclient.GetVersionConfig(),
Repo: repo,
Repos: permittedHelmRepos,
Revision: revisions[i],
NoCache: noCache,
NoRevisionCache: noRevisionCache,
AppLabelKey: appLabelKey,
AppName: app.InstanceName(m.namespace),
Namespace: app.Spec.Destination.Namespace,
ApplicationSource: &source,
KustomizeOptions: kustomizeOptions,
KubeVersion: serverVersion,
ApiVersions: argo.APIResourcesToStrings(apiResources, true),
VerifySignature: verifySignature,
HelmRepoCreds: permittedHelmCredentials,
TrackingMethod: string(argo.GetTrackingMethod(m.settingsMgr)),
EnabledSourceTypes: enabledSourceTypes,
HelmOptions: helmOptions,
HasMultipleSources: app.Spec.HasMultipleSources(),
RefSources: refSources,
ProjectName: proj.Name,
ProjectSourceRepos: proj.Spec.SourceRepos,
ApplicationMetadata: &app.ObjectMeta,
})
if err != nil {
return nil, nil, fmt.Errorf("failed to generate manifest for source %d of %d: %w", i+1, len(sources), err)
Expand Down
78 changes: 0 additions & 78 deletions event_reporter/codefresh/client.go

This file was deleted.

2 changes: 1 addition & 1 deletion event_reporter/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"time"

argocommon "github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/event_reporter/codefresh"
"github.com/argoproj/argo-cd/v2/event_reporter/metrics"
"github.com/argoproj/argo-cd/v2/event_reporter/reporter"
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
applisters "github.com/argoproj/argo-cd/v2/pkg/client/listers/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/pkg/codefresh"
servercache "github.com/argoproj/argo-cd/v2/server/cache"
argoutil "github.com/argoproj/argo-cd/v2/util/argo"
"github.com/argoproj/argo-cd/v2/util/env"
Expand Down
11 changes: 6 additions & 5 deletions event_reporter/reporter/application_event_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"math"
"reflect"
"strings"
"time"

"github.com/argoproj/argo-cd/v2/reposerver/apiclient"

argocommon "github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/event_reporter/codefresh"
"github.com/argoproj/argo-cd/v2/event_reporter/metrics"
applisters "github.com/argoproj/argo-cd/v2/pkg/client/listers/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/pkg/codefresh"
servercache "github.com/argoproj/argo-cd/v2/server/cache"
"github.com/argoproj/argo-cd/v2/util/env"

Expand Down Expand Up @@ -46,7 +47,7 @@ type AppIdentity struct {

type applicationEventReporter struct {
cache *servercache.Cache
codefreshClient codefresh.CodefreshClient
codefreshClient codefresh.CodefreshClientInterface
appLister applisters.ApplicationLister
applicationServiceClient appclient.ApplicationClient
metricsServer *metrics.MetricsServer
Expand Down Expand Up @@ -258,7 +259,7 @@ func (s *applicationEventReporter) StreamApplicationEvents(
}

logWithAppStatus(a, logCtx, ts).Info("sending root application event")
if err := s.codefreshClient.Send(ctx, a.Name, appEvent); err != nil {
if err := s.codefreshClient.SendEvent(ctx, a.Name, appEvent); err != nil {
s.metricsServer.IncErroredEventsCounter(metrics.MetricParentAppEventType, metrics.MetricEventDeliveryErrorType, a.Name)
return fmt.Errorf("failed to send event for root application %s/%s: %w", a.Namespace, a.Name, err)
}
Expand Down Expand Up @@ -407,7 +408,7 @@ func (s *applicationEventReporter) processResource(
appName = rs.Name
}

if err := s.codefreshClient.Send(ctx, appName, ev); err != nil {
if err := s.codefreshClient.SendEvent(ctx, appName, ev); err != nil {
if strings.Contains(err.Error(), "context deadline exceeded") {
return fmt.Errorf("failed to send resource event: %w", err)
}
Expand Down
14 changes: 10 additions & 4 deletions event_reporter/reporter/application_event_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package reporter
import (
"context"
"encoding/json"
"github.com/argoproj/argo-cd/v2/event_reporter/metrics"
"github.com/argoproj/argo-cd/v2/util/io"
"github.com/argoproj/gitops-engine/pkg/health"
"net/http"
"testing"
"time"

"github.com/argoproj/argo-cd/v2/event_reporter/metrics"
"github.com/argoproj/argo-cd/v2/util/io"
"github.com/argoproj/gitops-engine/pkg/health"

"github.com/ghodss/yaml"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

Expand All @@ -33,6 +34,7 @@ import (
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"github.com/argoproj/argo-cd/v2/pkg/apiclient/events"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v2/pkg/codefresh"
repoApiclient "github.com/argoproj/argo-cd/v2/reposerver/apiclient"
"github.com/argoproj/argo-cd/v2/util/argo"
)
Expand Down Expand Up @@ -229,10 +231,14 @@ type MockCodefreshClient struct {
httpClient *http.Client
}

func (cc *MockCodefreshClient) Send(ctx context.Context, appName string, event *events.Event) error {
func (cc *MockCodefreshClient) SendEvent(ctx context.Context, appName string, event *events.Event) error {
return nil
}

func (cc *MockCodefreshClient) SendGraphQL(query codefresh.GraphQLQuery) (*json.RawMessage, error) {
return nil, nil
}

func fakeReporter() *applicationEventReporter {
guestbookApp := &appsv1.Application{
TypeMeta: metav1.TypeMeta{
Expand Down
2 changes: 1 addition & 1 deletion event_reporter/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"time"

"github.com/argoproj/argo-cd/v2/common"
codefresh "github.com/argoproj/argo-cd/v2/event_reporter/codefresh"
event_reporter "github.com/argoproj/argo-cd/v2/event_reporter/controller"
"github.com/argoproj/argo-cd/v2/event_reporter/handlers"
"github.com/argoproj/argo-cd/v2/event_reporter/metrics"
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"
codefresh "github.com/argoproj/argo-cd/v2/pkg/codefresh"
repoapiclient "github.com/argoproj/argo-cd/v2/reposerver/apiclient"
servercache "github.com/argoproj/argo-cd/v2/server/cache"
"github.com/argoproj/argo-cd/v2/server/rbacpolicy"
Expand Down
2 changes: 1 addition & 1 deletion manifests/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Kustomization
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.8.1-cap-CR-rollout-skip-step-fix
newTag: latest
resources:
- ./application-controller
- ./dex
Expand Down
6 changes: 3 additions & 3 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21451,7 +21451,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-rollout-skip-step-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -21503,7 +21503,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-rollout-skip-step-fix
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -21721,7 +21721,7 @@ spec:
key: controller.kubectl.parallelism.limit
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-rollout-skip-step-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
2 changes: 1 addition & 1 deletion manifests/core-install/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ resources:
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.8.1-cap-CR-rollout-skip-step-fix
newTag: latest
2 changes: 1 addition & 1 deletion manifests/ha/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ patches:
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.8.1-cap-CR-rollout-skip-step-fix
newTag: latest
resources:
- ../../base/application-controller
- ../../base/applicationset-controller
Expand Down
Loading

0 comments on commit 0f82ce2

Please sign in to comment.