Skip to content

Commit 9a7f901

Browse files
authored
Merge pull request #12369 from fabriziopandini/switch-clusterctl-describe-to-v1beta2
⚠️ Clusterctl describe defaults to v1beta2
2 parents e3c936e + 7bc23d7 commit 9a7f901

File tree

8 files changed

+61
-62
lines changed

8 files changed

+61
-62
lines changed

cmd/clusterctl/client/describe.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ type DescribeClusterOptions struct {
5858
// have the same Status, Severity and Reason.
5959
Grouping bool
6060

61-
// V1Beta2 instructs tree to use V1Beta2 conditions.
62-
V1Beta2 bool
61+
// V1Beta1 instructs tree to use V1Beta1 conditions.
62+
//
63+
// Deprecated: This field will be removed when v1beta1 will be dropped.
64+
V1Beta1 bool
6365
}
6466

6567
// DescribeCluster returns the object tree representing the status of a Cluster API cluster.
@@ -99,6 +101,6 @@ func (c *clusterctlClient) DescribeCluster(ctx context.Context, options Describe
99101
AddTemplateVirtualNode: options.AddTemplateVirtualNode,
100102
Echo: options.Echo,
101103
Grouping: options.Grouping,
102-
V1Beta2: options.V1Beta2,
104+
V1Beta1: options.V1Beta1,
103105
})
104106
}

cmd/clusterctl/client/tree/discovery.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ type DiscoverOptions struct {
5757
// have the same Status, Severity and Reason.
5858
Grouping bool
5959

60-
// V1Beta2 instructs tree to use V1Beta2 conditions.
61-
V1Beta2 bool
60+
// V1Beta1 instructs tree to use V1Beta1 conditions.
61+
//
62+
// Deprecated: This field will be removed when v1beta1 will be dropped.
63+
V1Beta1 bool
6264
}
6365

6466
func (d DiscoverOptions) toObjectTreeOptions() ObjectTreeOptions {

cmd/clusterctl/client/tree/tree.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ type ObjectTreeOptions struct {
5757
// have the same Status, Severity and Reason
5858
Grouping bool
5959

60-
// V1Beta2 instructs tree to use V1Beta2 conditions.
61-
V1Beta2 bool
60+
// V1Beta1 instructs tree to use V1Beta1 conditions.
61+
//
62+
// Deprecated: This field will be removed when v1beta1 will be dropped.
63+
V1Beta1 bool
6264
}
6365

6466
// ObjectTree defines an object tree representing the status of a Cluster API cluster.
@@ -99,15 +101,15 @@ func (od ObjectTree) Add(parent, obj client.Object, opts ...AddObjectOption) (ad
99101
// its parent.
100102
var objReadyV1Beta1, parentReadyV1Beta1 *clusterv1.Condition
101103
var objAvailable, objReady, objUpToDate, parentReady *metav1.Condition
102-
switch od.options.V1Beta2 {
104+
switch od.options.V1Beta1 {
103105
case true:
106+
objReadyV1Beta1 = GetV1Beta1ReadyCondition(obj)
107+
parentReadyV1Beta1 = GetV1Beta1ReadyCondition(parent)
108+
default:
104109
objAvailable = GetAvailableCondition(obj)
105110
objReady = GetReadyCondition(obj)
106111
objUpToDate = GetMachineUpToDateCondition(obj)
107112
parentReady = GetReadyCondition(parent)
108-
default:
109-
objReadyV1Beta1 = GetV1Beta1ReadyCondition(obj)
110-
parentReadyV1Beta1 = GetV1Beta1ReadyCondition(parent)
111113
}
112114

113115
// If it is requested to show all the conditions for the object, add
@@ -119,13 +121,13 @@ func (od ObjectTree) Add(parent, obj client.Object, opts ...AddObjectOption) (ad
119121
// If echo should be dropped from the ObjectTree, return if the object's ready condition is true, and it is the same it has of parent's object ready condition (it is an echo).
120122
// Note: the Echo option applies only for infrastructure machine or bootstrap config objects, and for those objects only Ready condition makes sense.
121123
if addOpts.NoEcho && !od.options.Echo {
122-
switch od.options.V1Beta2 {
124+
switch od.options.V1Beta1 {
123125
case true:
124-
if (objReady != nil && objReady.Status == metav1.ConditionTrue) || hasSameAvailableReadyUptoDateStatusAndReason(nil, nil, parentReady, objReady, nil, nil) {
126+
if (objReadyV1Beta1 != nil && objReadyV1Beta1.Status == corev1.ConditionTrue) || hasSameReadyStatusSeverityAndReason(parentReadyV1Beta1, objReadyV1Beta1) {
125127
return false, false
126128
}
127129
default:
128-
if (objReadyV1Beta1 != nil && objReadyV1Beta1.Status == corev1.ConditionTrue) || hasSameReadyStatusSeverityAndReason(parentReadyV1Beta1, objReadyV1Beta1) {
130+
if (objReady != nil && objReady.Status == metav1.ConditionTrue) || hasSameAvailableReadyUptoDateStatusAndReason(nil, nil, parentReady, objReady, nil, nil) {
129131
return false, false
130132
}
131133
}
@@ -156,8 +158,16 @@ func (od ObjectTree) Add(parent, obj client.Object, opts ...AddObjectOption) (ad
156158

157159
var sReadyV1Beta1 *clusterv1.Condition
158160
var sAvailable, sReady, sUpToDate *metav1.Condition
159-
switch od.options.V1Beta2 {
161+
switch od.options.V1Beta1 {
160162
case true:
163+
sReadyV1Beta1 = GetV1Beta1ReadyCondition(s)
164+
165+
// If the object's ready condition has a different Status, Severity and Reason than the sibling object,
166+
// move on (they should not be grouped).
167+
if !hasSameReadyStatusSeverityAndReason(objReadyV1Beta1, sReadyV1Beta1) {
168+
continue
169+
}
170+
default:
161171
// If the object's ready condition has a different Available/ReadyUpToDate condition than the sibling object,
162172
// move on (they should not be grouped).
163173
sAvailable = GetAvailableCondition(s)
@@ -166,26 +176,18 @@ func (od ObjectTree) Add(parent, obj client.Object, opts ...AddObjectOption) (ad
166176
if !hasSameAvailableReadyUptoDateStatusAndReason(objAvailable, sAvailable, objReady, sReady, objUpToDate, sUpToDate) {
167177
continue
168178
}
169-
default:
170-
sReadyV1Beta1 = GetV1Beta1ReadyCondition(s)
171-
172-
// If the object's ready condition has a different Status, Severity and Reason than the sibling object,
173-
// move on (they should not be grouped).
174-
if !hasSameReadyStatusSeverityAndReason(objReadyV1Beta1, sReadyV1Beta1) {
175-
continue
176-
}
177179
}
178180

179181
// If the sibling node is already a group object
180182
if IsGroupObject(s) {
181183
// Check to see if the group object kind matches the object, i.e. group is MachineGroup and object is Machine.
182184
// If so, upgrade it with the current object.
183185
if s.GetObjectKind().GroupVersionKind().Kind == obj.GetObjectKind().GroupVersionKind().Kind+"Group" {
184-
switch od.options.V1Beta2 {
186+
switch od.options.V1Beta1 {
185187
case true:
186-
updateGroupNode(s, sReady, obj, objAvailable, objReady, objUpToDate)
187-
default:
188188
updateV1Beta1GroupNode(s, sReadyV1Beta1, obj, objReadyV1Beta1)
189+
default:
190+
updateGroupNode(s, sReady, obj, objAvailable, objReady, objUpToDate)
189191
}
190192

191193
return true, false
@@ -199,11 +201,11 @@ func (od ObjectTree) Add(parent, obj client.Object, opts ...AddObjectOption) (ad
199201

200202
// Create virtual object for the group and add it to the object tree.
201203
var groupNode *NodeObject
202-
switch od.options.V1Beta2 {
204+
switch od.options.V1Beta1 {
203205
case true:
204-
groupNode = createGroupNode(s, sReady, obj, objAvailable, objReady, objUpToDate)
205-
default:
206206
groupNode = createV1Beta1GroupNode(s, sReadyV1Beta1, obj, objReadyV1Beta1)
207+
default:
208+
groupNode = createGroupNode(s, sReady, obj, objAvailable, objReady, objUpToDate)
207209
}
208210

209211
// By default, grouping objects should be sorted last.

cmd/clusterctl/client/tree/tree_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,10 @@ func Test_Add_setsShowObjectConditionsAnnotation(t *testing.T) {
860860
},
861861
}
862862
for _, tt := range tests {
863-
for _, v1beta2 := range []bool{true, false} {
864-
tt.args.treeOptions.V1Beta2 = v1beta2
863+
for _, v1beta1 := range []bool{true, false} {
864+
tt.args.treeOptions.V1Beta1 = v1beta1
865865

866-
t.Run(tt.name+" v1beta2: "+fmt.Sprintf("%t", v1beta2), func(t *testing.T) {
866+
t.Run(tt.name+" v1beta2: "+fmt.Sprintf("%t", v1beta1), func(t *testing.T) {
867867
root := parent.DeepCopy()
868868
tree := NewObjectTree(root, tt.args.treeOptions)
869869

@@ -925,10 +925,10 @@ func Test_Add_setsGroupingObjectAnnotation(t *testing.T) {
925925
},
926926
}
927927
for _, tt := range tests {
928-
for _, v1beta2 := range []bool{true, false} {
929-
tt.args.treeOptions.V1Beta2 = v1beta2
928+
for _, v1beta1 := range []bool{true, false} {
929+
tt.args.treeOptions.V1Beta1 = v1beta1
930930

931-
t.Run(tt.name+" v1beta2: "+fmt.Sprintf("%t", v1beta2), func(t *testing.T) {
931+
t.Run(tt.name+" v1beta2: "+fmt.Sprintf("%t", v1beta1), func(t *testing.T) {
932932
root := parent.DeepCopy()
933933
tree := NewObjectTree(root, tt.args.treeOptions)
934934

@@ -979,10 +979,10 @@ func Test_Add_setsObjectMetaNameAnnotation(t *testing.T) {
979979
},
980980
}
981981
for _, tt := range tests {
982-
for _, v1beta2 := range []bool{true, false} {
983-
treeOptions := ObjectTreeOptions{V1Beta2: v1beta2}
982+
for _, v1beta1 := range []bool{true, false} {
983+
treeOptions := ObjectTreeOptions{V1Beta1: v1beta1}
984984

985-
t.Run(tt.name+" v1beta2: "+fmt.Sprintf("%t", v1beta2), func(t *testing.T) {
985+
t.Run(tt.name+" v1beta2: "+fmt.Sprintf("%t", v1beta1), func(t *testing.T) {
986986
root := parent.DeepCopy()
987987
tree := NewObjectTree(root, treeOptions)
988988

@@ -1067,7 +1067,6 @@ func Test_Add_NoEcho(t *testing.T) {
10671067
}
10681068
for _, tt := range tests {
10691069
t.Run(tt.name, func(t *testing.T) {
1070-
tt.args.treeOptions.V1Beta2 = true
10711070
root := parent.DeepCopy()
10721071
tree := NewObjectTree(root, tt.args.treeOptions)
10731072

@@ -1149,6 +1148,8 @@ func Test_Add_NoEcho_V1Beta1(t *testing.T) {
11491148
}
11501149
for _, tt := range tests {
11511150
t.Run(tt.name, func(t *testing.T) {
1151+
tt.args.treeOptions.V1Beta1 = true
1152+
11521153
root := parent.DeepCopy()
11531154
tree := NewObjectTree(root, tt.args.treeOptions)
11541155

@@ -1249,7 +1250,7 @@ func Test_Add_Grouping(t *testing.T) {
12491250
for _, tt := range tests {
12501251
t.Run(tt.name, func(t *testing.T) {
12511252
root := parent.DeepCopy()
1252-
tree := NewObjectTree(root, ObjectTreeOptions{V1Beta2: true})
1253+
tree := NewObjectTree(root, ObjectTreeOptions{})
12531254

12541255
for i := range tt.args.siblings {
12551256
tree.Add(parent, tt.args.siblings[i], tt.args.addOptions...)
@@ -1361,7 +1362,7 @@ func Test_Add_Grouping_V1Beta1(t *testing.T) {
13611362
for _, tt := range tests {
13621363
t.Run(tt.name, func(t *testing.T) {
13631364
root := parent.DeepCopy()
1364-
tree := NewObjectTree(root, ObjectTreeOptions{})
1365+
tree := NewObjectTree(root, ObjectTreeOptions{V1Beta1: true})
13651366

13661367
for i := range tt.args.siblings {
13671368
tree.Add(parent, tt.args.siblings[i], tt.args.addOptions...)

cmd/clusterctl/cmd/describe_cluster.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ func init() {
109109
"Disable grouping machines when ready condition has the same Status, Severity and Reason.")
110110
_ = describeClusterClusterCmd.Flags().MarkDeprecated("disable-grouping",
111111
"use --grouping instead.")
112-
describeClusterClusterCmd.Flags().BoolVar(&dc.v1beta2, "v1beta2", false,
112+
describeClusterClusterCmd.Flags().BoolVar(&dc.v1beta2, "v1beta2", true,
113113
"Use V1Beta2 conditions..")
114+
_ = describeClusterClusterCmd.Flags().MarkDeprecated("v1beta2",
115+
"this field will be removed when v1beta1 will be dropped.")
114116
describeClusterClusterCmd.Flags().BoolVarP(&dc.color, "color", "c", false, "Enable or disable color output; if not set color is enabled by default only if using tty. The flag is overridden by the NO_COLOR env variable if set.")
115117

116118
// completions
@@ -144,7 +146,7 @@ func runDescribeCluster(cmd *cobra.Command, name string) error {
144146
AddTemplateVirtualNode: true,
145147
Echo: dc.echo,
146148
Grouping: dc.grouping && !dc.disableGrouping,
147-
V1Beta2: dc.v1beta2,
149+
V1Beta1: !dc.v1beta2,
148150
})
149151
if err != nil {
150152
return err

docs/book/src/developer/providers/migrations/v1.10-to-v1.11.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,13 @@ TODO
474474

475475
### clusterctl
476476

477-
- **Stricter validation for provider metadata**: clusterctl now enforces validation rules when reading provider metadata files to ensure they are properly formatted and contain required information. The following validation rules are now enforced:
477+
- **Stricter validation for provider metadata**: clusterctl now enforces validation rules when reading provider metadata files to ensure they are properly formatted and contain required information.
478+
These changes help surface mis-shaped metadata early and make failures easier to troubleshoot. Providers with invalid metadata.yaml files will need to update them to comply with these validation rules.
479+
The following validation rules are now enforced:
478480
- `apiVersion` must be set to `clusterctl.cluster.x-k8s.io/v1alpha3`
479481
- `kind` must be set to `Metadata`
480482
- `releaseSeries` must contain at least one entry
481-
482-
These changes help surface mis-shaped metadata early and make failures easier to troubleshoot. Providers with invalid metadata.yaml files will need to update them to comply with these validation rules.
483+
- The `--v1beta2` flag in clusterctl describe now defaults to `true`; the flag will be removed as soon as v1beta1 API is removed.
483484

484485
## Deprecations
485486

internal/util/tree/tree_test.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,7 @@ func Test_TreePrefix(t *testing.T) {
314314
Message: "first line must not be validated in the test\nsecond line",
315315
}),
316316
)
317-
objectTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{
318-
V1Beta2: true,
319-
})
317+
objectTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{})
320318

321319
o1 := fakeObject("child1",
322320
withCondition(falseCondition("Available", "first line must not be validated in the test\nsecond line")),
@@ -348,9 +346,7 @@ func Test_TreePrefix(t *testing.T) {
348346
Reason: "Available",
349347
}),
350348
)
351-
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{
352-
V1Beta2: true,
353-
})
349+
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{})
354350

355351
o1 := fakeObject("child1",
356352
withCondition(trueCondition()),
@@ -383,9 +379,7 @@ func Test_TreePrefix(t *testing.T) {
383379
Reason: "Available",
384380
}),
385381
)
386-
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{
387-
V1Beta2: true,
388-
})
382+
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{})
389383

390384
o1 := fakeObject("child1",
391385
withCondition(trueCondition()),
@@ -432,9 +426,7 @@ func Test_TreePrefix(t *testing.T) {
432426
Reason: "Available",
433427
}),
434428
)
435-
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{
436-
V1Beta2: true,
437-
})
429+
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{})
438430

439431
o1 := fakeObject("child1",
440432
withCondition(trueCondition()),
@@ -475,9 +467,7 @@ func Test_TreePrefix(t *testing.T) {
475467
Reason: "Available",
476468
}),
477469
)
478-
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{
479-
V1Beta2: true,
480-
})
470+
obectjTree := tree.NewObjectTree(root, tree.ObjectTreeOptions{})
481471

482472
o1 := fakeObject("child1",
483473
withCondition(trueCondition()),

test/framework/cluster_helpers.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ func DescribeCluster(ctx context.Context, input DescribeClusterInput) {
368368
AddTemplateVirtualNode: true,
369369
Echo: true,
370370
Grouping: false,
371-
V1Beta2: true,
372371
})
373372
Expect(err).ToNot(HaveOccurred(), "Failed to run clusterctl describe")
374373

0 commit comments

Comments
 (0)