Skip to content

Conversation

@dergeberl
Copy link
Member

Description

This PR adds --ignore-existing as a flag for stackit config profile create in order to call the create idempotent and don not get a error in case the profile already exists. That make it possible to use profiles in automation/tool.

Example: I am currently integrating stackit(-cli) into the gardenctl (gardener/gardenctl-v2#669).

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@github-actions
Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale label Nov 27, 2025
@dergeberl
Copy link
Member Author

cc @rubenhoenle

@github-actions github-actions bot removed the Stale label Dec 2, 2025
@github-actions
Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.


func configureFlags(cmd *cobra.Command) {
cmd.Flags().Bool(noSetFlag, false, "Do not set the profile as the active profile")
cmd.Flags().Bool(ignoreExistingFlag, false, "Suppress the error it the profile exists already")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Suggested change
cmd.Flags().Bool(ignoreExistingFlag, false, "Suppress the error it the profile exists already")
cmd.Flags().Bool(ignoreExistingFlag, false, "Suppress the error if the profile exists already")

// CreateProfile creates a new profile.
// If emptyProfile is true, it creates an empty profile. Otherwise, copies the config from the current profile to the new profile.
// If setProfile is true, it sets the new profile as the active profile.
// If the profile already exists, it returns an error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If the profile already exists, it returns an error.
// If the profile already exists and ignoreExisting is false, it returns an error.

_, err = os.Stat(configFolderPath)
if err == nil {
if ignoreExising {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil
if setProfile {
err = SetProfile(p, profile)
if err != nil {
return fmt.Errorf("set profile: %w", err)
}
}
return nil

Currently the value of setProfile is ignored, when this branch is taken.

When creating a profile with --ignore-existing, that already exists but isn't active at the moment, the CLI reports:

Successfully created and set active profile to "qa"
'qa' isn't activated in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants