Skip to content

Commit fb92a96

Browse files
Merge pull request openshift#8166 from r4f4/capi-manifests
CORS-3142: capi: write manifests to disk during create manifests
2 parents 6ca6a89 + 2833e66 commit fb92a96

File tree

17 files changed

+64
-68
lines changed

17 files changed

+64
-68
lines changed

pkg/asset/machines/aws/awsmachines.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ func GenerateMachines(clusterID string, region string, subnets map[string]string
5454
}
5555

5656
awsMachine := &capa.AWSMachine{
57-
TypeMeta: metav1.TypeMeta{
58-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta2",
59-
Kind: "AWSMachine",
60-
},
6157
ObjectMeta: metav1.ObjectMeta{
6258
Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, idx),
6359
Labels: map[string]string{
@@ -82,6 +78,7 @@ func GenerateMachines(clusterID string, region string, subnets map[string]string
8278
},
8379
},
8480
}
81+
awsMachine.SetGroupVersionKind(capa.GroupVersion.WithKind("AWSMachine"))
8582

8683
// Handle additional security groups.
8784
for _, sg := range mpool.AdditionalSecurityGroupIDs {
@@ -109,12 +106,13 @@ func GenerateMachines(clusterID string, region string, subnets map[string]string
109106
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, role)),
110107
},
111108
InfrastructureRef: v1.ObjectReference{
112-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta2",
109+
APIVersion: capa.GroupVersion.String(),
113110
Kind: "AWSMachine",
114111
Name: awsMachine.Name,
115112
},
116113
},
117114
}
115+
machine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
118116

119117
result = append(result, &asset.RuntimeFile{
120118
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", machine.Name)},

pkg/asset/machines/azure/azuremachines.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
109109
for idx := int64(0); idx < total; idx++ {
110110
zone := mpool.Zones[int(idx)%len(mpool.Zones)]
111111
azureMachine := &capz.AzureMachine{
112-
TypeMeta: metav1.TypeMeta{
113-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
114-
Kind: "AzureMachine",
115-
},
116112
ObjectMeta: metav1.ObjectMeta{
117113
Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, idx),
118114
Labels: map[string]string{
@@ -131,6 +127,7 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
131127
SecurityProfile: securityProfile,
132128
},
133129
}
130+
azureMachine.SetGroupVersionKind(capz.GroupVersion.WithKind("AzureMachine"))
134131
result = append(result, &asset.RuntimeFile{
135132
File: asset.File{Filename: fmt.Sprintf("10_inframachine_%s.yaml", azureMachine.Name)},
136133
Object: azureMachine,
@@ -149,12 +146,13 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
149146
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, role)),
150147
},
151148
InfrastructureRef: v1.ObjectReference{
152-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta2",
149+
APIVersion: capz.GroupVersion.String(),
153150
Kind: "AzureMachine",
154151
Name: azureMachine.Name,
155152
},
156153
},
157154
}
155+
controlPlaneMachine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
158156

159157
result = append(result, &asset.RuntimeFile{
160158
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", azureMachine.Name)},
@@ -163,10 +161,6 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
163161
}
164162

165163
bootstrapAzureMachine := &capz.AzureMachine{
166-
TypeMeta: metav1.TypeMeta{
167-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
168-
Kind: "AzureMachine",
169-
},
170164
ObjectMeta: metav1.ObjectMeta{
171165
Name: capiutils.GenerateBoostrapMachineName(clusterID),
172166
Labels: map[string]string{
@@ -186,6 +180,7 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
186180
SecurityProfile: securityProfile,
187181
},
188182
}
183+
bootstrapAzureMachine.SetGroupVersionKind(capz.GroupVersion.WithKind("AzureMachine"))
189184

190185
result = append(result, &asset.RuntimeFile{
191186
File: asset.File{Filename: fmt.Sprintf("10_inframachine_%s.yaml", bootstrapAzureMachine.Name)},
@@ -205,12 +200,13 @@ func GenerateMachines(platform *azure.Platform, pool *types.MachinePool, userDat
205200
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, "bootstrap")),
206201
},
207202
InfrastructureRef: v1.ObjectReference{
208-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta2",
203+
APIVersion: capz.GroupVersion.String(),
209204
Kind: "AzureMachine",
210205
Name: bootstrapAzureMachine.Name,
211206
},
212207
},
213208
}
209+
bootstrapMachine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
214210

215211
result = append(result, &asset.RuntimeFile{
216212
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", bootstrapMachine.Name)},

pkg/asset/machines/clusterapi.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package machines
33
import (
44
"context"
55
"fmt"
6-
"os"
76
"path/filepath"
87
"strings"
98

@@ -44,6 +43,8 @@ import (
4443

4544
var _ asset.WritableRuntimeAsset = (*ClusterAPI)(nil)
4645

46+
var machineManifestDir = filepath.Join(capiutils.ManifestDir, "machines")
47+
4748
// ClusterAPI is the asset for CAPI control-plane manifests.
4849
type ClusterAPI struct {
4950
FileList []*asset.RuntimeFile
@@ -78,10 +79,6 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
7879
return nil
7980
}
8081

81-
if err := os.MkdirAll(filepath.Dir(capiutils.ManifestDir), 0755); err != nil {
82-
return err
83-
}
84-
8582
c.FileList = []*asset.RuntimeFile{}
8683

8784
var err error
@@ -191,6 +188,7 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
191188
},
192189
},
193190
}
191+
bootstrapAWSMachine.SetGroupVersionKind(capa.GroupVersion.WithKind("AWSMachine"))
194192

195193
// Handle additional security groups.
196194
for _, sg := range mpool.AdditionalSecurityGroupIDs {
@@ -218,12 +216,13 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
218216
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID.InfraID, "bootstrap")),
219217
},
220218
InfrastructureRef: v1.ObjectReference{
221-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta2",
219+
APIVersion: capa.GroupVersion.String(),
222220
Kind: "AWSMachine",
223221
Name: bootstrapAWSMachine.Name,
224222
},
225223
},
226224
}
225+
bootstrapMachine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
227226

228227
c.FileList = append(c.FileList, &asset.RuntimeFile{
229228
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", bootstrapMachine.Name)},
@@ -421,10 +420,10 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
421420
m.Data = objData
422421

423422
// If the filename is already a path, do not append the manifest dir.
424-
if filepath.Dir(m.Filename) == capiutils.ManifestDir {
423+
if filepath.Dir(m.Filename) == machineManifestDir {
425424
continue
426425
}
427-
m.Filename = filepath.Join(capiutils.ManifestDir, m.Filename)
426+
m.Filename = filepath.Join(machineManifestDir, m.Filename)
428427
}
429428
asset.SortManifestFiles(c.FileList)
430429
return nil
@@ -446,15 +445,15 @@ func (c *ClusterAPI) RuntimeFiles() []*asset.RuntimeFile {
446445

447446
// Load returns the openshift asset from disk.
448447
func (c *ClusterAPI) Load(f asset.FileFetcher) (bool, error) {
449-
yamlFileList, err := f.FetchByPattern(filepath.Join(capiutils.ManifestDir, "*.yaml"))
448+
yamlFileList, err := f.FetchByPattern(filepath.Join(machineManifestDir, "*.yaml"))
450449
if err != nil {
451450
return false, errors.Wrap(err, "failed to load *.yaml files")
452451
}
453-
ymlFileList, err := f.FetchByPattern(filepath.Join(capiutils.ManifestDir, "*.yml"))
452+
ymlFileList, err := f.FetchByPattern(filepath.Join(machineManifestDir, "*.yml"))
454453
if err != nil {
455454
return false, errors.Wrap(err, "failed to load *.yml files")
456455
}
457-
jsonFileList, err := f.FetchByPattern(filepath.Join(capiutils.ManifestDir, "*.json"))
456+
jsonFileList, err := f.FetchByPattern(filepath.Join(machineManifestDir, "*.json"))
458457
if err != nil {
459458
return false, errors.Wrap(err, "failed to load *.json files")
460459
}

pkg/asset/machines/gcp/gcpmachines.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ func createGCPMachine(name string, installConfig *installconfig.InstallConfig, i
104104
}
105105

106106
gcpMachine := &capg.GCPMachine{
107-
TypeMeta: metav1.TypeMeta{
108-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
109-
Kind: "GCPMachine",
110-
},
111107
ObjectMeta: metav1.ObjectMeta{
112108
Name: name,
113109
Labels: map[string]string{
@@ -123,6 +119,7 @@ func createGCPMachine(name string, installConfig *installconfig.InstallConfig, i
123119
RootDeviceSize: mpool.OSDisk.DiskSizeGB,
124120
},
125121
}
122+
gcpMachine.SetGroupVersionKind(capg.GroupVersion.WithKind("GCPMachine"))
126123
// Set optional values from machinepool
127124
if mpool.OnHostMaintenance != "" {
128125
gcpMachine.Spec.OnHostMaintenance = ptr.To(capg.HostMaintenancePolicy(mpool.OnHostMaintenance))
@@ -174,12 +171,13 @@ func createCAPIMachine(name string, dataSecret string, infraID string) *capi.Mac
174171
DataSecretName: ptr.To(dataSecret),
175172
},
176173
InfrastructureRef: v1.ObjectReference{
177-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
174+
APIVersion: capg.GroupVersion.String(),
178175
Kind: "GCPMachine",
179176
Name: name,
180177
},
181178
},
182179
}
180+
machine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
183181

184182
return machine
185183
}

pkg/asset/machines/gcp/gcpmachines_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ func getBaseGCPMachine() *capg.GCPMachine {
153153
image := "rhcos-415-92-202311241643-0-gcp-x86-64"
154154
diskType := "pd-ssd"
155155
gcpMachine := &capg.GCPMachine{
156-
TypeMeta: metav1.TypeMeta{
157-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
158-
Kind: "GCPMachine",
159-
},
160156
ObjectMeta: metav1.ObjectMeta{
161157
Name: "012345678-master-0",
162158
Labels: map[string]string{
@@ -178,6 +174,7 @@ func getBaseGCPMachine() *capg.GCPMachine {
178174
},
179175
},
180176
}
177+
gcpMachine.SetGroupVersionKind(capg.GroupVersion.WithKind("GCPMachine"))
181178
return gcpMachine
182179
}
183180

@@ -227,11 +224,12 @@ func getBaseCapiMachine() *capi.Machine {
227224
DataSecretName: ptr.To(dataSecret),
228225
},
229226
InfrastructureRef: v1.ObjectReference{
230-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
227+
APIVersion: capg.GroupVersion.String(),
231228
Kind: "GCPMachine",
232229
Name: "012345678-master-0",
233230
},
234231
},
235232
}
233+
capiMachine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
236234
return capiMachine
237235
}

pkg/asset/machines/openstack/openstackmachines.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func GenerateMachines(clusterID string, config *types.InstallConfig, pool *types
9696
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, role)),
9797
},
9898
InfrastructureRef: v1.ObjectReference{
99-
APIVersion: "infrastructure.cluster.x-k8s.io/v1alpha7",
99+
APIVersion: capo.GroupVersion.String(),
100100
Kind: "OpenStackMachine",
101101
Name: openStackMachine.Name,
102102
},

pkg/asset/machines/powervs/powervsmachines.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ func GenerateMachines(clusterID string, pool *types.MachinePool, role string) ([
3737

3838
for idx := int64(0); idx < total; idx++ {
3939
powervsMachine := &capibm.IBMPowerVSMachine{
40-
TypeMeta: metav1.TypeMeta{
41-
APIVersion: capibm.GroupVersion.String(),
42-
Kind: "IBMPowerVSMachine",
43-
},
4440
ObjectMeta: metav1.ObjectMeta{
4541
Name: fmt.Sprintf("%s-%s-%d", clusterID, pool.Name, idx),
4642
Labels: map[string]string{
@@ -58,17 +54,14 @@ func GenerateMachines(clusterID string, pool *types.MachinePool, role string) ([
5854
MemoryGiB: mpool.MemoryGiB,
5955
},
6056
}
57+
powervsMachine.SetGroupVersionKind(capibm.GroupVersion.WithKind("IBMPowerVSMachine"))
6158

6259
result = append(result, &asset.RuntimeFile{
6360
File: asset.File{Filename: fmt.Sprintf("10_inframachine_%s.yaml", powervsMachine.Name)},
6461
Object: powervsMachine,
6562
})
6663

6764
machine := &capi.Machine{
68-
TypeMeta: metav1.TypeMeta{
69-
Kind: "Machine",
70-
APIVersion: capi.GroupVersion.String(),
71-
},
7265
ObjectMeta: metav1.ObjectMeta{
7366
Name: powervsMachine.Name,
7467
Labels: map[string]string{
@@ -81,12 +74,13 @@ func GenerateMachines(clusterID string, pool *types.MachinePool, role string) ([
8174
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, role)),
8275
},
8376
InfrastructureRef: v1.ObjectReference{
84-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta2",
77+
APIVersion: capibm.GroupVersion.String(),
8578
Kind: "IBMPowerVSMachine",
8679
Name: powervsMachine.Name,
8780
},
8881
},
8982
}
83+
machine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
9084

9185
result = append(result, &asset.RuntimeFile{
9286
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", machine.Name)},

pkg/asset/machines/vsphere/capimachines.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
111111
}
112112

113113
vsphereMachine := &capv.VSphereMachine{
114-
TypeMeta: metav1.TypeMeta{
115-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
116-
Kind: "VSphereMachine",
117-
},
118114
ObjectMeta: metav1.ObjectMeta{
119115
Namespace: capiutils.Namespace,
120116
Name: machine.Name,
@@ -141,6 +137,7 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
141137
},
142138
},
143139
}
140+
vsphereMachine.SetGroupVersionKind(capv.GroupVersion.WithKind("VSphereMachine"))
144141
capvMachines = append(capvMachines, vsphereMachine)
145142

146143
result = append(result, &asset.RuntimeFile{
@@ -162,12 +159,13 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
162159
DataSecretName: ptr.To(fmt.Sprintf("%s-%s", clusterID, role)),
163160
},
164161
InfrastructureRef: v1.ObjectReference{
165-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
162+
APIVersion: capv.GroupVersion.String(),
166163
Kind: "VSphereMachine",
167164
Name: vsphereMachine.Name,
168165
},
169166
},
170167
}
168+
machine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
171169

172170
result = append(result, &asset.RuntimeFile{
173171
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", machine.Name)},
@@ -199,6 +197,7 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
199197
},
200198
Spec: bootstrapSpec,
201199
}
200+
bootstrapVSphereMachine.SetGroupVersionKind(capv.GroupVersion.WithKind("VSphereMachine"))
202201

203202
result = append(result, &asset.RuntimeFile{
204203
File: asset.File{Filename: fmt.Sprintf("10_inframachine_%s.yaml", bootstrapVSphereMachine.Name)},
@@ -218,12 +217,13 @@ func GenerateMachines(ctx context.Context, clusterID string, config *types.Insta
218217
DataSecretName: ptr.To(fmt.Sprintf("%s-bootstrap", clusterID)),
219218
},
220219
InfrastructureRef: v1.ObjectReference{
221-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
220+
APIVersion: capv.GroupVersion.String(),
222221
Kind: "VSphereMachine",
223222
Name: bootstrapVSphereMachine.Name,
224223
},
225224
},
226225
}
226+
bootstrapMachine.SetGroupVersionKind(capi.GroupVersion.WithKind("Machine"))
227227
result = append(result, &asset.RuntimeFile{
228228
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", bootstrapVSphereMachine.Name)},
229229
Object: bootstrapMachine,

pkg/asset/manifests/aws/cluster.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
181181
AdditionalTags: tags,
182182
},
183183
}
184+
awsCluster.SetGroupVersionKind(capa.GroupVersion.WithKind("AWSCluster"))
184185

185186
if installConfig.Config.Publish == types.ExternalPublishingStrategy {
186187
// FIXME: CAPA bug. Remove when fixed upstream
@@ -270,6 +271,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
270271
},
271272
},
272273
}
274+
id.SetGroupVersionKind(capa.GroupVersion.WithKind("AWSClusterControllerIdentity"))
273275
manifests = append(manifests, &asset.RuntimeFile{
274276
Object: id,
275277
File: asset.File{Filename: "01_aws-cluster-controller-identity-default.yaml"},
@@ -278,7 +280,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
278280
return &capiutils.GenerateClusterAssetsOutput{
279281
Manifests: manifests,
280282
InfrastructureRef: &corev1.ObjectReference{
281-
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta2",
283+
APIVersion: capa.GroupVersion.String(),
282284
Kind: "AWSCluster",
283285
Name: awsCluster.Name,
284286
Namespace: awsCluster.Namespace,

0 commit comments

Comments
 (0)