Skip to content

Commit

Permalink
Respect cloud configuration in dnsrecord (#1018)
Browse files Browse the repository at this point in the history
* fix issue with dnsrecord on CN not having a region

* remove unneeded objects
  • Loading branch information
kon-angelo authored Nov 20, 2024
1 parent 24e0e39 commit dd6be7b
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 310 deletions.
51 changes: 1 addition & 50 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Resource Types:
</li><li>
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.ControlPlaneConfig">ControlPlaneConfig</a>
</li><li>
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.DNSRecordConfig">DNSRecordConfig</a>
</li><li>
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.InfrastructureConfig">InfrastructureConfig</a>
</li><li>
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.WorkerConfig">WorkerConfig</a>
Expand Down Expand Up @@ -230,52 +228,6 @@ Storage
</tr>
</tbody>
</table>
<h3 id="azure.provider.extensions.gardener.cloud/v1alpha1.DNSRecordConfig">DNSRecordConfig
</h3>
<p>
<p>DNSRecordConfig is the provider-specific configuration for DNSRecords.</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>apiVersion</code></br>
string</td>
<td>
<code>
azure.provider.extensions.gardener.cloud/v1alpha1
</code>
</td>
</tr>
<tr>
<td>
<code>kind</code></br>
string
</td>
<td><code>DNSRecordConfig</code></td>
</tr>
<tr>
<td>
<code>cloudConfiguration</code></br>
<em>
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.CloudConfiguration">
CloudConfiguration
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>CloudConfiguration contains config that controls which cloud to connect to.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="azure.provider.extensions.gardener.cloud/v1alpha1.InfrastructureConfig">InfrastructureConfig
</h3>
<p>
Expand Down Expand Up @@ -621,8 +573,7 @@ string
<p>
(<em>Appears on:</em>
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.BackupBucketConfig">BackupBucketConfig</a>,
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.CloudProfileConfig">CloudProfileConfig</a>,
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.DNSRecordConfig">DNSRecordConfig</a>)
<a href="#azure.provider.extensions.gardener.cloud/v1alpha1.CloudProfileConfig">CloudProfileConfig</a>)
</p>
<p>
<p>CloudConfiguration contains detailed config for the cloud to connect to. Currently we only support selection of well-
Expand Down
16 changes: 0 additions & 16 deletions pkg/apis/azure/helper/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,6 @@ func BackupConfigFromBackupBucket(backupBucket *extensionsv1alpha1.BackupBucket)
return backupConfig, nil
}

// DNSRecordConfigFromDNSRecord decodes the provider specific config from a given DNSRecord object.
func DNSRecordConfigFromDNSRecord(dnsRecord *extensionsv1alpha1.DNSRecord) (api.DNSRecordConfig, error) {
dnsRecordConfig := api.DNSRecordConfig{}
if dnsRecord != nil && dnsRecord.Spec.ProviderConfig != nil {
dnsJson, err := dnsRecord.Spec.ProviderConfig.MarshalJSON()
if err != nil {
return dnsRecordConfig, err
}

if _, _, err := decoder.Decode(dnsJson, nil, &dnsRecordConfig); err != nil {
return dnsRecordConfig, err
}
}
return dnsRecordConfig, nil
}

// InfrastructureStateFromRaw extracts the state from the Infrastructure. If no state was available, it returns a "zero" value InfrastructureState object.
func InfrastructureStateFromRaw(raw *runtime.RawExtension) (*api.InfrastructureState, error) {
state := &api.InfrastructureState{}
Expand Down
12 changes: 1 addition & 11 deletions pkg/apis/azure/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ var (

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&CloudProfileConfig{},
&InfrastructureConfig{},
&InfrastructureStatus{},
&InfrastructureState{},
&ControlPlaneConfig{},
&WorkerStatus{},
&WorkerConfig{},
&BackupBucketConfig{},
&DNSRecordConfig{},
)
scheme.AddKnownTypes(SchemeGroupVersion, &CloudProfileConfig{}, &InfrastructureConfig{}, &InfrastructureStatus{}, &InfrastructureState{}, &ControlPlaneConfig{}, &WorkerStatus{}, &WorkerConfig{}, &BackupBucketConfig{})
return nil
}
27 changes: 0 additions & 27 deletions pkg/apis/azure/types_dnsrecord.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/apis/azure/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&WorkerConfig{},
&WorkerStatus{},
&BackupBucketConfig{},
&DNSRecordConfig{},
)
return nil
}
29 changes: 0 additions & 29 deletions pkg/apis/azure/v1alpha1/types_dnsrecord.go

This file was deleted.

30 changes: 0 additions & 30 deletions pkg/apis/azure/v1alpha1/zz_generated.conversion.go

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

30 changes: 0 additions & 30 deletions pkg/apis/azure/v1alpha1/zz_generated.deepcopy.go

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

30 changes: 0 additions & 30 deletions pkg/apis/azure/zz_generated.deepcopy.go

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

10 changes: 9 additions & 1 deletion pkg/azure/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ func NewAzureClientFactoryFromSecret(
isDNSSecret bool,
options ...AzureFactoryOption,
) (Factory, error) {
auth, err := internal.GetClientAuthData(ctx, client, secretRef, isDNSSecret)
auth, secret, err := internal.GetClientAuthData(ctx, client, secretRef, isDNSSecret)
if err != nil {
return nil, err
}
if isDNSSecret {
acc, err := cloudConfigurationFromSecret(secret)
if err != nil {
return nil, err
}
// prepend the cloud configuration from the secret in favor of the explicit ones that may be passed from options.
options = append([]AzureFactoryOption{WithCloudConfiguration(acc)}, options...)
}
return NewAzureClientFactory(auth, options...)
}

Expand Down
14 changes: 13 additions & 1 deletion pkg/azure/client/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/go-autorest/autorest"
azerrors "github.com/AzureAD/microsoft-authentication-library-for-go/apps/errors"
corev1 "k8s.io/api/core/v1"

"github.com/gardener/gardener-extension-provider-azure/pkg/apis/azure"
azuretypes "github.com/gardener/gardener-extension-provider-azure/pkg/azure"
)

// FilterNotFoundError returns nil for NotFound errors.
Expand Down Expand Up @@ -89,6 +91,17 @@ func AzureCloudConfiguration(cloudConfiguration *azure.CloudConfiguration, regio
return AzureCloudConfigurationFromCloudConfiguration(cloudConf)
}

// cloudConfigurationFromRegion returns a matching cloudConfiguration corresponding to a well known cloud instance for the given region
func cloudConfigurationFromSecret(secret *corev1.Secret) (cloud.Configuration, error) {
if v, ok := secret.Data[azuretypes.AzureCloud]; ok {
return AzureCloudConfigurationFromCloudConfiguration(&azure.CloudConfiguration{Name: string(v)})
}
if v, ok := secret.Data[azuretypes.DNSAzureCloud]; ok {
return AzureCloudConfigurationFromCloudConfiguration(&azure.CloudConfiguration{Name: string(v)})
}
return AzureCloudConfigurationFromCloudConfiguration(nil)
}

// cloudConfigurationFromRegion returns a matching cloudConfiguration corresponding to a well known cloud instance for the given region
func cloudConfigurationFromRegion(region string) *azure.CloudConfiguration {
switch {
Expand All @@ -106,7 +119,6 @@ func AzureCloudConfigurationFromCloudConfiguration(cloudConfiguration *azure.Clo
if cloudConfiguration == nil {
return cloud.AzurePublic, nil
}

cloudConfigurationName := cloudConfiguration.Name
switch {
case strings.EqualFold(cloudConfigurationName, azure.AzurePublicCloudName):
Expand Down
4 changes: 4 additions & 0 deletions pkg/azure/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
ClientIDKey = "clientID"
// ClientSecretKey is the key for the client secret.
ClientSecretKey = "clientSecret"
// AzureCloud is the key for the cloud configuration in the DNS Secret.
AzureCloud = "azureCloud" // #nosec G101 -- No credential.

// DNSSubscriptionIDKey is the key for the subscription ID in DNS secrets.
DNSSubscriptionIDKey = "AZURE_SUBSCRIPTION_ID"
Expand All @@ -66,6 +68,8 @@ const (
DNSClientIDKey = "AZURE_CLIENT_ID"
// DNSClientSecretKey is the key for the client secret in DNS secrets.
DNSClientSecretKey = "AZURE_CLIENT_SECRET" // #nosec G101 -- No credential.
// DNSAzureCloud is the key for the cloud configuration in the DNS Secret
DNSAzureCloud = "AZURE_CLOUD" // #nosec G101 -- No credential.

// StorageAccount is a constant for the key in a cloud provider secret and backup secret that holds the Azure account name.
StorageAccount = "storageAccount"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controlplane/valuesprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (vp *valuesProvider) GetConfigChartValues(ctx context.Context, cp *extensio
}

// Get client auth
auth, err := internal.GetClientAuthData(ctx, vp.client, cp.Spec.SecretRef, false)
auth, _, err := internal.GetClientAuthData(ctx, vp.client, cp.Spec.SecretRef, false)
if err != nil {
return nil, fmt.Errorf("could not get service account from secret '%s/%s': %w", cp.Spec.SecretRef.Namespace, cp.Spec.SecretRef.Name, err)
}
Expand Down
Loading

0 comments on commit dd6be7b

Please sign in to comment.