Skip to content

Commit 448366c

Browse files
pranavsriram8l-technicore
authored andcommitted
Implement NSG rule management for CCM loadbalancers and add respective e2e test cases
1 parent bd86c23 commit 448366c

35 files changed

+3774
-186
lines changed

cmd/oci-cloud-controller-manager/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"os"
2222
"time"
2323

24-
"github.com/oracle/oci-cloud-controller-manager/pkg/cloudprovider/providers/oci"
2524
"github.com/oracle/oci-cloud-controller-manager/pkg/logging"
2625
"github.com/spf13/pflag"
2726
"go.uber.org/zap"

hack/existing-standalone-cluster-env-template.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export CMEK_KMS_KEY=""
5050
# Mandatory
5151
export NSG_OCIDS=","
5252

53+
# NSG Network security group created in cluster's VCN for backend management, this NSG will have to be attached to the nodes manually for tests to pass
54+
export BACKEND_NSG_OCIDS=""
55+
5356
# FSS VOLUME HANDLE in the format filesystem_ocid:mountTargetIP:export_path
5457
# Make sure fss volume handle is in the same subnet as your nodes
5558
# Create a file system, file export path and mount target in your VCN by following

hack/run_e2e_test.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ function check-env () {
2121
fi
2222
}
2323

24-
check-env "CLUSTER_KUBECONFIG" $CLUSTER_KUBECONFIG
25-
check-env "CLOUD_CONFIG" $CLOUD_CONFIG
26-
check-env "ADLOCATION" $ADLOCATION
27-
check-env "NSG_OCIDS" $NSG_OCIDS
28-
check-env "FSS_VOLUME_HANDLE" $FSS_VOLUME_HANDLE
24+
check-env "CLUSTER_KUBECONFIG" $CLUSTER_KUBECONFIG
25+
check-env "CLOUD_CONFIG" $CLOUD_CONFIG
26+
check-env "ADLOCATION" $ADLOCATION
27+
check-env "NSG_OCIDS" $NSG_OCIDS
28+
check-env "BACKEND_NSG_OCIDS" $BACKEND_NSG_OCIDS
29+
check-env "FSS_VOLUME_HANDLE" $FSS_VOLUME_HANDLE
2930
check-env "MNT_TARGET_ID" $MNT_TARGET_ID
3031
check-env "MNT_TARGET_SUBNET_ID" $MNT_TARGET_SUBNET_ID
3132
check-env "MNT_TARGET_COMPARTMENT_ID" $MNT_TARGET_COMPARTMENT_ID
@@ -51,6 +52,7 @@ function run_e2e_tests_existing_cluster() {
5152
--mnt-target-subnet-id=${MNT_TARGET_SUBNET_ID} \
5253
--mnt-target-compartment-id=${MNT_TARGET_COMPARTMENT_ID} \
5354
--nsg-ocids=${NSG_OCIDS} \
55+
--backend-nsg-ocids=${BACKEND_NSG_OCIDS} \
5456
--reserved-ip=${RESERVED_IP} \
5557
--architecture=${ARCHITECTURE} \
5658
--volume-handle=${FSS_VOLUME_HANDLE} \

pkg/cloudprovider/providers/oci/instances.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (cp *CloudProvider) getCompartmentIDByInstanceID(instanceID string) (string
5050
return "", errors.Wrap(err, "error listing all the nodes using node informer")
5151
}
5252
for _, node := range nodeList {
53-
providerID, err := MapProviderIDToInstanceID(node.Spec.ProviderID)
53+
providerID, err := MapProviderIDToResourceID(node.Spec.ProviderID)
5454
if err != nil {
5555
return "", errors.New("Failed to map providerID to instanceID")
5656
}
@@ -147,9 +147,9 @@ func (cp *CloudProvider) NodeAddresses(ctx context.Context, name types.NodeName)
147147
func (cp *CloudProvider) NodeAddressesByProviderID(ctx context.Context, providerID string) ([]api.NodeAddress, error) {
148148
cp.logger.With("instanceID", providerID).Debug("Getting node addresses by provider id")
149149

150-
instanceID, err := MapProviderIDToInstanceID(providerID)
150+
instanceID, err := MapProviderIDToResourceID(providerID)
151151
if err != nil {
152-
return nil, errors.Wrap(err, "MapProviderIDToInstanceID")
152+
return nil, errors.Wrap(err, "MapProviderIDToResourceID")
153153
}
154154
return cp.extractNodeAddresses(ctx, instanceID)
155155

@@ -196,9 +196,9 @@ func (cp *CloudProvider) InstanceType(ctx context.Context, name types.NodeName)
196196
func (cp *CloudProvider) InstanceTypeByProviderID(ctx context.Context, providerID string) (string, error) {
197197
cp.logger.With("instanceID", providerID).Debug("Getting instance type by provider id")
198198

199-
instanceID, err := MapProviderIDToInstanceID(providerID)
199+
instanceID, err := MapProviderIDToResourceID(providerID)
200200
if err != nil {
201-
return "", errors.Wrap(err, "MapProviderIDToInstanceID")
201+
return "", errors.Wrap(err, "MapProviderIDToResourceID")
202202
}
203203
item, exists, err := cp.instanceCache.GetByKey(instanceID)
204204
if err != nil {
@@ -237,7 +237,7 @@ func (cp *CloudProvider) CurrentNodeName(ctx context.Context, hostname string) (
237237
func (cp *CloudProvider) InstanceExistsByProviderID(ctx context.Context, providerID string) (bool, error) {
238238
//Please do not try to optimise it by using InstanceCache because we prefer correctness over efficiency here
239239
cp.logger.With("instanceID", providerID).Debug("Checking instance exists by provider id")
240-
instanceID, err := MapProviderIDToInstanceID(providerID)
240+
instanceID, err := MapProviderIDToResourceID(providerID)
241241
if err != nil {
242242
return false, err
243243
}
@@ -256,7 +256,7 @@ func (cp *CloudProvider) InstanceExistsByProviderID(ctx context.Context, provide
256256
func (cp *CloudProvider) InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error) {
257257
//Please do not try to optimise it by using InstanceCache because we prefer correctness over efficiency here
258258
cp.logger.With("instanceID", providerID).Debug("Checking instance is stopped by provider id")
259-
instanceID, err := MapProviderIDToInstanceID(providerID)
259+
instanceID, err := MapProviderIDToResourceID(providerID)
260260
if err != nil {
261261
return false, err
262262
}

pkg/cloudprovider/providers/oci/instances_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ func (MockSecurityListManager) Delete(ctx context.Context, lbSubnets []*core.Sub
278278

279279
type MockSecurityListManagerFactory func(mode string) MockSecurityListManager
280280

281+
type MockNsgManager struct{}
282+
283+
func (MockNsgManager) Add(ctx context.Context, lbService serviceComponents) error {
284+
return nil
285+
}
286+
287+
func (MockNsgManager) Delete(ctx context.Context, lbService serviceComponents) error {
288+
return nil
289+
}
290+
291+
type MockNsgManagerFactory func(mode string) MockNsgManager
292+
281293
type MockOCIClient struct{}
282294

283295
func (MockOCIClient) Compute() client.ComputeInterface {
@@ -401,7 +413,7 @@ func (c *MockVirtualNetworkClient) IsRegionalSubnet(ctx context.Context, id stri
401413
return subnets[id].AvailabilityDomain == nil, nil
402414
}
403415

404-
func (c *MockVirtualNetworkClient) GetPrivateIP(ctx context.Context, id string) (*core.PrivateIp, error) {
416+
func (c *MockVirtualNetworkClient) GetPrivateIp(ctx context.Context, id string) (*core.PrivateIp, error) {
405417
return nil, nil
406418
}
407419

0 commit comments

Comments
 (0)