-
Notifications
You must be signed in to change notification settings - Fork 20
/
sks_deprecated_resources.go
104 lines (81 loc) · 2.91 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
97
98
99
100
101
102
103
104
package cmd
import (
"errors"
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
exoapi "github.com/exoscale/egoscale/v2/api"
)
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() { output.JSON(o) }
func (o *sksListDeprecatedResourcesOutput) ToText() { output.Text(o) }
func (o *sksListDeprecatedResourcesOutput) ToTable() { output.Table(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(output.TemplateAnnotations(&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(account.CurrentAccount.Environment, c.Zone))
cluster, err := globalstate.EgoscaleClient.FindSKSCluster(ctx, c.Zone, c.Cluster)
if err != nil {
if errors.Is(err, exoapi.ErrNotFound) {
return fmt.Errorf("resource not found in zone %q", c.Zone)
}
return err
}
deprecatedResources, err := globalstate.EgoscaleClient.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(),
}))
}