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 b847c57
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 21 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
24 changes: 14 additions & 10 deletions cloud/scope/powervs_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"strings"

"github.com/blang/semver/v4"
ignTypes "github.com/coreos/ignition/config/v2_3/types"
ignV3Types "github.com/coreos/ignition/v2/config/v3_4/types"
"github.com/go-logr/logr"

Expand Down Expand Up @@ -63,6 +62,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/resourcecontroller"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/vpc"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/endpoints"
ignV2Types "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/ignition"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/record"
genUtil "sigs.k8s.io/cluster-api-provider-ibmcloud/util"
Expand Down Expand Up @@ -445,13 +445,17 @@ func (m *PowerVSMachineScope) ignitionUserData(userData []byte) ([]byte, error)

switch semver.Major {
case 2:
ignData := &ignTypes.Config{
Ignition: ignTypes.Ignition{
ignData := &ignV2Types.Config{
Ignition: ignV2Types.Ignition{
Version: semver.String(),
Config: ignTypes.IgnitionConfig{
Append: []ignTypes.ConfigReference{
{
Source: objectURL,
Config: ignV2Types.IgnitionConfig{
Replace: &ignV2Types.ConfigReference{
Source: objectURL,
HTTPHeaders: ignV2Types.HTTPHeaders{
{
Name: "Authorization",
Value: token,
},
},
},
},
Expand Down Expand Up @@ -584,7 +588,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 +721,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 +914,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
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/IBM/platform-services-go-sdk v0.59.0
github.com/IBM/vpc-go-sdk v0.48.0
github.com/blang/semver/v4 v4.0.0
github.com/coreos/ignition v0.35.0
github.com/coreos/ignition/v2 v2.17.0
github.com/go-logr/logr v1.3.0
github.com/go-openapi/strfmt v0.22.0
Expand Down Expand Up @@ -64,7 +63,6 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,8 @@ github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb h1:rmqyI19j3Z/74bIR
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb/go.mod h1:rcFZM3uxVvdyNmsAV2jopgPD1cs5SPWJWU5dOz2LUnw=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/ignition v0.35.0 h1:UFodoYq1mOPrbEjtxIsZbThcDyQwAI1owczRDqWmKkQ=
github.com/coreos/ignition v0.35.0/go.mod h1:WJQapxzEn9DE0ryxsGvm8QnBajm/XsS/PkrDqSpz+bA=
github.com/coreos/ignition/v2 v2.17.0 h1:bBqoZ9HYuIq20hbkb1ucypA7tMi9k/iouPnLNFZQXGM=
github.com/coreos/ignition/v2 v2.17.0/go.mod h1:BFL205qhVgftPJ1nej+C/VPrK6Hl3LlZUhqmhV/HUuA=
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 h1:uSmlDgJGbUB0bwQBcZomBTottKwEDF5fF8UjSwKSzWM=
Expand Down
18 changes: 18 additions & 0 deletions pkg/ignition/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package ignition implements ignition code.
package ignition
Loading

0 comments on commit b847c57

Please sign in to comment.