github.com/openshift/installer@v1.4.17/pkg/asset/manifests/ibmcloud/cloudproviderconfig_test.go (about)

     1  package ibmcloud
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	configv1 "github.com/openshift/api/config/v1"
     9  )
    10  
    11  func TestCloudProviderConfig(t *testing.T) {
    12  	accountID := "1e1f75646aef447814a6d907cc83fb3c"
    13  	existingSubnets := []string{
    14  		"existing-subnet-control-plane-eu-gb-1",
    15  		"existing-subnet-control-plane-eu-gb-2",
    16  		"existing-subnet-control-plane-eu-gb-3",
    17  		"existing-subnet-compute-eu-gb-1",
    18  		"existing-subnet-compute-eu-gb-2",
    19  		"existing-subnet-compute-eu-gb-3",
    20  	}
    21  	defaultConfig := `[global]
    22  version = 1.1.0
    23  [kubernetes]
    24  config-file = ""
    25  [provider]
    26  accountID = 1e1f75646aef447814a6d907cc83fb3c
    27  clusterID = ocp4-8pxks
    28  cluster-default-provider = g2
    29  region = us-east
    30  g2Credentials = /etc/vpc/ibmcloud_api_key
    31  g2ResourceGroupName = ocp4-8pxks-rg
    32  g2VpcName = ocp4-8pxks-vpc
    33  g2workerServiceAccountID = 1e1f75646aef447814a6d907cc83fb3c
    34  g2VpcSubnetNames = ocp4-8pxks-subnet-compute-us-east-1,ocp4-8pxks-subnet-compute-us-east-2,ocp4-8pxks-subnet-compute-us-east-3,ocp4-8pxks-subnet-control-plane-us-east-1,ocp4-8pxks-subnet-control-plane-us-east-2,ocp4-8pxks-subnet-control-plane-us-east-3
    35  
    36  
    37  `
    38  
    39  	existingSubnetConfig := `[global]
    40  version = 1.1.0
    41  [kubernetes]
    42  config-file = ""
    43  [provider]
    44  accountID = 1e1f75646aef447814a6d907cc83fb3c
    45  clusterID = ocp4-hf4vtt
    46  cluster-default-provider = g2
    47  region = eu-gb
    48  g2Credentials = /etc/vpc/ibmcloud_api_key
    49  g2ResourceGroupName = ocp4-hf4vtt-rg
    50  g2VpcName = ocp4-hf4vtt-vpc
    51  g2workerServiceAccountID = 1e1f75646aef447814a6d907cc83fb3c
    52  g2VpcSubnetNames = existing-subnet-control-plane-eu-gb-1,existing-subnet-control-plane-eu-gb-2,existing-subnet-control-plane-eu-gb-3,existing-subnet-compute-eu-gb-1,existing-subnet-compute-eu-gb-2,existing-subnet-compute-eu-gb-3
    53  
    54  
    55  `
    56  
    57  	singleEndpointOverrideConfig := `[global]
    58  version = 1.1.0
    59  [kubernetes]
    60  config-file = ""
    61  [provider]
    62  accountID = 1e1f75646aef447814a6d907cc83fb3c
    63  clusterID = ocp4-ghs4s3
    64  cluster-default-provider = g2
    65  region = eu-gb
    66  g2Credentials = /etc/vpc/ibmcloud_api_key
    67  g2ResourceGroupName = ocp4-ghs4s3-rg
    68  g2VpcName = ocp4-ghs4s3-vpc
    69  g2workerServiceAccountID = 1e1f75646aef447814a6d907cc83fb3c
    70  g2VpcSubnetNames = existing-subnet-control-plane-eu-gb-1,existing-subnet-control-plane-eu-gb-2,existing-subnet-control-plane-eu-gb-3,existing-subnet-compute-eu-gb-1,existing-subnet-compute-eu-gb-2,existing-subnet-compute-eu-gb-3
    71  g2EndpointOverride = https://ibmcloud.vpc.override.endpoint.test
    72  
    73  
    74  `
    75  
    76  	multiEndpointOverrideConfig := `[global]
    77  version = 1.1.0
    78  [kubernetes]
    79  config-file = ""
    80  [provider]
    81  accountID = 1e1f75646aef447814a6d907cc83fb3c
    82  clusterID = ocp4-ppcj33
    83  cluster-default-provider = g2
    84  region = eu-gb
    85  g2Credentials = /etc/vpc/ibmcloud_api_key
    86  g2ResourceGroupName = ocp4-ppcj33-rg
    87  g2VpcName = ocp4-ppcj33-vpc
    88  g2workerServiceAccountID = 1e1f75646aef447814a6d907cc83fb3c
    89  g2VpcSubnetNames = existing-subnet-control-plane-eu-gb-1,existing-subnet-control-plane-eu-gb-2,existing-subnet-control-plane-eu-gb-3,existing-subnet-compute-eu-gb-1,existing-subnet-compute-eu-gb-2,existing-subnet-compute-eu-gb-3
    90  iamEndpointOverride = https://ibmcloud.iam.override.endpoint.test
    91  g2EndpointOverride = https://ibmcloud.vpc.override.endpoint.test
    92  rmEndpointOverride = https://ibmcloud.resource-manager.override.endpoint.test
    93  
    94  
    95  `
    96  
    97  	eugbZones := []string{"eu-gb-1", "eu-gb-2", "eu-gb-3"}
    98  	useastZones := []string{"us-east-1", "us-east-2", "us-east-3"}
    99  
   100  	cases := []struct {
   101  		name              string
   102  		infraID           string
   103  		accountID         string
   104  		region            string
   105  		resourceGroupName string
   106  		vpcName           string
   107  		subnets           []string
   108  		cpZones           []string
   109  		computeZones      []string
   110  		serviceEndpoints  []configv1.IBMCloudServiceEndpoint
   111  		expectedConfig    string
   112  	}{
   113  		{
   114  			name:              "default subnet config",
   115  			infraID:           "ocp4-8pxks",
   116  			accountID:         accountID,
   117  			region:            "us-east",
   118  			resourceGroupName: "ocp4-8pxks-rg",
   119  			vpcName:           "ocp4-8pxks-vpc",
   120  			subnets:           []string{},
   121  			cpZones:           useastZones,
   122  			computeZones:      useastZones,
   123  			expectedConfig:    defaultConfig,
   124  		},
   125  		{
   126  			name:              "existing subnet config",
   127  			infraID:           "ocp4-hf4vtt",
   128  			accountID:         accountID,
   129  			region:            "eu-gb",
   130  			resourceGroupName: "ocp4-hf4vtt-rg",
   131  			vpcName:           "ocp4-hf4vtt-vpc",
   132  			subnets:           existingSubnets,
   133  			cpZones:           eugbZones,
   134  			computeZones:      eugbZones,
   135  			expectedConfig:    existingSubnetConfig,
   136  		},
   137  		{
   138  			name:              "single endpoint override config",
   139  			infraID:           "ocp4-ghs4s3",
   140  			accountID:         accountID,
   141  			region:            "eu-gb",
   142  			resourceGroupName: "ocp4-ghs4s3-rg",
   143  			vpcName:           "ocp4-ghs4s3-vpc",
   144  			subnets:           existingSubnets,
   145  			cpZones:           eugbZones,
   146  			computeZones:      eugbZones,
   147  			serviceEndpoints: []configv1.IBMCloudServiceEndpoint{
   148  				{
   149  					Name: configv1.IBMCloudServiceVPC,
   150  					URL:  "https://ibmcloud.vpc.override.endpoint.test",
   151  				},
   152  			},
   153  			expectedConfig: singleEndpointOverrideConfig,
   154  		},
   155  		{
   156  			name:              "multiple endpoint override config",
   157  			infraID:           "ocp4-ppcj33",
   158  			accountID:         accountID,
   159  			region:            "eu-gb",
   160  			resourceGroupName: "ocp4-ppcj33-rg",
   161  			vpcName:           "ocp4-ppcj33-vpc",
   162  			subnets:           existingSubnets,
   163  			cpZones:           eugbZones,
   164  			computeZones:      eugbZones,
   165  			serviceEndpoints: []configv1.IBMCloudServiceEndpoint{
   166  				{
   167  					Name: configv1.IBMCloudServiceCOS,
   168  					URL:  "https://ibmcloud.cos.override.endpoint.test",
   169  				},
   170  				{
   171  					Name: configv1.IBMCloudServiceIAM,
   172  					URL:  "https://ibmcloud.iam.override.endpoint.test",
   173  				},
   174  				{
   175  					Name: configv1.IBMCloudServiceVPC,
   176  					URL:  "https://ibmcloud.vpc.override.endpoint.test",
   177  				},
   178  				{
   179  					Name: configv1.IBMCloudServiceResourceManager,
   180  					URL:  "https://ibmcloud.resource-manager.override.endpoint.test",
   181  				},
   182  			},
   183  			expectedConfig: multiEndpointOverrideConfig,
   184  		},
   185  	}
   186  
   187  	for _, tc := range cases {
   188  		t.Run(tc.name, func(t *testing.T) {
   189  			actualConfig, err := CloudProviderConfig(tc.infraID, tc.accountID, tc.region, tc.resourceGroupName, tc.vpcName, tc.subnets, tc.cpZones, tc.computeZones, tc.serviceEndpoints)
   190  			assert.NoError(t, err, "failed to create cloud provider config")
   191  			assert.Equal(t, tc.expectedConfig, actualConfig, "unexpected cloud provider config")
   192  		})
   193  	}
   194  }