Skip to content

Commit b847c57

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

10 files changed

+391
-21
lines changed

api/v1beta2/ibmpowervscluster_types.go

-1
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

+14-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"strings"
3131

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

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

446446
switch semver.Major {
447447
case 2:
448-
ignData := &ignTypes.Config{
449-
Ignition: ignTypes.Ignition{
448+
ignData := &ignV2Types.Config{
449+
Ignition: ignV2Types.Ignition{
450450
Version: semver.String(),
451-
Config: ignTypes.IgnitionConfig{
452-
Append: []ignTypes.ConfigReference{
453-
{
454-
Source: objectURL,
451+
Config: ignV2Types.IgnitionConfig{
452+
Replace: &ignV2Types.ConfigReference{
453+
Source: objectURL,
454+
HTTPHeaders: ignV2Types.HTTPHeaders{
455+
{
456+
Name: "Authorization",
457+
Value: token,
458+
},
455459
},
456460
},
457461
},
@@ -584,7 +588,7 @@ func (m *PowerVSMachineScope) createCOSClient() (*cos.Service, error) {
584588

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

@@ -717,7 +721,7 @@ func (m *PowerVSMachineScope) SetHealth(health *models.PVMInstanceHealth) {
717721
}
718722

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

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

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

+1-2
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

+1-1
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

+4-1
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

+23
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)

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require (
1717
github.com/IBM/platform-services-go-sdk v0.59.0
1818
github.com/IBM/vpc-go-sdk v0.48.0
1919
github.com/blang/semver/v4 v4.0.0
20-
github.com/coreos/ignition v0.35.0
2120
github.com/coreos/ignition/v2 v2.17.0
2221
github.com/go-logr/logr v1.3.0
2322
github.com/go-openapi/strfmt v0.22.0
@@ -64,7 +63,6 @@ require (
6463
github.com/cespare/xxhash/v2 v2.2.0 // indirect
6564
github.com/cloudflare/circl v1.3.7 // indirect
6665
github.com/coreos/go-semver v0.3.1 // indirect
67-
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
6866
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
6967
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 // indirect
7068
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect

go.sum

-4
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,8 @@ github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb h1:rmqyI19j3Z/74bIR
117117
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb/go.mod h1:rcFZM3uxVvdyNmsAV2jopgPD1cs5SPWJWU5dOz2LUnw=
118118
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
119119
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
120-
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
121-
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
122120
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
123121
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
124-
github.com/coreos/ignition v0.35.0 h1:UFodoYq1mOPrbEjtxIsZbThcDyQwAI1owczRDqWmKkQ=
125-
github.com/coreos/ignition v0.35.0/go.mod h1:WJQapxzEn9DE0ryxsGvm8QnBajm/XsS/PkrDqSpz+bA=
126122
github.com/coreos/ignition/v2 v2.17.0 h1:bBqoZ9HYuIq20hbkb1ucypA7tMi9k/iouPnLNFZQXGM=
127123
github.com/coreos/ignition/v2 v2.17.0/go.mod h1:BFL205qhVgftPJ1nej+C/VPrK6Hl3LlZUhqmhV/HUuA=
128124
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 h1:uSmlDgJGbUB0bwQBcZomBTottKwEDF5fF8UjSwKSzWM=

pkg/ignition/doc.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package ignition implements ignition code.
18+
package ignition

0 commit comments

Comments
 (0)