Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <prajyot.parab2@ibm.com>
  • Loading branch information
Karthik-K-N committed Feb 29, 2024
1 parent 01de3b4 commit 274f8f9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
1 change: 0 additions & 1 deletion api/v1beta2/ibmpowervscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type IBMPowerVSClusterSpec struct {
// dhcpServer is contains the configuration to be used while creating a new DHCP server in PowerVS workspace.
// when the field is omitted, CLUSTER_NAME will be used as DHCPServer.Name and DHCP server will be created.
// it will automatically create network with name DHCPSERVER<DHCPServer.Name>_Private in PowerVS workspace.
// the default name
// +optional
DHCPServer *DHCPServer `json:"dhcpServer,omitempty"`

Expand Down
6 changes: 3 additions & 3 deletions cloud/scope/powervs_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func (m *PowerVSMachineScope) createCOSClient() (*cos.Service, error) {

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

Expand Down Expand Up @@ -717,7 +717,7 @@ func (m *PowerVSMachineScope) SetHealth(health *models.PVMInstanceHealth) {
}

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

// CreateVPCLoadBalancerPoolMember creates a member in load balaner pool.
func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember() (*vpcv1.LoadBalancerPoolMember, error) {
func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember() (*vpcv1.LoadBalancerPoolMember, error) { //nolint:gocyclo
loadBalancers := make([]infrav1beta2.VPCLoadBalancerSpec, 0)
if len(m.IBMPowerVSCluster.Spec.LoadBalancers) == 0 {
loadBalancer := infrav1beta2.VPCLoadBalancerSpec{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ spec:
creating a new DHCP server in PowerVS workspace. when the field
is omitted, CLUSTER_NAME will be used as DHCPServer.Name and DHCP
server will be created. it will automatically create network with
name DHCPSERVER<DHCPServer.Name>_Private in PowerVS workspace. the
default name
name DHCPSERVER<DHCPServer.Name>_Private in PowerVS workspace.
properties:
cidr:
description: Optional cidr for DHCP private network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ spec:
when the field is omitted, CLUSTER_NAME will be used as
DHCPServer.Name and DHCP server will be created. it will
automatically create network with name DHCPSERVER<DHCPServer.Name>_Private
in PowerVS workspace. the default name
in PowerVS workspace.
properties:
cidr:
description: Optional cidr for DHCP private network
Expand Down
5 changes: 4 additions & 1 deletion controllers/ibmpowervsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ func (r *IBMPowerVSMachineReconciler) reconcileDelete(scope *scope.PowerVSMachin
scope.Info("error deleting IBMPowerVSMachine")
return ctrl.Result{}, fmt.Errorf("error deleting IBMPowerVSMachine %v: %w", klog.KObj(scope.IBMPowerVSMachine), err)
}

if err := scope.DeleteMachineIgnition(); err != nil {
scope.Info("error deleting IBMPowerVSMachine ignition")
return ctrl.Result{}, fmt.Errorf("error deleting IBMPowerVSMachine ignition %v: %w", klog.KObj(scope.IBMPowerVSMachine), err)
}
// Remove the cached VM IP
err := scope.DHCPIPCacheStore.Delete(powervs.VMip{Name: scope.IBMPowerVSMachine.Name})
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions controllers/ibmpowervsmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,20 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
g := NewWithT(t)
setup(t)
t.Cleanup(teardown)

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "bootsecret",
Namespace: "default",
},
Data: map[string][]byte{
"value": []byte("user data"),
},
}

mockClient := fake.NewClientBuilder().WithObjects([]client.Object{secret}...).Build()
machineScope = &scope.PowerVSMachineScope{
Client: mockClient,
Logger: klogr.New(),
IBMPowerVSClient: mockpowervs,
IBMPowerVSMachine: &infrav1beta2.IBMPowerVSMachine{
Expand All @@ -330,6 +343,16 @@ func TestIBMPowerVSMachineReconciler_Delete(t *testing.T) {
},
IBMPowerVSCluster: &infrav1beta2.IBMPowerVSCluster{},
DHCPIPCacheStore: cache.NewTTLStore(powervs.CacheKeyFunc, powervs.CacheTTL),
Machine: &capiv1beta1.Machine{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
},
Spec: capiv1beta1.MachineSpec{
Bootstrap: capiv1beta1.Bootstrap{
DataSecretName: pointer.String("bootsecret"),
},
},
},
}
mockpowervs.EXPECT().DeleteInstance(machineScope.IBMPowerVSMachine.Status.InstanceID).Return(nil)
_, err := reconciler.reconcileDelete(machineScope)
Expand Down

0 comments on commit 274f8f9

Please sign in to comment.