Skip to content

Commit

Permalink
fail if --current but no version is deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Mar 4, 2024
1 parent 5c112b2 commit b9032ec
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions cmd/kots/cli/get-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmd/kots/cli/set-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 8 additions & 5 deletions pkg/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit b9032ec

Please sign in to comment.