Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/argocd-repo-server/commands/argocd_repo_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewCommand() *cobra.Command {
cmpUseManifestGeneratePaths bool
ociMediaTypes []string
enableBuiltinGitConfig bool
enableTrackingLabelOnCRDs bool
)
command := cobra.Command{
Use: common.CommandRepoServer,
Expand Down Expand Up @@ -155,6 +156,7 @@ func NewCommand() *cobra.Command {
OCIMediaTypes: ociMediaTypes,
EnableBuiltinGitConfig: enableBuiltinGitConfig,
HelmUserAgent: helmUserAgent,
EnableTrackingLabelOnCRDs: enableTrackingLabelOnCRDs,
}, askPassServer)
errors.CheckError(err)

Expand Down Expand Up @@ -266,6 +268,7 @@ func NewCommand() *cobra.Command {
command.Flags().BoolVar(&cmpUseManifestGeneratePaths, "plugin-use-manifest-generate-paths", env.ParseBoolFromEnv("ARGOCD_REPO_SERVER_PLUGIN_USE_MANIFEST_GENERATE_PATHS", false), "Pass the resources described in argocd.argoproj.io/manifest-generate-paths value to the cmpserver to generate the application manifests.")
command.Flags().StringSliceVar(&ociMediaTypes, "oci-layer-media-types", env.StringsFromEnv("ARGOCD_REPO_SERVER_OCI_LAYER_MEDIA_TYPES", []string{"application/vnd.oci.image.layer.v1.tar", "application/vnd.oci.image.layer.v1.tar+gzip", "application/vnd.cncf.helm.chart.content.v1.tar+gzip"}, ","), "Comma separated list of allowed media types for OCI media types. This only accounts for media types within layers.")
command.Flags().BoolVar(&enableBuiltinGitConfig, "enable-builtin-git-config", env.ParseBoolFromEnv("ARGOCD_REPO_SERVER_ENABLE_BUILTIN_GIT_CONFIG", true), "Enable builtin git configuration options that are required for correct argocd-repo-server operation.")
command.Flags().BoolVar(&enableTrackingLabelOnCRDs, "enable-tracking-label-on-crds", env.ParseBoolFromEnv("ARGOCD_REPO_SERVER_ENABLE_TRACKING_LABEL_ON_CRDS", false), "Enable tracking labels to be inserted into Custom Resource Definition resources")
tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(&command)
cacheSrc = reposervercache.AddCacheFlagsToCmd(&command, cacheutil.Options{
OnClientCreated: func(client *redis.Client) {
Expand Down
2 changes: 2 additions & 0 deletions docs/operator-manual/argocd-cmd-params-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ data:
reposerver.grpc.enable.txt.service.config: "false"
# Enables profile endpoint on the internal metrics port
reposerver.profile.enabled: "false"
# Enable the Argo CD tracking label/annotation to be applied to Custom Resource Definitions
reposerver.enable.tracking.label.on.crds: "false"

## Commit-server properties
# Listen on given address for incoming connections (default "0.0.0.0")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ spec:
key: reposerver.helm.user.agent
name: argocd-cmd-params-cm
optional: true
- name: ARGOCD_REPO_SERVER_ENABLE_TRACKING_LABEL_ON_CRDS
valueFrom:
configMapKeyRef:
key: reposerver.enable.tracking.label.on.crds
name: argocd-cmd-params-cm
optional: true
- name: HELM_CACHE_HOME
value: /helm-working-dir
- name: HELM_CONFIG_HOME
Expand Down
6 changes: 6 additions & 0 deletions manifests/core-install-with-hydrator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/core-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/ha/install-with-hydrator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/ha/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/ha/namespace-install-with-hydrator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/ha/namespace-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/install-with-hydrator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/namespace-install-with-hydrator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/namespace-install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type RepoServerInitConstants struct {
CMPUseManifestGeneratePaths bool
EnableBuiltinGitConfig bool
HelmUserAgent string
EnableTrackingLabelOnCRDs bool
}

var manifestGenerateLock = sync.NewKeyLock()
Expand Down Expand Up @@ -925,7 +926,7 @@ func (s *Service) runManifestGenAsync(ctx context.Context, repoRoot, commitSHA,
}
}

manifestGenResult, err = GenerateManifests(ctx, opContext.appPath, repoRoot, commitSHA, q, false, s.gitCredsStore, s.initConstants.MaxCombinedDirectoryManifestsSize, s.gitRepoPaths, WithCMPTarDoneChannel(ch.tarDoneCh), WithCMPTarExcludedGlobs(s.initConstants.CMPTarExcludedGlobs), WithCMPUseManifestGeneratePaths(s.initConstants.CMPUseManifestGeneratePaths))
manifestGenResult, err = GenerateManifests(ctx, opContext.appPath, repoRoot, commitSHA, q, false, s.gitCredsStore, s.initConstants.MaxCombinedDirectoryManifestsSize, s.gitRepoPaths, WithCMPTarDoneChannel(ch.tarDoneCh), WithCMPTarExcludedGlobs(s.initConstants.CMPTarExcludedGlobs), WithCMPUseManifestGeneratePaths(s.initConstants.CMPUseManifestGeneratePaths), WithTrackingLabelOnCRDs(s.initConstants.EnableTrackingLabelOnCRDs))
}
refSourceCommitSHAs := make(map[string]string)
if len(repoRefs) > 0 {
Expand Down Expand Up @@ -1654,6 +1655,7 @@ type (
cmpTarDoneCh chan<- bool
cmpTarExcludedGlobs []string
cmpUseManifestGeneratePaths bool
trackingLabelsOnCRDs bool
Comment thread
cjcocokrisp marked this conversation as resolved.
Outdated
}
)

Expand Down Expand Up @@ -1690,6 +1692,12 @@ func WithCMPUseManifestGeneratePaths(enabled bool) GenerateManifestOpt {
}
}

func WithTrackingLabelOnCRDs(enabled bool) GenerateManifestOpt {
return func(o *generateManifestOpt) {
o.trackingLabelsOnCRDs = enabled
}
}

// GenerateManifests generates manifests from a path. Overrides are applied as a side effect on the given ApplicationSource.
func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string, q *apiclient.ManifestRequest, isLocal bool, gitCredsStore git.CredsStore, maxCombinedManifestQuantity resource.Quantity, gitRepoPaths utilio.TempPaths, opts ...GenerateManifestOpt) (*apiclient.ManifestResponse, error) {
opt := newGenerateManifestOpt(opts...)
Expand Down Expand Up @@ -1783,7 +1791,7 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
}

for _, target := range targets {
if q.AppLabelKey != "" && q.AppName != "" && !kube.IsCRD(target) {
if q.AppLabelKey != "" && q.AppName != "" && (opt.trackingLabelsOnCRDs || !kube.IsCRD(target)) {
err = resourceTracking.SetAppInstance(target, q.AppLabelKey, q.AppName, q.Namespace, v1alpha1.TrackingMethod(q.TrackingMethod), q.InstallationID)
if err != nil {
return nil, fmt.Errorf("failed to set app instance tracking info on manifest: %w", err)
Expand Down
44 changes: 44 additions & 0 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5850,3 +5850,47 @@ func TestGenerateManifest_OCISourceSkipsGitClient(t *testing.T) {
// verify that newGitClient was never invoked
assert.False(t, gitCalled, "GenerateManifest should not invoke Git for OCI sources")
}

func TestGenerateManifests_TrackingLabelOnCRDs(t *testing.T) {
tests := []struct {
name string
enableTrackingLabelOnCRDs bool
shouldHaveLabel bool
}{
{
name: "enable tracking label on CRDs",
enableTrackingLabelOnCRDs: true,
shouldHaveLabel: true,
},
{
name: "label should not be on CRDs when disabled",
enableTrackingLabelOnCRDs: false,
shouldHaveLabel: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
src := v1alpha1.ApplicationSource{Path: "."}
q := apiclient.ManifestRequest{
Repo: &v1alpha1.Repository{},
ApplicationSource: &src,
AppLabelKey: "test",
AppName: "crd-tracking",
ProjectName: "something",
ProjectSourceRepos: []string{"*"},
}

res, err := GenerateManifests(t.Context(), "./testdata/crd-tracking", "/", "", &q, false, &git.NoopCredsStore{}, resource.MustParse("0"), nil, WithTrackingLabelOnCRDs(tt.enableTrackingLabelOnCRDs))
require.NoError(t, err)

obj := unstructured.Unstructured{}
err = json.Unmarshal([]byte(res.Manifests[0]), &obj)
require.NoError(t, err)

annotations := obj.GetAnnotations()
_, exists := annotations[common.AnnotationKeyAppInstance]
require.Equal(t, tt.shouldHaveLabel, exists, "AnnotationKeyAppInstance must exist in the returned manifest")
Comment thread
cjcocokrisp marked this conversation as resolved.
Outdated
})
}
}
24 changes: 24 additions & 0 deletions reposerver/repository/testdata/crd-tracking/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: useful.argocd.argoproj.io
spec:
group: argocd.argoproj.io
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
usefulField:
type: string
scope: Namespaced
names:
plural: usefuls
singular: useful
kind: Useful
shortNames:
- ufl
Loading