Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor jwt parser code and add uts for setProviderID #2144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

infrav1beta2 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/globaltagging"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/vpc"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/endpoints"
Expand Down Expand Up @@ -1074,10 +1075,10 @@ func (m *MachineScope) SetNotReady() {
}

// SetProviderID will set the provider id for the machine.
func (m *MachineScope) SetProviderID(id *string) error {
func (m *MachineScope) SetProviderID(id *string, jwtParser parser.TokenParser) error {
// Based on the ProviderIDFormat version the providerID format will be decided.
if options.ProviderIDFormatType(options.ProviderIDFormat) == options.ProviderIDFormatV2 {
accountID, err := utils.GetAccountID()
accountID, err := utils.GetAccountID(jwtParser)
if err != nil {
m.Logger.Error(err, "failed to get cloud account id", err.Error())
return err
Expand Down
67 changes: 67 additions & 0 deletions cloud/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,29 @@ package scope
import (
"context"
"errors"
"fmt"
"os"
"testing"

"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/golang-jwt/jwt"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

infrav1beta2 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
mockParser "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser/mock"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/vpc/mock"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/options"

. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -1059,3 +1065,64 @@ func TestDeleteVPCLoadBalancerPoolMember(t *testing.T) {
})
})
}

func TestSetProviderID_Machine(t *testing.T) {
setup := func(t *testing.T) (*gomock.Controller, *mockParser.MockTokenParser, *mock.MockVpc) {
t.Helper()
return gomock.NewController(t), mockParser.NewMockTokenParser(gomock.NewController(t)), mock.NewMockVpc(gomock.NewController(t))
}

t.Run("Set Provider ID in v1 format", func(t *testing.T) {
g := NewWithT(t)
mockController, mockparser, mockvpc := setup(t)
t.Cleanup(mockController.Finish)
scope := setupMachineScope(clusterName, machineName, mockvpc)
err := scope.SetProviderID(ptr.To("foo-providerID"), mockparser)
expectedProviderID := ptr.To(fmt.Sprintf("ibmvpc://%s/%s", scope.Machine.Spec.ClusterName, scope.IBMVPCMachine.Name))
g.Expect(*scope.IBMVPCMachine.Spec.ProviderID).To(Equal(*expectedProviderID))
g.Expect(err).To(BeNil())
})
t.Run("Set Provider ID in v2 format, returns error", func(t *testing.T) {
g := NewWithT(t)
mockController, mockparser, mockvpc := setup(t)
t.Cleanup(mockController.Finish)
err := os.Setenv("IBMCLOUD", "IBMCLOUD")
g.Expect(err).To(BeNil())
err = os.Setenv("IBMCLOUD_AUTH_TYPE", "bearerToken")
g.Expect(err).To(BeNil())
err = os.Setenv("IBMCLOUD_BEARER_TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.1DhH-W1bP_u1mEU8UXYQkh6XP1P0TNILV5TVSbWlk74")
g.Expect(err).To(BeNil())
defer os.Unsetenv("IBMCLOUD")
defer os.Unsetenv("IBMCLOUD_AUTH_TYPE")
defer os.Unsetenv("IBMCLOUD_BEARER_TOKEN")
mockparser.EXPECT().Parse(gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("parse error"))
scope := setupMachineScope(clusterName, machineName, mockvpc)
options.ProviderIDFormat = string(options.ProviderIDFormatV2)
err = scope.SetProviderID(ptr.To("foo-providerID"), mockparser)
g.Expect(err).NotTo(BeNil())
})

t.Run("Set Provider ID in v2 format", func(t *testing.T) {
g := NewWithT(t)
mockController, mockparser, mockvpc := setup(t)
t.Cleanup(mockController.Finish)
err := os.Setenv("IBMCLOUD", "IBMCLOUD")
g.Expect(err).To(BeNil())
err = os.Setenv("IBMCLOUD_AUTH_TYPE", "bearerToken")
g.Expect(err).To(BeNil())
err = os.Setenv("IBMCLOUD_BEARER_TOKEN", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.1DhH-W1bP_u1mEU8UXYQkh6XP1P0TNILV5TVSbWlk74")
g.Expect(err).To(BeNil())
defer os.Unsetenv("IBMCLOUD")
defer os.Unsetenv("IBMCLOUD_AUTH_TYPE")
defer os.Unsetenv("IBMCLOUD_BEARER_TOKEN")
mp := make(map[string]interface{})
mp["bss"] = "accountID"
mockparser.EXPECT().Parse(gomock.Any(), gomock.Any()).Return(&jwt.Token{Claims: jwt.MapClaims{"account": mp}}, nil)
scope := setupMachineScope(clusterName, machineName, mockvpc)
options.ProviderIDFormat = string(options.ProviderIDFormatV2)
err = scope.SetProviderID(ptr.To("foo-providerID"), mockparser)
expectedProviderID := ptr.To(fmt.Sprintf("ibm://%s///%s/%s", "accountID", scope.Machine.Spec.ClusterName, "foo-providerID"))
g.Expect(*scope.IBMVPCMachine.Spec.ProviderID).To(Equal(*expectedProviderID))
g.Expect(err).To(BeNil())
})
}
3 changes: 2 additions & 1 deletion cloud/scope/powervs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
infrav1beta2 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/authenticator"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/cos"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/resourcecontroller"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/resourcemanager"
Expand Down Expand Up @@ -2398,7 +2399,7 @@ func (s *PowerVSClusterScope) fetchResourceGroupID() (string, error) {
return "", err
}

account, err := utils.GetAccount(auth)
account, err := utils.GetAccount(auth, parser.NewJWTService())
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/image/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -107,7 +108,7 @@ func importimage(ctx context.Context, imageImportOption imageImportOptions) erro
log := logf.Log
log.Info("Importing PowerVS images: ", "service-instance-id", options.GlobalOptions.ServiceInstanceID)

accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/image/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
pkgUtils "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand All @@ -57,7 +58,7 @@ func listimage(ctx context.Context) error {
log := logf.Log
log.Info("Listing PowerVS images", "service-instance-id", options.GlobalOptions.ServiceInstanceID)

accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth())
accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/key/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -89,7 +90,7 @@ func createSSHKey(ctx context.Context, keyCreateOption keyCreateOptions) error {
logger := log.Log
logger.Info("Creating SSH key...")

accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/key/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -56,7 +57,7 @@ func deleteSSHKey(ctx context.Context, keyName string) error {
logger := log.Log
logger.Info("Deleting SSH key...")

accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/key/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand All @@ -56,7 +57,7 @@ func listSSHKeys(ctx context.Context) error {
log := logf.Log
log.Info("Listing PowerVS SSH Keys", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone)

accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -84,7 +85,7 @@ func createNetwork(ctx context.Context, netCreateOption networkCreateOptions) er
log := logf.Log
log.Info("Creating PowerVS network", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone)

accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/network/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -56,7 +57,7 @@ func deleteNetwork(ctx context.Context, networkID string) error {
log := logf.Log
log.Info("Deleting PowerVS network", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone)

accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/network/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand All @@ -56,7 +57,7 @@ func listNetwork(ctx context.Context) error {
log := logf.Log
log.Info("Listing PowerVS networks", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone)

accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/port/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
pkgUtils "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ capibmadm powervs port create --network <netword-id/network-name> --description
func createPort(ctx context.Context, portCreateOption portCreateOptions) error {
logger := log.Log
logger.Info("Creating Port ", "Network ID/Name", portCreateOption.network, "IP Address", portCreateOption.ipAddress, "Description", portCreateOption.description, "service-instance-id", options.GlobalOptions.ServiceInstanceID, "zone", options.GlobalOptions.PowerVSZone)
accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth())
accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/port/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/iam"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/powervs"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -62,7 +63,7 @@ capibmadm powervs port delete --port-id <port-id> --network <network-name/networ
func deletePort(ctx context.Context, portDeleteOption portDeleteOptions) error {
log := logf.Log
log.Info("Deleting PowerVS network port", "network", portDeleteOption.network, "service-instance-id", options.GlobalOptions.ServiceInstanceID, "port-id", portDeleteOption.portID)
accountID, err := utils.GetAccount(iam.GetIAMAuth())
accountID, err := utils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/powervs/port/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
pkgUtils "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ func listPorts(ctx context.Context, network string) error {
log := logf.Log
log.Info("Listing PowerVS ports", "service-instance-id", options.GlobalOptions.ServiceInstanceID, "network", network)

accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth())
accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/vpc/image/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/printer"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
pkgUtils "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -59,7 +60,7 @@ func listImages(ctx context.Context, resourceGroupName string) error {
return err
}

accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth())
accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/capibmadm/cmd/vpc/key/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/clients/vpc"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/options"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cmd/capibmadm/utils"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
pkgUtils "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/utils"
)

Expand Down Expand Up @@ -93,7 +94,7 @@ func createKey(ctx context.Context, keyCreateOption keyCreateOptions) error {
return err
}

accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth())
accountID, err := pkgUtils.GetAccount(iam.GetIAMAuth(), parser.NewJWTService())
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions controllers/ibmvpcmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

infrav1beta2 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
"sigs.k8s.io/cluster-api-provider-ibmcloud/cloud/scope"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/cloud/services/parser"
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/endpoints"
capibmrecord "sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/record"
)
Expand Down Expand Up @@ -162,6 +163,7 @@ func (r *IBMVPCMachineReconciler) reconcileNormal(machineScope *scope.MachineSco
return ctrl.Result{}, fmt.Errorf("failed to reconcile VSI for IBMVPCMachine %s/%s: %w", machineScope.IBMVPCMachine.Namespace, machineScope.IBMVPCMachine.Name, err)
}

jwtParser := parser.NewJWTService()
machineRunning := false
if instance != nil {
// Attempt to tag the Instance.
Expand All @@ -171,7 +173,7 @@ func (r *IBMVPCMachineReconciler) reconcileNormal(machineScope *scope.MachineSco

// Set available status' for Machine.
machineScope.SetInstanceID(*instance.ID)
if err := machineScope.SetProviderID(instance.ID); err != nil {
if err := machineScope.SetProviderID(instance.ID, jwtParser); err != nil {
return ctrl.Result{}, fmt.Errorf("error failed to set machine provider id: %w", err)
}
machineScope.SetAddresses(instance)
Expand Down Expand Up @@ -236,7 +238,7 @@ func (r *IBMVPCMachineReconciler) reconcileNormal(machineScope *scope.MachineSco
} else {
// Otherwise, default to previous Load Balancer Pool Member configuration.
_, ok := machineScope.IBMVPCMachine.Labels[capiv1beta1.MachineControlPlaneNameLabel]
if err = machineScope.SetProviderID(instance.ID); err != nil {
if err = machineScope.SetProviderID(instance.ID, jwtParser); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to set provider id IBMVPCMachine %s/%s: %w", machineScope.IBMVPCMachine.Namespace, machineScope.IBMVPCMachine.Name, err)
}
if ok {
Expand Down
Loading