-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): add support for multiple sources to sync command #18016
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -880,7 +880,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C | |
} | ||
} | ||
|
||
source := app.Spec.GetSourcePtr(sourcePosition) | ||
source := app.Spec.GetSourcePtrByPosition(sourcePosition) | ||
|
||
updated, nothingToUnset := unset(source, opts) | ||
if nothingToUnset { | ||
|
@@ -1807,6 +1807,8 @@ func printTreeViewDetailed(nodeMapping map[string]argoappv1.ResourceNode, parent | |
func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command { | ||
var ( | ||
revision string | ||
revisions []string | ||
sourcePositions []int64 | ||
resources []string | ||
labels []string | ||
selector string | ||
|
@@ -1849,6 +1851,9 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co | |
argocd app sync -l '!app.kubernetes.io/instance' | ||
argocd app sync -l 'app.kubernetes.io/instance notin (my-app,other-app)' | ||
|
||
# Sync a multi-source application for specific revision of specific sources | ||
argocd app manifests my-app --revisions 0.0.1 --source-positions 1 --revisions 0.0.2 --source-positions 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I wonder if we should have named sources too. Maybe a followup PR, not worth stalling this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is an open issue opened for the same as a future enhancement. #17731 |
||
|
||
# Sync a specific resource | ||
# Resource should be formatted as GROUP:KIND:NAME. If no GROUP is specified then :KIND:NAME | ||
argocd app sync my-app --resource :Service:my-service | ||
|
@@ -1867,6 +1872,21 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co | |
if len(args) > 1 && selector != "" { | ||
log.Fatal("Cannot use selector option when application name(s) passed as argument(s)") | ||
} | ||
|
||
if len(args) != 1 && (len(revisions) > 0 || len(sourcePositions) > 0) { | ||
log.Fatal("Cannot use --revisions and --source-positions options when 0 or more than 1 application names are passed as argument(s)") | ||
} | ||
|
||
if len(revisions) != len(sourcePositions) { | ||
log.Fatal("While using --revisions and --source-positions, length of values for both flags should be same.") | ||
} | ||
|
||
for _, pos := range sourcePositions { | ||
if pos <= 0 { | ||
log.Fatal("source-position cannot be less than or equal to 0, Counting starts at 1") | ||
} | ||
} | ||
|
||
acdClient := headless.NewClientOrDie(clientOpts, c) | ||
conn, appIf := acdClient.NewApplicationClientOrDie() | ||
defer argoio.Close(conn) | ||
|
@@ -1908,9 +1928,11 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co | |
|
||
if len(selectedLabels) > 0 { | ||
q := application.ApplicationManifestQuery{ | ||
Name: &appName, | ||
AppNamespace: &appNs, | ||
Revision: &revision, | ||
Name: &appName, | ||
AppNamespace: &appNs, | ||
Revision: &revision, | ||
Revisions: revisions, | ||
SourcePositions: sourcePositions, | ||
} | ||
|
||
res, err := appIf.GetManifests(ctx, &q) | ||
|
@@ -1953,7 +1975,7 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co | |
|
||
if app.Spec.HasMultipleSources() { | ||
if revision != "" { | ||
log.Fatal("argocd cli does not work on multi-source app with --revision flag") | ||
log.Fatal("argocd cli does not work on multi-source app with --revision flag. Use --revisions and --source-position instead.") | ||
return | ||
} | ||
|
||
|
@@ -2018,15 +2040,17 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co | |
} | ||
|
||
syncReq := application.ApplicationSyncRequest{ | ||
Name: &appName, | ||
AppNamespace: &appNs, | ||
DryRun: &dryRun, | ||
Revision: &revision, | ||
Resources: filteredResources, | ||
Prune: &prune, | ||
Manifests: localObjsStrings, | ||
Infos: getInfos(infos), | ||
SyncOptions: syncOptionsFactory(), | ||
Name: &appName, | ||
AppNamespace: &appNs, | ||
DryRun: &dryRun, | ||
Revision: &revision, | ||
Resources: filteredResources, | ||
Prune: &prune, | ||
Manifests: localObjsStrings, | ||
Infos: getInfos(infos), | ||
SyncOptions: syncOptionsFactory(), | ||
Revisions: revisions, | ||
SourcePositions: sourcePositions, | ||
} | ||
|
||
switch strategy { | ||
|
@@ -2123,6 +2147,8 @@ func NewApplicationSyncCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co | |
command.Flags().StringVarP(&output, "output", "o", "wide", "Output format. One of: json|yaml|wide|tree|tree=detailed") | ||
command.Flags().StringVarP(&appNamespace, "app-namespace", "N", "", "Only sync an application in namespace") | ||
command.Flags().DurationVar(&ignoreNormalizerOpts.JQExecutionTimeout, "ignore-normalizer-jq-execution-timeout", normalizers.DefaultJQExecutionTimeout, "Set ignore normalizer JQ execution timeout") | ||
command.Flags().StringArrayVar(&revisions, "revisions", []string{}, "Show manifests at specific revisions for source position in source-positions") | ||
command.Flags().Int64SliceVar(&sourcePositions, "source-positions", []int64{}, "List of source positions. Default is empty array. Counting start at 1.") | ||
return command | ||
} | ||
|
||
|
@@ -2505,7 +2531,7 @@ func setParameterOverrides(app *argoappv1.Application, parameters []string, sour | |
if len(parameters) == 0 { | ||
return | ||
} | ||
source := app.Spec.GetSourcePtr(sourcePosition) | ||
source := app.Spec.GetSourcePtrByPosition(sourcePosition) | ||
var sourceType argoappv1.ApplicationSourceType | ||
if st, _ := source.ExplicitType(); st != nil { | ||
sourceType = *st | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably use int8, I doubt we'll ever have more than 127 source positions to worry about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the command flagset does not support
int8
. Kept itint64
to avoid unwanted typecasting between command and api server.