Skip to content

Commit 5dcdd7c

Browse files
Kumm-Kaidergeberl
andauthored
Add SKE login command (#157)
* Add SKE login command Co-authored-by: Maximilian Geberl <[email protected]> * Different improvement from code review * remove unused function * rearrange functions and improve error messages * Add tests for cache pkg * Extend kubeconfig create command with flag to retrieve login kubeconfig * small extension to the kubeconfig login description * improve descriptions and examples * fix yaml output * codereview: use os.UserCacheDir instead of external lib * codereview: drop parseInput and use parseClusterConfig directly; move cacheKey into clusterConfig * codereview: add one nil check * codereview: print user facing error that explains that the login command should not be used directly * fixup! codereview: use os.UserCacheDir instead of external lib * codereview: first try at improving the description * generate-docs * Add tests for login (buildRequest & parseKubeConfigToExecCredential * cache: call Init func directly and return err * use p.Outputf instead of cmd.Print --------- Co-authored-by: Maximilian Geberl <[email protected]>
1 parent c6caa8e commit 5dcdd7c

File tree

13 files changed

+946
-34
lines changed

13 files changed

+946
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dist/
44

55
# IDE
66
.vscode
7+
.idea
78

89
# OS generated files
910
.DS_Store

docs/stackit_ske_kubeconfig.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ stackit ske kubeconfig [flags]
3030

3131
* [stackit ske](./stackit_ske.md) - Provides functionality for SKE
3232
* [stackit ske kubeconfig create](./stackit_ske_kubeconfig_create.md) - Creates a kubeconfig for an SKE cluster
33+
* [stackit ske kubeconfig login](./stackit_ske_kubeconfig_login.md) - Login plugin for kubernetes clients
3334

docs/stackit_ske_kubeconfig_create.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ stackit ske kubeconfig create CLUSTER_NAME [flags]
2121
Create a kubeconfig for the SKE cluster with name "my-cluster"
2222
$ stackit ske kubeconfig create my-cluster
2323
24+
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.
25+
$ stackit ske kubeconfig create my-cluster --login
26+
2427
Create a kubeconfig for the SKE cluster with name "my-cluster" and set the expiration time to 30 days
2528
$ stackit ske kubeconfig create my-cluster --expiration 30d
2629
@@ -37,6 +40,7 @@ stackit ske kubeconfig create CLUSTER_NAME [flags]
3740
-e, --expiration string 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
3841
--filepath string Path to create the kubeconfig file. By default, the kubeconfig is created as 'config' in the .kube folder, in the user's home directory.
3942
-h, --help Help for "stackit ske kubeconfig create"
43+
-l, --login Create a login kubeconfig that obtains valid credentials via the STACKIT CLI. This flag is mutually exclusive with the expiration flag.
4044
```
4145

4246
### Options inherited from parent commands

docs/stackit_ske_kubeconfig_login.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## stackit ske kubeconfig login
2+
3+
Login plugin for kubernetes clients
4+
5+
### Synopsis
6+
7+
Login plugin for kubernetes clients, that creates short-lived credentials to authenticate against a STACKIT Kubernetes Engine (SKE) cluster.
8+
First you need to obtain a kubeconfig for use with the login command (first example).
9+
Secondly you use the kubeconfig with your chosen Kubernetes client (second example), the client will automatically retrieve the credentials via the STACKIT CLI.
10+
11+
```
12+
stackit ske kubeconfig login [flags]
13+
```
14+
15+
### Examples
16+
17+
```
18+
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.
19+
$ stackit ske kubeconfig create my-cluster --login
20+
21+
Use the previously saved kubeconfig to authenticate to the SKE cluster, in this case with kubectl.
22+
$ kubectl cluster-info
23+
$ kubectl get pods
24+
```
25+
26+
### Options
27+
28+
```
29+
-h, --help Help for "stackit ske kubeconfig login"
30+
```
31+
32+
### Options inherited from parent commands
33+
34+
```
35+
-y, --assume-yes If set, skips all confirmation prompts
36+
--async If set, runs the command asynchronously
37+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
38+
-p, --project-id string Project ID
39+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
40+
```
41+
42+
### SEE ALSO
43+
44+
* [stackit ske kubeconfig](./stackit_ske_kubeconfig.md) - Provides functionality for SKE kubeconfig
45+

go.mod

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ require (
2929
golang.org/x/oauth2 v0.20.0
3030
golang.org/x/term v0.20.0
3131
golang.org/x/text v0.15.0
32+
k8s.io/apimachinery v0.29.2
33+
k8s.io/client-go v0.29.2
34+
)
35+
36+
require (
37+
golang.org/x/net v0.20.0 // indirect
38+
golang.org/x/time v0.5.0 // indirect
39+
gopkg.in/inf.v0 v0.9.1 // indirect
3240
)
3341

3442
require (
@@ -41,17 +49,23 @@ require (
4149
github.com/alessio/shellescape v1.4.2 // indirect
4250
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
4351
github.com/danieljoos/wincred v1.2.1 // indirect
52+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4453
github.com/fsnotify/fsnotify v1.7.0 // indirect
54+
github.com/go-logr/logr v1.3.0 // indirect
4555
github.com/godbus/dbus/v5 v5.1.0 // indirect
56+
github.com/gogo/protobuf v1.3.2 // indirect
57+
github.com/google/gofuzz v1.2.0 // indirect
4658
github.com/hashicorp/hcl v1.0.0 // indirect
59+
github.com/imdario/mergo v0.3.6 // indirect
4760
github.com/inconshreveable/mousetrap v1.1.0 // indirect
61+
github.com/json-iterator/go v1.1.12 // indirect
4862
github.com/magiconair/properties v1.8.7 // indirect
4963
github.com/mattn/go-runewidth v0.0.15 // indirect
5064
github.com/mitchellh/mapstructure v1.5.0 // indirect
51-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
65+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
66+
github.com/modern-go/reflect2 v1.0.2 // indirect
5267
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
5368
github.com/rivo/uniseg v0.4.4 // indirect
54-
github.com/rogpeppe/go-internal v1.10.0 // indirect
5569
github.com/russross/blackfriday/v2 v2.1.0 // indirect
5670
github.com/sagikazarmark/locafero v0.4.0 // indirect
5771
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
@@ -69,7 +83,13 @@ require (
6983
go.uber.org/multierr v1.11.0 // indirect
7084
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
7185
golang.org/x/sys v0.20.0 // indirect
72-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
7386
gopkg.in/ini.v1 v1.67.0 // indirect
87+
gopkg.in/yaml.v2 v2.4.0 // indirect
7488
gopkg.in/yaml.v3 v3.0.1 // indirect
89+
k8s.io/api v0.29.2 // indirect
90+
k8s.io/klog/v2 v2.110.1 // indirect
91+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
92+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
93+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
94+
sigs.k8s.io/yaml v1.3.0 // indirect
7595
)

0 commit comments

Comments
 (0)