Skip to content

Commit

Permalink
Fix VPC related issues
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>
  • Loading branch information
Prajyot-Parab committed Apr 8, 2022
1 parent da1fdd6 commit 0144c67
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -295,14 +298,17 @@ 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,
})
options.SetZone(&vpcv1.ZoneIdentity{
Name: &zoneName,
})
options.SetResourceGroup(&vpcv1.ResourceGroupIdentity{
ID: &resourceGroupID,
})
publicGateway, _, err := s.IBMVPCClients.VPCService.CreatePublicGateway(options)
return publicGateway, err
}
Expand Down
3 changes: 3 additions & 0 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
6 changes: 2 additions & 4 deletions controllers/ibmvpccluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controllers

import (
"context"
"os"

"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions controllers/ibmvpcmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"os"

"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0144c67

Please sign in to comment.