Skip to content

Commit

Permalink
Add endpoint option in cloudprovideraccount CRD
Browse files Browse the repository at this point in the history
Endpoint can be used to set non AWS default URL. Primarily
used to set endpoint to mock AWS services like localstack

Signed-off-by: Rahul Jain <[email protected]>
  • Loading branch information
reachjainrahul committed Feb 8, 2023
1 parent 5a0f5aa commit 9607748
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apis/crd/v1alpha1/cloudprovideraccount_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type CloudProviderAccountAWSConfig struct {
SecretRef *SecretReference `json:"secretRef,omitempty"`
// Cloud provider account region.
Region string `json:"region,omitempty"`
// Endpoint URL that overrides the default AWS generated endpoint.
Endpoint string `json:"endpoint,omitempty"`
}

type CloudProviderAccountAzureConfig struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ spec:
awsConfig:
description: Cloud provider account config.
properties:
endpoint:
description: Endpoint URL that overrides the default AWS generated
endpoint.
type: string
region:
description: Cloud provider account region.
type: string
Expand Down
4 changes: 4 additions & 0 deletions config/nephe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ spec:
awsConfig:
description: Cloud provider account config.
properties:
endpoint:
description: Endpoint URL that overrides the default AWS generated
endpoint.
type: string
region:
description: Cloud provider account region.
type: string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ require (
k8s.io/apiextensions-apiserver v0.24.2 // indirect
k8s.io/apiserver v0.24.2
k8s.io/component-base v0.24.2 // indirect
k8s.io/klog/v2 v2.60.1
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.30 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
Expand Down
8 changes: 7 additions & 1 deletion pkg/cloud-provider/cloudapi/aws/aws_account_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

type awsAccountConfig struct {
v1alpha1.AwsAccountCredential
region string
region string
endpoint string
}

// setAccountCredentials sets account credentials.
Expand All @@ -43,6 +44,7 @@ func setAccountCredentials(client client.Client, credentials interface{}) (inter
awsConfig := &awsAccountConfig{
AwsAccountCredential: *accCred,
region: strings.TrimSpace(awsProviderConfig.Region),
endpoint: strings.TrimSpace(awsProviderConfig.Endpoint),
}

return awsConfig, nil
Expand Down Expand Up @@ -73,6 +75,10 @@ func compareAccountCredentials(accountName string, existing interface{}, new int
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)
}
return credsChanged
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cloud-provider/cloudapi/aws/aws_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (h *awsServicesHelperImpl) newServiceSdkConfigProvider(accConfig *awsAccoun

awsConfig := &aws.Config{
Region: &accConfig.region,
Endpoint: &accConfig.endpoint,
Credentials: creds,
CredentialsChainVerboseErrors: aws.Bool(true),
}
Expand Down

0 comments on commit 9607748

Please sign in to comment.