From 0144c6729715393ba413dfb7a72e3592920a6e62 Mon Sep 17 00:00:00 2001 From: Prajyot-Parab Date: Fri, 8 Apr 2022 11:15:13 +0530 Subject: [PATCH] Fix VPC related issues Signed-off-by: Prajyot-Parab --- cloud/scope/cluster.go | 10 ++++++++-- cloud/scope/machine.go | 3 +++ controllers/ibmvpccluster_controller.go | 6 ++---- controllers/ibmvpcmachine_controller.go | 5 ++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index be52150398..e4f0b20351 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -221,10 +221,13 @@ func (s *ClusterScope) CreateSubnet() (*vpcv1.Subnet, error) { Zone: &vpcv1.ZoneIdentity{ Name: &s.IBMVPCCluster.Spec.Zone, }, + ResourceGroup: &vpcv1.ResourceGroupIdentity{ + ID: &s.IBMVPCCluster.Spec.ResourceGroup, + }, }) subnet, _, err := s.IBMVPCClients.VPCService.CreateSubnet(options) if subnet != nil { - pgw, err := s.createPublicGateWay(s.IBMVPCCluster.Status.VPC.ID, s.IBMVPCCluster.Spec.Zone) + pgw, err := s.createPublicGateWay(s.IBMVPCCluster.Status.VPC.ID, s.IBMVPCCluster.Spec.Zone, s.IBMVPCCluster.Spec.ResourceGroup) if err != nil { return subnet, err } @@ -295,7 +298,7 @@ func (s *ClusterScope) DeleteSubnet() error { return err } -func (s *ClusterScope) createPublicGateWay(vpcID string, zoneName string) (*vpcv1.PublicGateway, error) { +func (s *ClusterScope) createPublicGateWay(vpcID string, zoneName string, resourceGroupID string) (*vpcv1.PublicGateway, error) { options := &vpcv1.CreatePublicGatewayOptions{} options.SetVPC(&vpcv1.VPCIdentity{ ID: &vpcID, @@ -303,6 +306,9 @@ func (s *ClusterScope) createPublicGateWay(vpcID string, zoneName string) (*vpcv options.SetZone(&vpcv1.ZoneIdentity{ Name: &zoneName, }) + options.SetResourceGroup(&vpcv1.ResourceGroupIdentity{ + ID: &resourceGroupID, + }) publicGateway, _, err := s.IBMVPCClients.VPCService.CreatePublicGateway(options) return publicGateway, err } diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index b3968ad3b1..ea22aa5f81 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -125,6 +125,9 @@ func (m *MachineScope) CreateMachine() (*vpcv1.Instance, error) { ID: &m.IBMVPCMachine.Spec.PrimaryNetworkInterface.Subnet, }, }, + ResourceGroup: &vpcv1.ResourceGroupIdentity{ + ID: &m.IBMVPCCluster.Spec.ResourceGroup, + }, UserData: &cloudInitData, } diff --git a/controllers/ibmvpccluster_controller.go b/controllers/ibmvpccluster_controller.go index 0081289213..8dbb666f2f 100644 --- a/controllers/ibmvpccluster_controller.go +++ b/controllers/ibmvpccluster_controller.go @@ -18,7 +18,6 @@ package controllers import ( "context" - "os" "github.com/IBM/vpc-go-sdk/vpcv1" "github.com/go-logr/logr" @@ -73,9 +72,8 @@ func (r *IBMVPCClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, nil } - // Create the scope. - // TODO: Will be removed once we find a better way of overriding the service endpoint, generate via spec. - svcEndpoint := os.Getenv("SERVICE_ENDPOINT") + // Create the service endpoint. + svcEndpoint := "https://" + ibmCluster.Spec.Region + ".iaas.cloud.ibm.com/v1" authenticator, err := authenticator.GetAuthenticator() if err != nil { diff --git a/controllers/ibmvpcmachine_controller.go b/controllers/ibmvpcmachine_controller.go index 404f0da5d2..0445aa95bd 100644 --- a/controllers/ibmvpcmachine_controller.go +++ b/controllers/ibmvpcmachine_controller.go @@ -19,7 +19,6 @@ package controllers import ( "context" "fmt" - "os" "github.com/IBM/vpc-go-sdk/vpcv1" "github.com/go-logr/logr" @@ -95,8 +94,8 @@ func (r *IBMVPCMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{}, nil } - // Create the cluster scope. - svcEndpoint := os.Getenv("SERVICE_ENDPOINT") + // Create the service endpoint. + svcEndpoint := "https://" + ibmCluster.Spec.Region + ".iaas.cloud.ibm.com/v1" authenticator, err := authenticator.GetAuthenticator() if err != nil {