Skip to content

Commit

Permalink
implement multi region support for cpa
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Liu <alliu@vmware.com>
  • Loading branch information
shenmo3 committed Aug 7, 2023
1 parent 67966f0 commit 531e968
Show file tree
Hide file tree
Showing 38 changed files with 818 additions and 352 deletions.
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ go 1.19

require (
antrea.io/antrea v1.12.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.6.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.1.0
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/aws/aws-sdk-go v1.44.201
github.com/cenkalti/backoff/v4 v4.1.3
Expand All @@ -32,9 +33,9 @@ require (
)

require (
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -55,7 +56,7 @@ require (
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.12.6 // indirect
Expand All @@ -77,7 +78,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
Expand Down
27 changes: 15 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0 h1:sVPhtT2qjO86rTUaWMr4WoES4TkjGnzcioXcnHV9s5k=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1 h1:T8quHYlUGyb/oqtSTwqlCr1ilJHrDv+ZtpSfo+hm1BU=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1/go.mod h1:gLa1CL2RNE4s7M3yopJ/p0iq5DdY6Yv5ZUt9MTRZOQM=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 h1:jp0dGvZ7ZK0mgqnTSClMxa5xuRL7NZgHameVYF6BurY=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 h1:uqM+VoHjVH6zdlkLF2b6O0ZANcHoj3rO0PoQ3jglUJA=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0 h1:/Di3vB4sNeQ+7A8efjUVENvyB945Wruvstucqp7ZArg=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0/go.mod h1:gM3K25LQlsET3QR+4V74zxCsFAy0r6xMNN9n80SZn+4=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.0.0 h1:lMW1lD/17LUA5z1XTURo7LcVG2ICBPlyMHjIUrcFZNQ=
Expand All @@ -50,12 +50,14 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0/
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.6.0 h1:ofIfA+/dTgrqhykfrz+GbFtPAtE697LAOCSw/8AQbwI=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.6.0/go.mod h1:KKrvyReEXgIA2D4ez2Jq5dRynJW4bOjRDkONdze2qjs=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.1.0 h1:pYhaMoTHP/zYIJGDA1sWsfyTDjdglaoYjIFMOEcL+/U=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.1.0/go.mod h1:iLq8GwpQhj09gpI4EdELwifR9kHrb/Q0LThq6iQq9yY=
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest/autorest/to v0.4.0 h1:oXVqrxakqqV1UZdSazDOPOLvOIz+XA683u8EctwboHk=
github.com/Azure/go-autorest/autorest/to v0.4.0/go.mod h1:fE8iZBn7LQR7zH/9XU2NcPR4o9jEImooCeWJcYV/zLE=
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 h1:oPdPEZFSbl7oSPEAIPMPBMUmiL+mqgzBJwM/9qYcwNg=
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1/go.mod h1:4qFor3D/HDsvBME35Xy9rwW9DecL+M2sNw1ybjPtwA0=
github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU=
github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
Expand Down Expand Up @@ -163,8 +165,8 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs=
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE=
Expand Down Expand Up @@ -314,8 +316,8 @@ github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU=
github.com/onsi/gomega v1.27.7/go.mod h1:1p8OOlwo2iUUDsHnOrjE5UKYJ+e3W8eQ3qSlRahPmr4=
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI=
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -571,6 +573,7 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
2 changes: 1 addition & 1 deletion pkg/accountmanager/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (p *accountPoller) doAccountPolling() {
p.updateAccountStatus(p.cloudInterface)
}()

cloudInventory, err := p.cloudInterface.GetCloudInventory(p.accountNamespacedName)
cloudInventory, err := p.cloudInterface.GetAccountCloudInventory(p.accountNamespacedName)
if err != nil {
p.log.Error(err, "failed to fetch cloud inventory from internal snapshot", "account",
p.accountNamespacedName)
Expand Down
10 changes: 5 additions & 5 deletions pkg/accountmanager/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,21 @@ var _ = Describe("Account Poller", func() {
CloudProviderAccountStatus{}, nil).AnyTimes()

// Invalid VPC.
mockCloudInterface.EXPECT().GetCloudInventory(&testAccountNamespacedName).Return(nil,
mockCloudInterface.EXPECT().GetAccountCloudInventory(&testAccountNamespacedName).Return(nil,
fmt.Errorf("error")).Times(1)
accountPollerObj.doAccountPolling()
Expect(len(accountPollerObj.inventory.GetAllVpcs())).To(Equal(0))

// Empty VPC.
cloudInventory := nephetypes.CloudInventory{}
mockCloudInterface.EXPECT().GetCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
mockCloudInterface.EXPECT().GetAccountCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
nil).Times(1)
accountPollerObj.doAccountPolling()
Expect(len(accountPollerObj.inventory.GetAllVpcs())).To(Equal(0))

// Valid VPC.
cloudInventory = nephetypes.CloudInventory{VpcMap: vpcList}
mockCloudInterface.EXPECT().GetCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
mockCloudInterface.EXPECT().GetAccountCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
nil).Times(1)
accountPollerObj.doAccountPolling()
Expect(len(accountPollerObj.inventory.GetAllVpcs())).To(Equal(len(vpcList)))
Expand All @@ -253,7 +253,7 @@ var _ = Describe("Account Poller", func() {

cloudInventory = nephetypes.CloudInventory{VpcMap: vpcList}
// Invalid VMs.
mockCloudInterface.EXPECT().GetCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
mockCloudInterface.EXPECT().GetAccountCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
nil).Times(1)
accountPollerObj.doAccountPolling()
Expect(len(accountPollerObj.inventory.GetAllVms())).To(Equal(0))
Expand All @@ -262,7 +262,7 @@ var _ = Describe("Account Poller", func() {
vmMap := make(map[types.NamespacedName]map[string]*runtimev1alpha1.VirtualMachine)
vmMap[testCesNamespacedName] = vmList
cloudInventory = nephetypes.CloudInventory{VpcMap: vpcList, VmMap: vmMap}
mockCloudInterface.EXPECT().GetCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
mockCloudInterface.EXPECT().GetAccountCloudInventory(&testAccountNamespacedName).Return(&cloudInventory,
nil).Times(1)
accountPollerObj.doAccountPolling()
Expect(len(accountPollerObj.inventory.GetAllVms())).To(Equal(len(vmList)))
Expand Down
28 changes: 17 additions & 11 deletions pkg/apiserver/webhook/cloudprovideraccount_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

const MinPollInterval = 30

var (
const (
errorMsgSecretNotConfigured = "unable to get secret"
errorMsgMinPollInterval = "pollIntervalInSeconds should be >= 30. If not specified, defaults to 60"
errorMsgMissingCredential = "must specify either credentials or role arn, cannot both be empty"
Expand Down Expand Up @@ -247,20 +247,22 @@ func (v *CPAValidator) validateAWSAccount(account *crdv1alpha1.CloudProviderAcco
return fmt.Errorf(errorMsgMissingCredential)
}

if len(awsConfig.Region) == 0 || len(strings.TrimSpace(awsConfig.Region[0])) == 0 {
if len(awsConfig.Region) == 0 {
return fmt.Errorf(errorMsgMissingRegion)
}

// NOTE: currently only AWS standard partition regions supported (aws-cn, aws-us-gov etc are not
// supported). As we add support for other partitions, validation needs to be updated.
regions := endpoints.AwsPartition().Regions()
_, found := regions[awsConfig.Region[0]]
if !found {
var supportedRegions []string
for key := range regions {
supportedRegions = append(supportedRegions, key)
awsRegionMap := endpoints.AwsPartition().Regions()
awsRegionMap["all"] = endpoints.Region{}
for _, region := range awsConfig.Region {
if _, found := awsRegionMap[strings.ToLower(region)]; !found {
var supportedRegions []string
for key := range awsRegionMap {
supportedRegions = append(supportedRegions, key)
}
return fmt.Errorf("%v %s [%v]", region, errorMsgInvalidRegion, supportedRegions)
}
return fmt.Errorf("%v %s [%v]", awsConfig.Region, errorMsgInvalidRegion, supportedRegions)
}

return nil
Expand Down Expand Up @@ -306,11 +308,15 @@ func (v *CPAValidator) validateAzureAccount(account *crdv1alpha1.CloudProviderAc
if len(strings.TrimSpace(azureCredential.ClientID)) == 0 || len(strings.TrimSpace(azureCredential.ClientKey)) == 0 {
return fmt.Errorf(errorMsgMissingClientDetails)
}

// validate region
if len(azureConfig.Region) == 0 || len(strings.TrimSpace(azureConfig.Region[0])) == 0 {
if len(azureConfig.Region) == 0 {
return fmt.Errorf(errorMsgMissingRegion)
}
for _, region := range azureConfig.Region {
if len(strings.TrimSpace(region)) == 0 {
return fmt.Errorf(errorMsgMissingRegion)
}
}

return nil
}
4 changes: 2 additions & 2 deletions pkg/cloudprovider/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type AccountMgmtInterface interface {

// ComputeInterface is an abstract providing set of methods to get inventory details to be implemented by cloud providers.
type ComputeInterface interface {
// GetCloudInventory gets VPC and VM inventory from plugin snapshot for a given cloud provider account.
GetCloudInventory(accountNamespacedName *types.NamespacedName) (*nephetypes.CloudInventory, error)
// GetAccountCloudInventory gets VPC and VM inventory from plugin snapshot for a given cloud provider account.
GetAccountCloudInventory(accountNamespacedName *types.NamespacedName) (*nephetypes.CloudInventory, error)
}

type SecurityInterface interface {
Expand Down
5 changes: 5 additions & 0 deletions pkg/cloudprovider/plugins/aws/aws_account_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package aws

import (
"strings"

"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -23,6 +25,9 @@ import (

// AddProviderAccount adds and initializes given account of a cloud provider.
func (c *awsCloud) AddProviderAccount(client client.Client, account *crdv1alpha1.CloudProviderAccount) error {
for idx := range account.Spec.AWSConfig.Region {
account.Spec.AWSConfig.Region[idx] = strings.ToLower(account.Spec.AWSConfig.Region[idx])
}
return c.cloudCommon.AddCloudAccount(client, account, account.Spec.AWSConfig)
}

Expand Down
18 changes: 11 additions & 7 deletions pkg/cloudprovider/plugins/aws/aws_account_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"reflect"
"sort"
"strings"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -32,15 +34,15 @@ import (

type awsAccountConfig struct {
crdv1alpha1.AwsAccountCredential
region string
regions []string
endpoint string
}

// setAccountCredentials sets account credentials.
func setAccountCredentials(client client.Client, credentials interface{}) (interface{}, error) {
awsProviderConfig := credentials.(*crdv1alpha1.CloudProviderAccountAWSConfig)
awsConfig := &awsAccountConfig{
region: strings.TrimSpace(awsProviderConfig.Region[0]),
regions: awsProviderConfig.Region,
endpoint: strings.TrimSpace(awsProviderConfig.Endpoint),
}
accCred, err := extractSecret(client, awsProviderConfig.SecretRef)
Expand All @@ -52,11 +54,11 @@ func setAccountCredentials(client client.Client, credentials interface{}) (inter
accCred.ExternalID = internal.AccountCredentialsDefault
}

// As only single region is supported right now, use 0th index in awsProviderConfig.Region as the configured region.
awsConfig.AwsAccountCredential = *accCred
return awsConfig, err
}

// compareAccountCredentials compares two account credentials and returns they are different or not.
func compareAccountCredentials(accountName string, existing interface{}, new interface{}) bool {
existingConfig := existing.(*awsAccountConfig)
newConfig := new.(*awsAccountConfig)
Expand All @@ -82,14 +84,16 @@ func compareAccountCredentials(accountName string, existing interface{}, new int
credsChanged = true
awsPluginLogger().Info("Account IAM external id updated", "account", accountName)
}
if strings.Compare(existingConfig.region, newConfig.region) != 0 {
credsChanged = true
awsPluginLogger().Info("Account region updated", "account", accountName)
}
if strings.Compare(existingConfig.endpoint, newConfig.endpoint) != 0 {
credsChanged = true
awsPluginLogger().Info("Endpoint url updated", "account", accountName)
}
sort.Strings(existingConfig.regions)
sort.Strings(newConfig.regions)
if !reflect.DeepEqual(existingConfig.regions, newConfig.regions) {
credsChanged = true
awsPluginLogger().Info("Account regions updated", "account", accountName)
}
return credsChanged
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/cloudprovider/plugins/aws/aws_api_wrappers-mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 531e968

Please sign in to comment.