Skip to content

Commit 4de83a5

Browse files
authored
Use ignition only when Ignition is set in IBMPowerVSCluster (#2037)
1 parent 7fcd3c3 commit 4de83a5

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

cloud/scope/powervs_machine.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func NewPowerVSMachineScope(params PowerVSMachineScopeParams) (scope *PowerVSMac
131131
scope.IBMPowerVSMachine = params.IBMPowerVSMachine
132132
scope.IBMPowerVSCluster = params.IBMPowerVSCluster
133133
scope.IBMPowerVSImage = params.IBMPowerVSImage
134+
scope.ServiceEndpoint = params.ServiceEndpoint
134135

135136
if params.Logger == (logr.Logger{}) {
136137
params.Logger = klog.Background()
@@ -168,6 +169,7 @@ func NewPowerVSMachineScope(params PowerVSMachineScopeParams) (scope *PowerVSMac
168169
}
169170
scope.Logger.V(3).Info("Overriding the default resource controller endpoint")
170171
}
172+
scope.ResourceClient = rc
171173

172174
var serviceInstanceID, serviceInstanceName string
173175
if params.IBMPowerVSMachine.Spec.ServiceInstanceID != "" {
@@ -221,10 +223,6 @@ func NewPowerVSMachineScope(params PowerVSMachineScopeParams) (scope *PowerVSMac
221223
scope.IBMPowerVSClient = c
222224
scope.DHCPIPCacheStore = params.DHCPIPCacheStore
223225

224-
if !CheckCreateInfraAnnotation(*params.IBMPowerVSCluster) {
225-
return scope, nil
226-
}
227-
228226
var vpcRegion string
229227
if params.IBMPowerVSCluster.Spec.VPC == nil || params.IBMPowerVSCluster.Spec.VPC.Region == nil {
230228
vpcRegion, err = regionUtil.VPCRegionForPowerVSRegion(scope.GetRegion())
@@ -239,10 +237,7 @@ func NewPowerVSMachineScope(params PowerVSMachineScopeParams) (scope *PowerVSMac
239237
if err != nil {
240238
return nil, fmt.Errorf("failed to create IBM VPC client: %w", err)
241239
}
242-
243240
scope.IBMVPCClient = vpcClient
244-
scope.ResourceClient = rc
245-
scope.ServiceEndpoint = params.ServiceEndpoint
246241
return scope, nil
247242
}
248243

@@ -354,11 +349,11 @@ func (m *PowerVSMachineScope) CreateMachine() (*models.PVMInstanceReference, err
354349
}
355350

356351
func (m *PowerVSMachineScope) resolveUserData() (string, error) {
357-
userData, userDataFormat, err := m.GetRawBootstrapDataWithFormat()
352+
userData, err := m.GetRawBootstrapData()
358353
if err != nil {
359354
return "", err
360355
}
361-
if m.UseIgnition(userDataFormat) {
356+
if m.UseIgnition() {
362357
data, err := m.ignitionUserData(userData)
363358
if err != nil {
364359
return "", err
@@ -512,9 +507,9 @@ func (m *PowerVSMachineScope) ignitionUserData(userData []byte) ([]byte, error)
512507
}
513508
}
514509

515-
// UseIgnition returns true if user data format is of type 'ignition', else returns false.
516-
func (m *PowerVSMachineScope) UseIgnition(userDataFormat string) bool {
517-
return userDataFormat == "ignition" || (m.IBMPowerVSCluster.Spec.Ignition != nil)
510+
// UseIgnition returns true if Ignition is set in IBMPowerVSCluster.
511+
func (m *PowerVSMachineScope) UseIgnition() bool {
512+
return m.IBMPowerVSCluster.Spec.Ignition != nil
518513
}
519514

520515
// Close closes the current scope persisting the cluster configuration and status.
@@ -539,11 +534,11 @@ func (m *PowerVSMachineScope) DeleteMachine() error {
539534

540535
// DeleteMachineIgnition deletes the ignition associated with machine.
541536
func (m *PowerVSMachineScope) DeleteMachineIgnition() error {
542-
_, userDataFormat, err := m.GetRawBootstrapDataWithFormat()
537+
_, err := m.GetRawBootstrapData()
543538
if err != nil {
544539
return err
545540
}
546-
if !m.UseIgnition(userDataFormat) {
541+
if !m.UseIgnition() {
547542
m.V(3).Info("Machine is not using user data of type ignition")
548543
return nil
549544
}
@@ -632,24 +627,24 @@ func (m *PowerVSMachineScope) createCOSClient() (*cos.Service, error) {
632627
return cosClient, nil
633628
}
634629

635-
// GetRawBootstrapDataWithFormat returns the bootstrap data if present.
636-
func (m *PowerVSMachineScope) GetRawBootstrapDataWithFormat() ([]byte, string, error) {
630+
// GetRawBootstrapData returns the bootstrap data if present.
631+
func (m *PowerVSMachineScope) GetRawBootstrapData() ([]byte, error) {
637632
if m.Machine == nil || m.Machine.Spec.Bootstrap.DataSecretName == nil {
638-
return nil, "", errors.New("failed to retrieve bootstrap data: linked Machine's bootstrap.dataSecretName is nil")
633+
return nil, errors.New("failed to retrieve bootstrap data: linked Machine's bootstrap.dataSecretName is nil")
639634
}
640635

641636
secret := &corev1.Secret{}
642637
key := types.NamespacedName{Namespace: m.Machine.Namespace, Name: *m.Machine.Spec.Bootstrap.DataSecretName}
643638
if err := m.Client.Get(context.TODO(), key, secret); err != nil {
644-
return nil, "", fmt.Errorf("failed to retrieve bootstrap data secret for IBMPowerVSMachine %s/%s: %w", m.Machine.Namespace, m.Machine.Name, err)
639+
return nil, fmt.Errorf("failed to retrieve bootstrap data secret for IBMPowerVSMachine %s/%s: %w", m.Machine.Namespace, m.Machine.Name, err)
645640
}
646641

647642
value, ok := secret.Data["value"]
648643
if !ok {
649-
return nil, "", errors.New("failed to retrieve bootstrap data: secret value key is missing")
644+
return nil, errors.New("failed to retrieve bootstrap data: secret value key is missing")
650645
}
651646

652-
return value, string(secret.Data["format"]), nil
647+
return value, nil
653648
}
654649

655650
func getImageID(image *infrav1beta2.IBMPowerVSResourceReference, m *PowerVSMachineScope) (*string, error) {

controllers/ibmpowervsmachine_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,11 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(machineScope *scope.PowerV
289289
return ctrl.Result{RequeueAfter: 2 * time.Minute}, nil
290290
}
291291

292-
if !scope.CheckCreateInfraAnnotation(*machineScope.IBMPowerVSCluster) {
292+
if machineScope.IBMPowerVSCluster.Spec.VPC == nil || machineScope.IBMPowerVSCluster.Spec.VPC.Region == nil {
293+
machineScope.Info("Skipping configuring machine to loadbalancer as VPC is not set")
293294
return ctrl.Result{}, nil
294295
}
296+
295297
// Register instance with load balancer
296298
machineScope.Info("updating loadbalancer for machine", "name", machineScope.IBMPowerVSMachine.Name)
297299
internalIP := machineScope.GetMachineInternalIP()

controllers/ibmpowervsmachine_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {
512512
},
513513
},
514514
Spec: infrav1beta2.IBMPowerVSClusterSpec{
515+
VPC: &infrav1beta2.VPCResourceReference{
516+
Region: ptr.To("us-south"),
517+
},
515518
LoadBalancers: []infrav1beta2.VPCLoadBalancerSpec{
516519
{
517520
Name: "capi-test-lb",
@@ -603,6 +606,9 @@ func TestIBMPowerVSMachineReconciler_ReconcileOperations(t *testing.T) {
603606
},
604607
},
605608
Spec: infrav1beta2.IBMPowerVSClusterSpec{
609+
VPC: &infrav1beta2.VPCResourceReference{
610+
Region: ptr.To("us-south"),
611+
},
606612
LoadBalancers: []infrav1beta2.VPCLoadBalancerSpec{
607613
{
608614
Name: "capi-test-lb",

0 commit comments

Comments
 (0)