Skip to content

Commit 274f8f9

Browse files
committed
Fix test failures
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent 01de3b4 commit 274f8f9

6 files changed

+32
-8
lines changed

api/v1beta2/ibmpowervscluster_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ type IBMPowerVSClusterSpec struct {
4949
// dhcpServer is contains the configuration to be used while creating a new DHCP server in PowerVS workspace.
5050
// when the field is omitted, CLUSTER_NAME will be used as DHCPServer.Name and DHCP server will be created.
5151
// it will automatically create network with name DHCPSERVER<DHCPServer.Name>_Private in PowerVS workspace.
52-
// the default name
5352
// +optional
5453
DHCPServer *DHCPServer `json:"dhcpServer,omitempty"`
5554

cloud/scope/powervs_machine.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func (m *PowerVSMachineScope) createCOSClient() (*cos.Service, error) {
584584

585585
// GetRawBootstrapDataWithFormat returns the bootstrap data if present.
586586
func (m *PowerVSMachineScope) GetRawBootstrapDataWithFormat() ([]byte, string, error) {
587-
if m.Machine.Spec.Bootstrap.DataSecretName == nil {
587+
if m.Machine == nil || m.Machine.Spec.Bootstrap.DataSecretName == nil {
588588
return nil, "", errors.New("error retrieving bootstrap data: linked Machine's bootstrap.dataSecretName is nil")
589589
}
590590

@@ -717,7 +717,7 @@ func (m *PowerVSMachineScope) SetHealth(health *models.PVMInstanceHealth) {
717717
}
718718

719719
// SetAddresses will set the addresses for the machine.
720-
func (m *PowerVSMachineScope) SetAddresses(instance *models.PVMInstance) {
720+
func (m *PowerVSMachineScope) SetAddresses(instance *models.PVMInstance) { //nolint:gocyclo
721721
var addresses []corev1.NodeAddress
722722
// Setting the name of the vm to the InternalDNS and Hostname as the vm uses that as hostname.
723723
addresses = append(addresses, corev1.NodeAddress{
@@ -910,7 +910,7 @@ func (m *PowerVSMachineScope) GetMachineInternalIP() string {
910910
}
911911

912912
// CreateVPCLoadBalancerPoolMember creates a member in load balaner pool.
913-
func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember() (*vpcv1.LoadBalancerPoolMember, error) {
913+
func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember() (*vpcv1.LoadBalancerPoolMember, error) { //nolint:gocyclo
914914
loadBalancers := make([]infrav1beta2.VPCLoadBalancerSpec, 0)
915915
if len(m.IBMPowerVSCluster.Spec.LoadBalancers) == 0 {
916916
loadBalancer := infrav1beta2.VPCLoadBalancerSpec{

config/crd/bases/infrastructure.cluster.x-k8s.io_ibmpowervsclusters.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ spec:
204204
creating a new DHCP server in PowerVS workspace. when the field
205205
is omitted, CLUSTER_NAME will be used as DHCPServer.Name and DHCP
206206
server will be created. it will automatically create network with
207-
name DHCPSERVER<DHCPServer.Name>_Private in PowerVS workspace. the
208-
default name
207+
name DHCPSERVER<DHCPServer.Name>_Private in PowerVS workspace.
209208
properties:
210209
cidr:
211210
description: Optional cidr for DHCP private network

config/crd/bases/infrastructure.cluster.x-k8s.io_ibmpowervsclustertemplates.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ spec:
231231
when the field is omitted, CLUSTER_NAME will be used as
232232
DHCPServer.Name and DHCP server will be created. it will
233233
automatically create network with name DHCPSERVER<DHCPServer.Name>_Private
234-
in PowerVS workspace. the default name
234+
in PowerVS workspace.
235235
properties:
236236
cidr:
237237
description: Optional cidr for DHCP private network

controllers/ibmpowervsmachine_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ func (r *IBMPowerVSMachineReconciler) reconcileDelete(scope *scope.PowerVSMachin
182182
scope.Info("error deleting IBMPowerVSMachine")
183183
return ctrl.Result{}, fmt.Errorf("error deleting IBMPowerVSMachine %v: %w", klog.KObj(scope.IBMPowerVSMachine), err)
184184
}
185-
185+
if err := scope.DeleteMachineIgnition(); err != nil {
186+
scope.Info("error deleting IBMPowerVSMachine ignition")
187+
return ctrl.Result{}, fmt.Errorf("error deleting IBMPowerVSMachine ignition %v: %w", klog.KObj(scope.IBMPowerVSMachine), err)
188+
}
186189
// Remove the cached VM IP
187190
err := scope.DHCPIPCacheStore.Delete(powervs.VMip{Name: scope.IBMPowerVSMachine.Name})
188191
if err != nil {

controllers/ibmpowervsmachine_controller_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,20 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
316316
g := NewWithT(t)
317317
setup(t)
318318
t.Cleanup(teardown)
319+
320+
secret := &corev1.Secret{
321+
ObjectMeta: metav1.ObjectMeta{
322+
Name: "bootsecret",
323+
Namespace: "default",
324+
},
325+
Data: map[string][]byte{
326+
"value": []byte("user data"),
327+
},
328+
}
329+
330+
mockClient := fake.NewClientBuilder().WithObjects([]client.Object{secret}...).Build()
319331
machineScope = &scope.PowerVSMachineScope{
332+
Client: mockClient,
320333
Logger: klogr.New(),
321334
IBMPowerVSClient: mockpowervs,
322335
IBMPowerVSMachine: &infrav1beta2.IBMPowerVSMachine{
@@ -330,6 +343,16 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
330343
},
331344
IBMPowerVSCluster: &infrav1beta2.IBMPowerVSCluster{},
332345
DHCPIPCacheStore: cache.NewTTLStore(powervs.CacheKeyFunc, powervs.CacheTTL),
346+
Machine: &capiv1beta1.Machine{
347+
ObjectMeta: metav1.ObjectMeta{
348+
Namespace: "default",
349+
},
350+
Spec: capiv1beta1.MachineSpec{
351+
Bootstrap: capiv1beta1.Bootstrap{
352+
DataSecretName: pointer.String("bootsecret"),
353+
},
354+
},
355+
},
333356
}
334357
mockpowervs.EXPECT().DeleteInstance(machineScope.IBMPowerVSMachine.Status.InstanceID).Return(nil)
335358
_, err := reconciler.reconcileDelete(machineScope)

0 commit comments

Comments
 (0)