Skip to content

Commit 008e32c

Browse files
authored
Merge pull request #7988 from hiromu-a5a/refactoring-rollout
⚠️ Refactor clusterctl alpha rollout
2 parents 94ea776 + efe3728 commit 008e32c

File tree

9 files changed

+263
-98
lines changed

9 files changed

+263
-98
lines changed

cmd/clusterctl/client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ type Client interface {
7979
// AlphaClient exposes the alpha features in clusterctl high-level client library.
8080
type AlphaClient interface {
8181
// RolloutRestart provides rollout restart of cluster-api resources
82-
RolloutRestart(options RolloutOptions) error
82+
RolloutRestart(options RolloutRestartOptions) error
8383
// RolloutPause provides rollout pause of cluster-api resources
84-
RolloutPause(options RolloutOptions) error
84+
RolloutPause(options RolloutPauseOptions) error
8585
// RolloutResume provides rollout resume of paused cluster-api resources
86-
RolloutResume(options RolloutOptions) error
86+
RolloutResume(options RolloutResumeOptions) error
8787
// RolloutUndo provides rollout rollback of cluster-api resources
88-
RolloutUndo(options RolloutOptions) error
88+
RolloutUndo(options RolloutUndoOptions) error
8989
// TopologyPlan dry runs the topology reconciler
9090
TopologyPlan(options TopologyPlanOptions) (*TopologyPlanOutput, error)
9191
}

cmd/clusterctl/client/client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,23 @@ func (f fakeClient) ProcessYAML(options ProcessYAMLOptions) (YamlPrinter, error)
124124
return f.internalClient.ProcessYAML(options)
125125
}
126126

127-
func (f fakeClient) RolloutRestart(options RolloutOptions) error {
127+
func (f fakeClient) RolloutRestart(options RolloutRestartOptions) error {
128128
return f.internalClient.RolloutRestart(options)
129129
}
130130

131131
func (f fakeClient) DescribeCluster(options DescribeClusterOptions) (*tree.ObjectTree, error) {
132132
return f.internalClient.DescribeCluster(options)
133133
}
134134

135-
func (f fakeClient) RolloutPause(options RolloutOptions) error {
135+
func (f fakeClient) RolloutPause(options RolloutPauseOptions) error {
136136
return f.internalClient.RolloutPause(options)
137137
}
138138

139-
func (f fakeClient) RolloutResume(options RolloutOptions) error {
139+
func (f fakeClient) RolloutResume(options RolloutResumeOptions) error {
140140
return f.internalClient.RolloutResume(options)
141141
}
142142

143-
func (f fakeClient) RolloutUndo(options RolloutOptions) error {
143+
func (f fakeClient) RolloutUndo(options RolloutUndoOptions) error {
144144
return f.internalClient.RolloutUndo(options)
145145
}
146146

cmd/clusterctl/client/rollout.go

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,50 @@ import (
2626
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
2727
)
2828

29-
// RolloutOptions carries the base set of options supported by rollout command.
30-
type RolloutOptions struct {
29+
// RolloutRestartOptions carries the options supported by RolloutRestart.
30+
type RolloutRestartOptions struct {
31+
// Kubeconfig defines the kubeconfig to use for accessing the management cluster. If empty,
32+
// default rules for kubeconfig discovery will be used.
33+
Kubeconfig Kubeconfig
34+
35+
// Resources for the rollout command
36+
Resources []string
37+
38+
// Namespace where the resource(s) live. If unspecified, the namespace name will be inferred
39+
// from the current configuration.
40+
Namespace string
41+
}
42+
43+
// RolloutPauseOptions carries the options supported by RolloutPause.
44+
type RolloutPauseOptions struct {
45+
// Kubeconfig defines the kubeconfig to use for accessing the management cluster. If empty,
46+
// default rules for kubeconfig discovery will be used.
47+
Kubeconfig Kubeconfig
48+
49+
// Resources for the rollout command
50+
Resources []string
51+
52+
// Namespace where the resource(s) live. If unspecified, the namespace name will be inferred
53+
// from the current configuration.
54+
Namespace string
55+
}
56+
57+
// RolloutResumeOptions carries the options supported by RolloutResume.
58+
type RolloutResumeOptions struct {
59+
// Kubeconfig defines the kubeconfig to use for accessing the management cluster. If empty,
60+
// default rules for kubeconfig discovery will be used.
61+
Kubeconfig Kubeconfig
62+
63+
// Resources for the rollout command
64+
Resources []string
65+
66+
// Namespace where the resource(s) live. If unspecified, the namespace name will be inferred
67+
// from the current configuration.
68+
Namespace string
69+
}
70+
71+
// RolloutUndoOptions carries the options supported by RolloutUndo.
72+
type RolloutUndoOptions struct {
3173
// Kubeconfig defines the kubeconfig to use for accessing the management cluster. If empty,
3274
// default rules for kubeconfig discovery will be used.
3375
Kubeconfig Kubeconfig
@@ -40,16 +82,15 @@ type RolloutOptions struct {
4082
Namespace string
4183

4284
// Revision number to rollback to when issuing the undo command.
43-
// Revision number of a specific revision when issuing the history command.
4485
ToRevision int64
4586
}
4687

47-
func (c *clusterctlClient) RolloutRestart(options RolloutOptions) error {
88+
func (c *clusterctlClient) RolloutRestart(options RolloutRestartOptions) error {
4889
clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig})
4990
if err != nil {
5091
return err
5192
}
52-
objRefs, err := getObjectRefs(clusterClient, options)
93+
objRefs, err := getObjectRefs(clusterClient, options.Namespace, options.Resources)
5394
if err != nil {
5495
return err
5596
}
@@ -61,12 +102,12 @@ func (c *clusterctlClient) RolloutRestart(options RolloutOptions) error {
61102
return nil
62103
}
63104

64-
func (c *clusterctlClient) RolloutPause(options RolloutOptions) error {
105+
func (c *clusterctlClient) RolloutPause(options RolloutPauseOptions) error {
65106
clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig})
66107
if err != nil {
67108
return err
68109
}
69-
objRefs, err := getObjectRefs(clusterClient, options)
110+
objRefs, err := getObjectRefs(clusterClient, options.Namespace, options.Resources)
70111
if err != nil {
71112
return err
72113
}
@@ -78,12 +119,12 @@ func (c *clusterctlClient) RolloutPause(options RolloutOptions) error {
78119
return nil
79120
}
80121

81-
func (c *clusterctlClient) RolloutResume(options RolloutOptions) error {
122+
func (c *clusterctlClient) RolloutResume(options RolloutResumeOptions) error {
82123
clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig})
83124
if err != nil {
84125
return err
85126
}
86-
objRefs, err := getObjectRefs(clusterClient, options)
127+
objRefs, err := getObjectRefs(clusterClient, options.Namespace, options.Resources)
87128
if err != nil {
88129
return err
89130
}
@@ -95,12 +136,12 @@ func (c *clusterctlClient) RolloutResume(options RolloutOptions) error {
95136
return nil
96137
}
97138

98-
func (c *clusterctlClient) RolloutUndo(options RolloutOptions) error {
139+
func (c *clusterctlClient) RolloutUndo(options RolloutUndoOptions) error {
99140
clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig})
100141
if err != nil {
101142
return err
102143
}
103-
objRefs, err := getObjectRefs(clusterClient, options)
144+
objRefs, err := getObjectRefs(clusterClient, options.Namespace, options.Resources)
104145
if err != nil {
105146
return err
106147
}
@@ -112,21 +153,21 @@ func (c *clusterctlClient) RolloutUndo(options RolloutOptions) error {
112153
return nil
113154
}
114155

115-
func getObjectRefs(clusterClient cluster.Client, options RolloutOptions) ([]corev1.ObjectReference, error) {
156+
func getObjectRefs(clusterClient cluster.Client, namespace string, resources []string) ([]corev1.ObjectReference, error) {
116157
// If the option specifying the Namespace is empty, try to detect it.
117-
if options.Namespace == "" {
158+
if namespace == "" {
118159
currentNamespace, err := clusterClient.Proxy().CurrentNamespace()
119160
if err != nil {
120161
return []corev1.ObjectReference{}, err
121162
}
122-
options.Namespace = currentNamespace
163+
namespace = currentNamespace
123164
}
124165

125-
if len(options.Resources) == 0 {
166+
if len(resources) == 0 {
126167
return []corev1.ObjectReference{}, fmt.Errorf("required resource not specified")
127168
}
128-
normalized := normalizeResources(options.Resources)
129-
objRefs, err := util.GetObjectReferences(options.Namespace, normalized...)
169+
normalized := normalizeResources(resources)
170+
objRefs, err := util.GetObjectReferences(namespace, normalized...)
130171
if err != nil {
131172
return []corev1.ObjectReference{}, err
132173
}

0 commit comments

Comments
 (0)