-
Notifications
You must be signed in to change notification settings - Fork 20
/
sks_deprecated_resources.go
96 lines (74 loc) · 2.63 KB
/
sks_deprecated_resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cmd
import (
"fmt"
"strings"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type sksListDeprecatedResourcesItemOutput struct {
Group string `json:"group"`
Version string `json:"version"`
Resource string `json:"resource"`
SubResource string `json:"subresource"`
RemovedRelease string `json:"removed_release"`
}
type sksListDeprecatedResourcesOutput []sksListDeprecatedResourcesItemOutput
func (o *sksListDeprecatedResourcesOutput) toJSON() { outputJSON(o) }
func (o *sksListDeprecatedResourcesOutput) toText() { outputText(o) }
func (o *sksListDeprecatedResourcesOutput) toTable() { outputTable(o) }
type sksDeprecatedResourcesCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"deprecated-resources"`
Cluster string `cli-arg:"#" cli-usage:"CLUSTER-NAME|ID"`
Zone string `cli-short:"z" cli-usage:"SKS cluster zone"`
}
func (c *sksDeprecatedResourcesCmd) cmdAliases() []string { return []string{"dr"} }
func (c *sksDeprecatedResourcesCmd) cmdShort() string {
return "List resources that will be deprecated in a futur release of Kubernetes for an SKS cluster"
}
func (c *sksDeprecatedResourcesCmd) cmdLong() string {
return fmt.Sprintf(`This command lists SKS cluster Nodepools.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&sksListDeprecatedResourcesItemOutput{}), ", "))
}
func emptyIfNil(inp *string) string {
if inp == nil {
return ""
}
return *inp
}
func (c *sksDeprecatedResourcesCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *sksDeprecatedResourcesCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, c.Zone))
cluster, err := cs.FindSKSCluster(ctx, c.Zone, c.Cluster)
if err != nil {
return err
}
deprecatedResources, err := cs.ListSKSClusterDeprecatedResources(
ctx,
c.Zone,
cluster,
)
if err != nil {
return fmt.Errorf("error retrieving deprecated resources: %w", err)
}
out := make(sksListDeprecatedResourcesOutput, 0)
for _, t := range deprecatedResources {
out = append(out, sksListDeprecatedResourcesItemOutput{
Group: emptyIfNil(t.Group),
RemovedRelease: emptyIfNil(t.RemovedRelease),
Resource: emptyIfNil(t.Resource),
SubResource: emptyIfNil(t.SubResource),
Version: emptyIfNil(t.Version),
})
}
return c.outputFunc(&out, nil)
}
func init() {
cobra.CheckErr(registerCLICommand(sksCmd, &sksDeprecatedResourcesCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}