Skip to content

Commit 49b4d0c

Browse files
committed
add CPMS type to MachineConfiguration API
1 parent 138fe6b commit 49b4d0c

File tree

2 files changed

+126
-3
lines changed

2 files changed

+126
-3
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
2+
name: "MachineConfiguration"
3+
crdName: machineconfigurations.operator.openshift.io
4+
featureGates:
5+
- ManagedBootImages
6+
tests:
7+
onCreate:
8+
- name: Should be able to create a minimal MachineConfiguration
9+
initial: |
10+
apiVersion: operator.openshift.io/v1
11+
kind: MachineConfiguration
12+
spec: {} # No spec is required for a MachineConfiguration
13+
expected: |
14+
apiVersion: operator.openshift.io/v1
15+
kind: MachineConfiguration
16+
spec:
17+
logLevel: Normal
18+
operatorLogLevel: Normal
19+
- name: Should be able to create an empty ManagedBootImages configuration knob
20+
initial: |
21+
apiVersion: operator.openshift.io/v1
22+
kind: MachineConfiguration
23+
spec:
24+
managedBootImages:
25+
machineManagers: []
26+
expected: |
27+
apiVersion: operator.openshift.io/v1
28+
kind: MachineConfiguration
29+
spec:
30+
logLevel: Normal
31+
operatorLogLevel: Normal
32+
managedBootImages:
33+
machineManagers: []
34+
- name: Should be able to create a ManagedBootImages configuration knob that opts in all ControlPlaneMachineSets
35+
initial: |
36+
apiVersion: operator.openshift.io/v1
37+
kind: MachineConfiguration
38+
spec:
39+
managedBootImages:
40+
machineManagers:
41+
- resource: controlplanemachinesets
42+
apiGroup: machine.openshift.io
43+
selection:
44+
mode: All
45+
expected: |
46+
apiVersion: operator.openshift.io/v1
47+
kind: MachineConfiguration
48+
spec:
49+
logLevel: Normal
50+
operatorLogLevel: Normal
51+
managedBootImages:
52+
machineManagers:
53+
- resource: controlplanemachinesets
54+
apiGroup: machine.openshift.io
55+
selection:
56+
mode: All
57+
- name: Should be able to create a ManagedBootImages configuration knob that opts in ControlPlaneMachineSets in partial mode
58+
initial: |
59+
apiVersion: operator.openshift.io/v1
60+
kind: MachineConfiguration
61+
spec:
62+
managedBootImages:
63+
machineManagers:
64+
- resource: controlplanemachinesets
65+
apiGroup: machine.openshift.io
66+
selection:
67+
mode: Partial
68+
partial:
69+
machineResourceSelector:
70+
matchLabels: {}
71+
expected: |
72+
apiVersion: operator.openshift.io/v1
73+
kind: MachineConfiguration
74+
spec:
75+
logLevel: Normal
76+
operatorLogLevel: Normal
77+
managedBootImages:
78+
machineManagers:
79+
- resource: controlplanemachinesets
80+
apiGroup: machine.openshift.io
81+
selection:
82+
mode: Partial
83+
partial:
84+
machineResourceSelector:
85+
matchLabels: {}
86+
- name: Should not be able to add partial field if machineManager.selection.mode is not set to Partial
87+
initial: |
88+
apiVersion: operator.openshift.io/v1
89+
kind: MachineConfiguration
90+
spec:
91+
managedBootImages:
92+
machineManagers:
93+
- resource: controlplanemachinesets
94+
apiGroup: machine.openshift.io
95+
selection:
96+
mode: All
97+
partial:
98+
machineResourceSelector:
99+
matchLabels: {}
100+
expectedError: "Partial is required when type is partial, and forbidden otherwise"
101+
- name: Only one unique pair of resource/apigroup is allowed in machineManagers
102+
initial: |
103+
apiVersion: operator.openshift.io/v1
104+
kind: MachineConfiguration
105+
spec:
106+
managedBootImages:
107+
machineManagers:
108+
- resource: controlplanemachinesets
109+
apiGroup: machine.openshift.io
110+
selection:
111+
mode: Partial
112+
partial:
113+
machineResourceSelector:
114+
matchLabels: {}
115+
- resource: controlplanemachinesets
116+
apiGroup: machine.openshift.io
117+
selection:
118+
mode: All
119+
expectedError: "spec.managedBootImages.machineManagers[1]: Duplicate value: map[string]interface {}{\"apiGroup\":\"machine.openshift.io\", \"resource\":\"machinesets\"}"

operator/v1/types_machineconfiguration.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ type ManagedBootImages struct {
135135
// such as the resource type and the API Group of the resource. It also provides granular control via the selection field.
136136
type MachineManager struct {
137137
// resource is the machine management resource's type.
138-
// The only current valid value is machinesets.
138+
// Valid values are machinesets and controlplanemachinesets.
139139
// machinesets means that the machine manager will only register resources of the kind MachineSet.
140+
// controlplanemachinesets means that the machine manager will only register resources of the kind ControlPlaneMachineSet.
140141
// +required
141142
Resource MachineManagerMachineSetsResourceType `json:"resource"`
142143

@@ -194,12 +195,15 @@ const (
194195

195196
// MachineManagerManagedResourceType is a string enum used in the MachineManager type to describe the resource
196197
// type to be registered.
197-
// +kubebuilder:validation:Enum:="machinesets"
198+
// +openshift:validation:FeatureGateAwareEnum:featureGate="",enum=machinesets
199+
// +openshift:validation:FeatureGateAwareEnum:featureGate=ManagedBootImagesCPMS,enum=machinesets;controlplanemachinesets
198200
type MachineManagerMachineSetsResourceType string
199201

200202
const (
201203
// MachineSets represent the MachineSet resource type, which manage a group of machines and belong to the Openshift machine API group.
202204
MachineSets MachineManagerMachineSetsResourceType = "machinesets"
205+
// ControlPlaneMachineSets represent the ControlPlaneMachineSets resource type, which manage a group of control-plane machines and belong to the Openshift machine API group.
206+
ControlPlaneMachineSets MachineManagerMachineSetsResourceType = "controlplanemachinesets"
203207
)
204208

205209
// MachineManagerManagedAPIGroupType is a string enum used in in the MachineManager type to describe the APIGroup
@@ -209,7 +213,7 @@ type MachineManagerMachineSetsAPIGroupType string
209213

210214
const (
211215
// MachineAPI represent the traditional MAPI Group that a machineset may belong to.
212-
// This feature only supports MAPI machinesets at this time.
216+
// This feature only supports MAPI machinesets and controlplanemachinesets at this time.
213217
MachineAPI MachineManagerMachineSetsAPIGroupType = "machine.openshift.io"
214218
)
215219

0 commit comments

Comments
 (0)