Skip to content

Commit 198631e

Browse files
committed
cmd/eks-utils: initial commit
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
1 parent 4017edc commit 198631e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+12543
-386
lines changed

CHANGELOG-1.0.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.0.1...v1.0.2
2222

2323
- Rename [`eksconfig.Parameters.ControlPlaneSecurityGroupID` to `eksconfig.Status.ClusterControlPlaneSecurityGroupID`](https://github.com/aws/aws-k8s-tester/commit/14565868ed452f6d9ffa8335935192bcb0d42e86).
2424
- Does not break anything, since `ControlPlaneSecurityGroupID` was a read-only field.
25-
- Add [`eksconfig.Status.(k8s.io/apimachinery/pkg/version).Info`](https://github.com/aws/aws-k8s-tester/commit/ba7231019be4637e0bbbd91220b260e903ecb5b6).
25+
- Add [`eksconfig.Status.(k8s.io/apimachinery/pkg/version).Info` as `Status.ServerVersionInfo`](https://github.com/aws/aws-k8s-tester/commit/ba7231019be4637e0bbbd91220b260e903ecb5b6).
26+
- Include [`float64` version value in `ServerVersionInfo`](https://github.com/aws/aws-k8s-tester/commit/).
2627

2728
### `eks`
2829

@@ -42,7 +43,8 @@ See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.0.1...v1.0.2
4243

4344
- Add [`k8sclient.NewEKS` and `k8sclient.EKSConfig` for `*kubernetes.Clientset`; use `pkg/k8s-client.EKS` interface](https://github.com/aws/aws-k8s-tester/commit/e673d3388ee44889e6572dcdcee530ea06984a86).
4445
- Move [`healthz` checks to `k8sclient.EKS` interface](https://github.com/aws/aws-k8s-tester/commit/3dac533adcf2fb0aa51f19d4f56bbc9dd2b59eb5).
45-
- Add [`k8sclient.EKS.FetchVersion`](https://github.com/aws/aws-k8s-tester/commit/56cd2d0f26e88f8c806a74a503def91769a3e8e3).
46+
- Add [`k8sclient.EKS.FetchServerVersion`](https://github.com/aws/aws-k8s-tester/commit/56cd2d0f26e88f8c806a74a503def91769a3e8e3).
47+
- Include [`float64` version value in `ServerVersionInfo`](https://github.com/aws/aws-k8s-tester/commit/).
4648

4749
### Dependency
4850

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,35 @@ less +FG /tmp/config.yaml
195195
```
196196

197197

198-
## `eks-utils api-resources`
198+
## `eks-utils`
199199

200-
TODO
200+
Install `eks-utils` from https://github.com/aws/aws-k8s-tester/releases.
201+
202+
**WARNING**
203+
204+
`kubectl` internally converts API versions in the response (see [`kubernetes/issues#58131`](https://github.com/kubernetes/kubernetes/issues/58131#issuecomment-403829566)). Which means `kubectl get` output may have different API versions than the one persisted in `etcd`.
205+
206+
Upstream recommends upgrading deprecated API with *get and put*:
207+
208+
> the simplest approach is to get/put every object after upgrades. objects that don't need migration will no-op (they won't even increment resourceVersion in etcd). objects that do need migration will persist in the new preferred storage version
209+
210+
```bash
211+
# to check supported API groups from current kube-apiserver
212+
eks-utils apis \
213+
--kubeconfig /tmp/kubeconfig.yaml \
214+
supported
215+
216+
# to write API upgrade/rollback scripts and YAML files in "/tmp/eks-utils"
217+
#
218+
# make sure to set proper "--list-batch" and "--list-interval"
219+
# to not overload EKS master; if it's set too high, it can affect
220+
# production workloads slowing down kube-apiserver
221+
rm -rf /tmp/eks-utils
222+
eks-utils apis \
223+
--kubeconfig /tmp/kubeconfig.yaml \
224+
--enable-prompt \
225+
deprecate \
226+
--dir /tmp/eks-utils \
227+
--list-batch 10 \
228+
--list-interval 2s
229+
```

cmd/aws-k8s-tester/eks/check.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66

77
k8sclient "github.com/aws/aws-k8s-tester/pkg/k8s-client"
8-
"github.com/mitchellh/colorstring"
98
"github.com/spf13/cobra"
109
"go.uber.org/zap"
1110
"k8s.io/utils/exec"
@@ -75,14 +74,14 @@ func checkFunc(cmd *cobra.Command, args []string) {
7574
panic(fmt.Errorf("failed to create client %v", err))
7675
}
7776

78-
colorstring.Printf("\n\n\n[green]fetching version...\n\n")
79-
ver, err := cli.FetchVersion()
77+
fmt.Printf("\n\n************************\nfetching version\n\n")
78+
ver, err := cli.FetchServerVersion()
8079
if err != nil {
8180
panic(fmt.Errorf("failed to check version %v", err))
8281
}
8382
fmt.Printf("\n\nVersion:\n%+v\n\n", ver)
8483

85-
colorstring.Printf("\n\n\n[green]checking health...\n\n")
84+
fmt.Printf("\n\n************************\nchecking health...\n\n")
8685
if err = cli.CheckHealth(); err != nil {
8786
panic(fmt.Errorf("failed to check health %v", err))
8887
}

cmd/eks-utils/apis/command.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Package apis implements EKS API related commands.
2+
package apis
3+
4+
import (
5+
"io/ioutil"
6+
"os"
7+
"time"
8+
9+
"github.com/spf13/cobra"
10+
"k8s.io/utils/exec"
11+
)
12+
13+
var (
14+
enablePrompt bool
15+
clientQPS float32
16+
clientBurst int
17+
kubeConfigPath string
18+
kubeConfigContext string
19+
kubectlPath string
20+
21+
listBatch int64
22+
listInterval time.Duration
23+
dir string
24+
)
25+
26+
var (
27+
defaultKubectlPath string
28+
defaultDir string
29+
)
30+
31+
func init() {
32+
cobra.EnablePrefixMatching = true
33+
defaultKubectlPath, _ = exec.New().LookPath("kubectl")
34+
35+
var err error
36+
defaultDir, err = ioutil.TempDir(os.TempDir(), "eks-upgrade-dir")
37+
if err != nil {
38+
panic(err)
39+
}
40+
}
41+
42+
// NewCommand implements "eks-utils apis" command.
43+
func NewCommand() *cobra.Command {
44+
ac := &cobra.Command{
45+
Use: "apis",
46+
Short: "EKS API commands",
47+
}
48+
ac.PersistentFlags().BoolVar(&enablePrompt, "enable-prompt", true, "'true' to enable prompt mode")
49+
ac.PersistentFlags().Float32Var(&clientQPS, "client-qps", 5.0, "EKS client qps")
50+
ac.PersistentFlags().IntVar(&clientBurst, "client-burst", 10, "EKS client burst")
51+
ac.PersistentFlags().StringVar(&kubeConfigPath, "kubeconfig", "", "EKS KUBECONFIG")
52+
ac.PersistentFlags().StringVar(&kubeConfigContext, "kubeconfig-context", "", "EKS KUBECONFIG context")
53+
ac.PersistentFlags().StringVar(&kubectlPath, "kubectl", defaultKubectlPath, "kubectl path")
54+
ac.AddCommand(
55+
newSupportedCommand(),
56+
newDeprecateCommand(),
57+
)
58+
return ac
59+
}

cmd/eks-utils/apis/deprecate.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package apis
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"time"
7+
8+
k8sclient "github.com/aws/aws-k8s-tester/pkg/k8s-client"
9+
"github.com/spf13/cobra"
10+
"go.uber.org/zap"
11+
)
12+
13+
func newDeprecateCommand() *cobra.Command {
14+
ac := &cobra.Command{
15+
Use: "deprecate",
16+
Run: deprecatedFunc,
17+
Short: "Check deprecated APIs",
18+
Long: `
19+
eks-utils apis \
20+
--kubeconfig /tmp/kubeconfig.yaml \
21+
deprecate
22+
23+
eks-utils apis \
24+
--kubeconfig ~/.kube/config \
25+
--kubeconfig-context prow-hkg \
26+
deprecate
27+
`,
28+
}
29+
ac.PersistentFlags().Int64Var(&listBatch, "list-batch", 30, "List batch limit (e.g. 30 items at a time)")
30+
ac.PersistentFlags().DurationVar(&listInterval, "list-interval", 5*time.Second, "List interval")
31+
ac.PersistentFlags().StringVar(&dir, "dir", defaultDir, "Directory to save all resource specs for upgrades and rollbacks")
32+
return ac
33+
}
34+
35+
func deprecatedFunc(cmd *cobra.Command, args []string) {
36+
if kubectlPath == "" {
37+
panic(errors.New("'kubectl' not found"))
38+
}
39+
40+
fmt.Printf("\n\n************************\nstarting 'eks-utils apis upgrade'\n\n")
41+
42+
lg := zap.NewExample()
43+
kcfg := &k8sclient.EKSConfig{
44+
Logger: lg,
45+
ClientQPS: clientQPS,
46+
ClientBurst: clientBurst,
47+
KubeConfigPath: kubeConfigPath,
48+
KubeConfigContext: kubeConfigContext,
49+
KubectlPath: kubectlPath,
50+
ListBatch: listBatch,
51+
ListInterval: listInterval,
52+
EnablePrompt: enablePrompt,
53+
Dir: dir,
54+
}
55+
cli, err := k8sclient.NewEKS(kcfg)
56+
if err != nil {
57+
lg.Fatal("failed to create client", zap.Error(err))
58+
}
59+
60+
if err = cli.Deprecate(); err != nil {
61+
lg.Fatal("failed to upgrade", zap.Error(err))
62+
}
63+
64+
println()
65+
fmt.Println("'eks-utils apis upgrade' success")
66+
}

cmd/eks-utils/apis/supported.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package apis
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"sort"
7+
8+
k8sclient "github.com/aws/aws-k8s-tester/pkg/k8s-client"
9+
"github.com/spf13/cobra"
10+
"go.uber.org/zap"
11+
)
12+
13+
func newSupportedCommand() *cobra.Command {
14+
ac := &cobra.Command{
15+
Use: "supported",
16+
SuggestFor: []string{"support", "getsupportedapis", "getsupportedapi", "apiresources", "apiresource", "api-resource"},
17+
Run: supportedFunc,
18+
Short: "List all supported APIs",
19+
Long: `
20+
eks-utils apis \
21+
--kubeconfig /tmp/kubeconfig.yaml \
22+
supported
23+
24+
eks-utils apis \
25+
--kubeconfig ~/.kube/config \
26+
--kubeconfig-context prow-hkg \
27+
supported
28+
`,
29+
}
30+
ac.PersistentFlags().Float32Var(&clientQPS, "client-qps", 5.0, "EKS client qps")
31+
ac.PersistentFlags().IntVar(&clientBurst, "client-burst", 10, "EKS client burst")
32+
ac.PersistentFlags().StringVar(&kubeConfigPath, "kubeconfig", "", "EKS KUBECONFIG")
33+
ac.PersistentFlags().StringVar(&kubeConfigContext, "kubeconfig-context", "", "EKS KUBECONFIG context")
34+
ac.PersistentFlags().StringVar(&kubectlPath, "kubectl", defaultKubectlPath, "kubectl path")
35+
return ac
36+
}
37+
38+
func supportedFunc(cmd *cobra.Command, args []string) {
39+
if kubectlPath == "" {
40+
panic(errors.New("'kubectl' not found"))
41+
}
42+
fmt.Printf("\n\n************************\nstarting 'eks-utils apis supported'\n\n")
43+
44+
lg := zap.NewExample()
45+
46+
kcfg := &k8sclient.EKSConfig{
47+
Logger: lg,
48+
ClientQPS: clientQPS,
49+
ClientBurst: clientBurst,
50+
KubeConfigPath: kubeConfigPath,
51+
KubeConfigContext: kubeConfigContext,
52+
KubectlPath: kubectlPath,
53+
}
54+
cli, err := k8sclient.NewEKS(kcfg)
55+
if err != nil {
56+
lg.Fatal("failed to create client", zap.Error(err))
57+
}
58+
59+
vv, apiVersions, err := cli.FetchSupportedAPIGroupVersions()
60+
if err != nil {
61+
panic(fmt.Errorf("failed to check health %v", err))
62+
}
63+
ss := make([]string, 0, len(apiVersions))
64+
65+
fmt.Printf("\n\n************************\nchecking supported API group veresion for %.2f\n\n", vv)
66+
for k := range apiVersions {
67+
ss = append(ss, k)
68+
}
69+
sort.Strings(ss)
70+
for _, v := range ss {
71+
fmt.Println(v)
72+
}
73+
74+
println()
75+
fmt.Println("'eks-utils apis supported' success")
76+
}

cmd/eks-utils/main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// eks-utils is a set of EKS utilities commands.
2+
package main
3+
4+
import (
5+
"fmt"
6+
"os"
7+
8+
"github.com/aws/aws-k8s-tester/cmd/eks-utils/apis"
9+
"github.com/aws/aws-k8s-tester/cmd/eks-utils/version"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var rootCmd = &cobra.Command{
14+
Use: "eks-utils",
15+
Short: "AWS EKS utils CLI",
16+
SuggestFor: []string{"eksutils"},
17+
}
18+
19+
func init() {
20+
cobra.EnablePrefixMatching = true
21+
}
22+
23+
func init() {
24+
rootCmd.AddCommand(
25+
apis.NewCommand(),
26+
version.NewCommand(),
27+
)
28+
}
29+
30+
func main() {
31+
if err := rootCmd.Execute(); err != nil {
32+
fmt.Fprintf(os.Stderr, "eks-utils failed %v\n", err)
33+
os.Exit(1)
34+
}
35+
os.Exit(0)
36+
}

cmd/eks-utils/version/command.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Package version implements version command.
2+
package version
3+
4+
import (
5+
"fmt"
6+
7+
"github.com/aws/aws-k8s-tester/version"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func init() {
13+
cobra.EnablePrefixMatching = true
14+
}
15+
16+
// NewCommand implements "aws-k8s-tester eks" command.
17+
func NewCommand() *cobra.Command {
18+
return &cobra.Command{
19+
Use: "version",
20+
Short: "Prints out eks-utils version",
21+
Run: versionFunc,
22+
}
23+
}
24+
25+
func versionFunc(cmd *cobra.Command, args []string) {
26+
fmt.Print(version.Version())
27+
}

0 commit comments

Comments
 (0)