diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 6094f8f906..45901b8877 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -4003,13 +4003,13 @@ jobs: validate_configmap "password" "" validate_configmap "sequence" "0" - ./bin/kots set config "$APP_SLUG" --key=password --value=example-password --namespace "$APP_SLUG" --deploy + ./bin/kots set config "$APP_SLUG" --key=password --value=example-password --namespace "$APP_SLUG" # don't deploy sleep 5 validate_configmap "username" "" - validate_configmap "password" "example-password" + validate_configmap "password" "" validate_configmap "email" "" - validate_configmap "sequence" "1" + validate_configmap "sequence" "0" ./bin/kots set config "$APP_SLUG" --key=username --value=example-username --namespace "$APP_SLUG" --deploy sleep 5 @@ -4091,6 +4091,18 @@ jobs: validate_configmap "email" "" validate_configmap "sequence" "5" + # should not be able to use --current and --sequence together + + if ./bin/kots get config "$APP_SLUG" --namespace "$APP_SLUG" --decrypt --sequence=0 --current; then + echo "expected error when using --current and --sequence together in get config" + exit 1 + fi + + if ./bin/kots set config "$APP_SLUG" --key=username --value=updated-username --namespace "$APP_SLUG" --sequence=0 --current --deploy; then + echo "expected error when using --current and --sequence together in set config" + exit 1 + fi + - name: Generate support bundle on failure if: failure() uses: ./.github/actions/generate-support-bundle diff --git a/cmd/kots/cli/get-config.go b/cmd/kots/cli/get-config.go index 909a898827..72bc5f9334 100644 --- a/cmd/kots/cli/get-config.go +++ b/cmd/kots/cli/get-config.go @@ -72,6 +72,10 @@ func getConfigCmd(cmd *cobra.Command, args []string) error { decrypt := v.GetBool("decrypt") current := v.GetBool("current") + if current && appSequence != -1 { + return errors.New("cannot use --current and --sequence together") + } + localPort, errChan, err := k8sutil.PortForward(0, 3000, namespace, getPodName, false, stopCh, log) if err != nil { log.FinishSpinnerWithError() @@ -122,12 +126,15 @@ func getConfigCmd(cmd *cobra.Command, args []string) error { return errors.Errorf("app %s not found", appSlug) } - if appSequence == -1 { - if current && foundApp.Downstream.CurrentVersion != nil { - appSequence = foundApp.Downstream.CurrentVersion.ParentSequence // this is the sequence of the currently deployed version - } else { - appSequence = foundApp.CurrentSequence // this is the sequence of the latest available version + if current { + if foundApp.Downstream.CurrentVersion == nil { + return errors.Errorf("no deployed version found for app %s", appSlug) } + appSequence = foundApp.Downstream.CurrentVersion.ParentSequence // this is the sequence of the currently deployed version + } + + if appSequence == -1 { + appSequence = foundApp.CurrentSequence // this is the sequence of the latest available version } getConfigURL := fmt.Sprintf("http://localhost:%d/api/v1/app/%s/config/%d", localPort, appSlug, appSequence) diff --git a/cmd/kots/cli/set-config.go b/cmd/kots/cli/set-config.go index 48d7c90624..d555ad48c0 100644 --- a/cmd/kots/cli/set-config.go +++ b/cmd/kots/cli/set-config.go @@ -57,6 +57,10 @@ func SetConfigCmd() *cobra.Command { log.Info("--skip-preflights will be ignored because --deploy is not set") } + if v.GetBool("current") && v.GetInt64("sequence") != -1 { + return errors.New("cannot use --current and --sequence together") + } + configValues, err := getConfigValuesFromArgs(v, args) if err != nil { return errors.Wrap(err, "failed to create config values from arguments") diff --git a/pkg/handlers/config.go b/pkg/handlers/config.go index 13327e6eeb..deb429784a 100644 --- a/pkg/handlers/config.go +++ b/pkg/handlers/config.go @@ -1039,7 +1039,7 @@ func (h *Handler) SetAppConfigValues(w http.ResponseWriter, r *http.Request) { baseSequence := setAppConfigValuesRequest.Sequence - if baseSequence == -1 && setAppConfigValuesRequest.Current { + if setAppConfigValuesRequest.Current { // use the currently deployed version as the base downstreams, err := store.GetStore().ListDownstreamsForApp(foundApp.ID) if err != nil { @@ -1064,11 +1064,14 @@ func (h *Handler) SetAppConfigValues(w http.ResponseWriter, r *http.Request) { return } - if versions.CurrentVersion != nil { - baseSequence = versions.CurrentVersion.Sequence - } else { - logger.Warnf("no deployed version found for app %s", foundApp.Slug) + if versions.CurrentVersion == nil { + setAppConfigValuesResponse.Error = fmt.Sprintf("no deployed version found for app %s", foundApp.Slug) + logger.Error(errors.New(setAppConfigValuesResponse.Error)) + JSON(w, http.StatusBadRequest, setAppConfigValuesResponse) + return } + + baseSequence = versions.CurrentVersion.Sequence } if baseSequence == -1 {