Skip to content

Commit

Permalink
Add test and update docs
Browse files Browse the repository at this point in the history
Signed-off-by: ishitasequeira <ishiseq29@gmail.com>
  • Loading branch information
ishitasequeira committed Mar 15, 2024
1 parent 2981def commit 3520132
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
12 changes: 6 additions & 6 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
# Set and override application parameters with a parameter file
argocd app set my-app --parameter-file path/to/parameter-file.yaml
# Set and override application parameters for a source at index 1 under spec.sources of app my-app
# Set and override application parameters for a source at index 1 under spec.sources of app my-app. source-index starts at 1.
argocd app set my-app --source-index 1 --repo https://github.com/argoproj/argocd-example-apps.git
# Set application parameters and specify the namespace
Expand Down Expand Up @@ -799,7 +799,7 @@ func NewApplicationSetCommand(clientOpts *argocdclient.ClientOptions) *cobra.Com
errors.CheckError(err)
},
}
command.Flags().IntVar(&sourceIndex, "source-index", -1, "Index of the source from the list of sources of the app. Default index is -1.")
command.Flags().IntVar(&sourceIndex, "source-index", -1, "Index of the source from the list of sources of the app. Index starts at 1.")
cmdutil.AddAppFlags(command, &appOpts)
command.Flags().StringVarP(&appNamespace, "app-namespace", "N", "", "Set application parameters in namespace")
return command
Expand Down Expand Up @@ -850,7 +850,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
# Unset kustomize override suffix
argocd app unset my-app --namesuffix
# Unset kustomize override suffix for source at index 1 under spec.sources of app my-app
# Unset kustomize override suffix for source at index 1 under spec.sources of app my-app. source-index starts at 1.
argocd app unset my-app --source-index 1 --namesuffix
# Unset parameter override
Expand Down Expand Up @@ -914,7 +914,7 @@ func NewApplicationUnsetCommand(clientOpts *argocdclient.ClientOptions) *cobra.C
command.Flags().StringArrayVar(&opts.pluginEnvs, "plugin-env", []string{}, "Unset plugin env variables (e.g --plugin-env name)")
command.Flags().BoolVar(&opts.passCredentials, "pass-credentials", false, "Unset passCredentials")
command.Flags().BoolVar(&opts.ref, "ref", false, "Unset ref on the source")
command.Flags().IntVar(&sourceIndex, "source-index", -1, "Index of the source from the list of sources of the app. Default index is -1.")
command.Flags().IntVar(&sourceIndex, "source-index", -1, "Index of the source from the list of sources of the app. Index starts at 1.")
return command
}

Expand Down Expand Up @@ -2957,8 +2957,8 @@ func NewApplicationRemoveSourceCommand(clientOpts *argocdclient.ClientOptions) *
)
command := &cobra.Command{
Use: "remove-source APPNAME",
Short: "Remove a source from multiple sources application. Index starts with 0.",
Example: ` # Remove the source at index 1 from application's sources
Short: "Remove a source from multiple sources application. Index starts with 1. Default value is -1.",
Example: ` # Remove the source at index 1 from application's sources. Index starts at 1.
argocd app remove-source myapplication --source-index 1`,
Run: func(c *cobra.Command, args []string) {
ctx := c.Context()
Expand Down
4 changes: 3 additions & 1 deletion cmd/util/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ func SetAppSpecOptions(flags *pflag.FlagSet, spec *argoappv1.ApplicationSpec, ap
}
source, visited = ConstructSource(source, *appOpts, flags)
if spec.HasMultipleSources() {
if index > 0 {
if index == 0 {
spec.Sources[index] = *source
} else if index > 0 {
spec.Sources[index-1] = *source
} else {
spec.Sources = append(spec.Sources, *source)
Expand Down
6 changes: 6 additions & 0 deletions cmd/util/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func newMultiSourceAppOptionsFixture() *appOptionsFixture {

func Test_setAppSpecOptionsMultiSourceApp(t *testing.T) {
f := newMultiSourceAppOptionsFixture()
index := 0
index1 := 1
index2 := 2
t.Run("SyncPolicy", func(t *testing.T) {
Expand All @@ -261,6 +262,11 @@ func Test_setAppSpecOptionsMultiSourceApp(t *testing.T) {
assert.NoError(t, f.SetFlagWithSourceIndex("sync-policy", "automatic", index1))
assert.NotNil(t, f.spec.SyncPolicy.Automated)
})
t.Run("Helm - Index 0", func(t *testing.T) {
assert.NoError(t, f.SetFlagWithSourceIndex("helm-version", "v2", index))
assert.Equal(t, len(f.spec.GetSources()), 2)
assert.Equal(t, f.spec.GetSources()[index].Helm.Version, "v2")
})
t.Run("Kustomize", func(t *testing.T) {
assert.NoError(t, f.SetFlagWithSourceIndex("kustomize-replica", "my-deployment=2", index1))
assert.Equal(t, f.spec.Sources[index1-1].Kustomize.Replicas, v1alpha1.KustomizeReplicas{{Name: "my-deployment", Count: intstr.FromInt(2)}})
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/commands/argocd_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ argocd app [flags]
* [argocd app manifests](argocd_app_manifests.md) - Print manifests of an application
* [argocd app patch](argocd_app_patch.md) - Patch application
* [argocd app patch-resource](argocd_app_patch-resource.md) - Patch resource in an application
* [argocd app remove-source](argocd_app_remove-source.md) - Remove a source from multiple sources application. Index starts with 0.
* [argocd app remove-source](argocd_app_remove-source.md) - Remove a source from multiple sources application. Index starts with 1. Default value is -1.
* [argocd app resources](argocd_app_resources.md) - List resource of application
* [argocd app rollback](argocd_app_rollback.md) - Rollback application to a previous deployed version by History ID, omitted will Rollback to the previous version
* [argocd app set](argocd_app_set.md) - Set application parameters
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/commands/argocd_app_remove-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## argocd app remove-source

Remove a source from multiple sources application. Index starts with 0.
Remove a source from multiple sources application. Index starts with 1. Default value is -1.

```
argocd app remove-source APPNAME [flags]
Expand All @@ -11,7 +11,7 @@ argocd app remove-source APPNAME [flags]
### Examples

```
# Remove the source at index 1 from application's sources
# Remove the source at index 1 from application's sources. Index starts at 1.
argocd app remove-source myapplication --source-index 1
```

Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/commands/argocd_app_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ argocd app set APPNAME [flags]
# Set and override application parameters with a parameter file
argocd app set my-app --parameter-file path/to/parameter-file.yaml
# Set and override application parameters for a source at index 1 under spec.sources of app my-app
# Set and override application parameters for a source at index 1 under spec.sources of app my-app. source-index starts at 1.
argocd app set my-app --source-index 1 --repo https://github.com/argoproj/argocd-example-apps.git
# Set application parameters and specify the namespace
Expand Down Expand Up @@ -79,7 +79,7 @@ argocd app set APPNAME [flags]
--revision string The tracking source branch, tag, commit or Helm chart version the application will sync to
--revision-history-limit int How many items to keep in revision history (default 10)
--self-heal Set self healing when sync is automated
--source-index int Index of the source from the list of sources of the app. Default index is -1. (default -1)
--source-index int Index of the source from the list of sources of the app. Index starts at 1. (default -1)
--sync-option Prune=false Add or remove a sync option, e.g add Prune=false. Remove using `!` prefix, e.g. `!Prune=false`
--sync-policy string Set the sync policy (one of: manual (aliases of manual: none), automated (aliases of automated: auto, automatic))
--sync-retry-backoff-duration duration Sync retry backoff base duration. Input needs to be a duration (e.g. 2m, 1h) (default 5s)
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/commands/argocd_app_unset.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ argocd app unset APPNAME parameters [flags]
# Unset kustomize override suffix
argocd app unset my-app --namesuffix
# Unset kustomize override suffix for source at index 1 under spec.sources of app my-app
# Unset kustomize override suffix for source at index 1 under spec.sources of app my-app. source-index starts at 1.
argocd app unset my-app --source-index 1 --namesuffix
# Unset parameter override
Expand All @@ -40,7 +40,7 @@ argocd app unset APPNAME parameters [flags]
--pass-credentials Unset passCredentials
--plugin-env stringArray Unset plugin env variables (e.g --plugin-env name)
--ref Unset ref on the source
--source-index int Index of the source from the list of sources of the app. Default index is -1. (default -1)
--source-index int Index of the source from the list of sources of the app. Index starts at 1. (default -1)
--values stringArray Unset one or more Helm values files
--values-literal Unset literal Helm values block
```
Expand Down

0 comments on commit 3520132

Please sign in to comment.