Skip to content

Commit c64874e

Browse files
committed
feat: ske kubeconfig merge. fix comments pr
Signed-off-by: Javier Vela <fjvela@gmail.com>
1 parent 198b3ed commit c64874e

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

docs/stackit_ske_kubeconfig_create.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ stackit ske kubeconfig create CLUSTER_NAME [flags]
2626
Get a login kubeconfig for the SKE cluster with name "my-cluster". This kubeconfig does not contain any credentials and instead obtains valid credentials via the `stackit ske kubeconfig login` command.
2727
$ stackit ske kubeconfig create my-cluster --login
2828
29-
Create o kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated.
29+
Create a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated.
3030
$ stackit ske kubeconfig create my-cluster --expiration 30d
3131
3232
Create or update a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 2 months. If the config exits in the kubeconfig file the information will be updated.

internal/cmd/ske/kubeconfig/create/create.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
expirationFlag = "expiration"
2727
filepathFlag = "filepath"
2828
loginFlag = "login"
29-
overwrite = "overwrite"
29+
overwriteFlag = "overwrite"
3030
)
3131

3232
type inputModel struct {
@@ -59,7 +59,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
5959
"This kubeconfig does not contain any credentials and instead obtains valid credentials via the `stackit ske kubeconfig login` command.",
6060
"$ stackit ske kubeconfig create my-cluster --login"),
6161
examples.NewExample(
62-
`Create o kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated.`,
62+
`Create a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days. If the config exits in the kubeconfig file the information will be updated.`,
6363
"$ stackit ske kubeconfig create my-cluster --expiration 30d"),
6464
examples.NewExample(
6565
`Create or update a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 2 months. If the config exits in the kubeconfig file the information will be updated.`,
@@ -92,7 +92,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
9292
if model.Overwrite {
9393
prompt = fmt.Sprintf("Are you sure you want to create a kubeconfig for SKE cluster %q? This will OVERWRITE your current kubeconfig file, if it exists.", model.ClusterName)
9494
} else {
95-
prompt = fmt.Sprintf("Are you sure you want to update your kubeconfig for SKE cluster %q? This will update your kubeconfig file. \n If it the kubeconfig file doesn't exists, it will create a new one.", model.ClusterName)
95+
prompt = fmt.Sprintf("Are you sure you want to update your kubeconfig for SKE cluster %q? This will update your kubeconfig file. \nIf it the kubeconfig file doesn't exists, it will create a new one.", model.ClusterName)
9696
}
9797
err = p.PromptForConfirmation(prompt)
9898
if err != nil {
@@ -170,7 +170,7 @@ func configureFlags(cmd *cobra.Command) {
170170
cmd.Flags().BoolP(loginFlag, "l", false, "Create a login kubeconfig that obtains valid credentials via the STACKIT CLI. This flag is mutually exclusive with the expiration flag.")
171171
cmd.Flags().String(filepathFlag, "", "Path to create the kubeconfig file. By default, the kubeconfig is created as 'config' in the .kube folder, in the user's home directory.")
172172
cmd.Flags().StringP(expirationFlag, "e", "", "Expiration time for the kubeconfig in seconds(s), minutes(m), hours(h), days(d) or months(M). Example: 30d. By default, expiration time is 1h")
173-
cmd.Flags().Bool(overwrite, false, "Overwrite the kubeconfig file.")
173+
cmd.Flags().Bool(overwriteFlag, false, "Overwrite the kubeconfig file.")
174174
cmd.MarkFlagsMutuallyExclusive(loginFlag, expirationFlag)
175175
}
176176

@@ -204,12 +204,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
204204
}
205205

206206
model := inputModel{
207-
GlobalFlagModel: globalFlags,
208207
ClusterName: clusterName,
209-
Filepath: flags.FlagToStringPointer(p, cmd, filepathFlag),
208+
DisableWriting: disableWriting,
210209
ExpirationTime: expTime,
210+
Filepath: flags.FlagToStringPointer(p, cmd, filepathFlag),
211+
GlobalFlagModel: globalFlags,
211212
Login: flags.FlagToBoolValue(p, cmd, loginFlag),
212-
DisableWriting: disableWriting,
213+
Overwrite: flags.FlagToBoolValue(p, cmd, overwriteFlag),
213214
}
214215

215216
if p.IsVerbosityDebug() {

internal/cmd/ske/kubeconfig/create/create_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,28 @@ func TestParseInput(t *testing.T) {
176176
}),
177177
isValid: true,
178178
},
179+
{
180+
description: "enable overwrite",
181+
argValues: fixtureArgValues(),
182+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
183+
flagValues[overwriteFlag] = "true"
184+
}),
185+
expectedModel: fixtureInputModel(func(model *inputModel) {
186+
model.Overwrite = true
187+
}),
188+
isValid: true,
189+
},
190+
{
191+
description: "disable overwrite",
192+
argValues: fixtureArgValues(),
193+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
194+
flagValues[overwriteFlag] = "false"
195+
}),
196+
expectedModel: fixtureInputModel(func(model *inputModel) {
197+
model.Overwrite = false
198+
}),
199+
isValid: true,
200+
},
179201
}
180202

181203
for _, tt := range tests {

0 commit comments

Comments
 (0)