-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cloud config parser and update hub-net-controller-manager chart
- Loading branch information
Showing
11 changed files
with
499 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
charts/hub-net-controller-manager/templates/azurecloudconfig.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: azure-cloud-config | ||
namespace: {{ .Values.fleetSystemNamespace }} | ||
type: Opaque | ||
data: | ||
azure.json: {{ .Values.config.azureCloudConfig | toJson | indent 4 | b64enc | quote }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
// Package azure defines azure cloud provider configuration. | ||
package azure | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"sigs.k8s.io/cloud-provider-azure/pkg/azclient" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
type CloudConfig struct { | ||
azclient.ARMClientConfig `json:",inline" mapstructure:",squash"` | ||
azclient.AzureAuthConfig `json:",inline" mapstructure:",squash"` | ||
// subscription ID | ||
SubscriptionID string `json:"subscriptionID,omitempty" mapstructure:"subscriptionID,omitempty"` | ||
// azure resource location | ||
Location string `json:"location,omitempty" mapstructure:"location,omitempty"` | ||
// default resource group where the azure resources are deployed | ||
ResourceGroup string `json:"resourceGroup,omitempty" mapstructure:"resourceGroup,omitempty"` | ||
} | ||
|
||
const ( | ||
// DefaultUserAgent is the default user agent string to access Azure resources. | ||
DefaultUserAgent = "fleet-net-controller-manager" | ||
) | ||
|
||
func LoadCloudConfigFromFile(filePath string) (*CloudConfig, error) { | ||
if filePath == "" { | ||
return nil, fmt.Errorf("failed to load cloud config: file path is empty") | ||
} | ||
|
||
var config CloudConfig | ||
configReader, err := os.Open(filePath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to open cloud config file: %w, file path: %s", err, filePath) | ||
} | ||
defer configReader.Close() | ||
|
||
contents, err := io.ReadAll(configReader) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read cloud config file: %w, file path: %s", err, filePath) | ||
} | ||
|
||
if err := yaml.Unmarshal(contents, &config); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal cloud config: %w, file path: %s", err, filePath) | ||
} | ||
|
||
if err := config.defaultAndValidate(); err != nil { | ||
return nil, fmt.Errorf("failed to validate cloud config: %w, file contents: `%s`", err, string(contents)) | ||
} | ||
|
||
return &config, nil | ||
} | ||
|
||
func (cfg *CloudConfig) defaultAndValidate() error { | ||
cfg.trimSpace() | ||
|
||
if cfg.Cloud == "" { | ||
return fmt.Errorf("cloud is empty") | ||
} | ||
|
||
if cfg.Location == "" { | ||
return fmt.Errorf("location is empty") | ||
} | ||
|
||
if cfg.SubscriptionID == "" { | ||
return fmt.Errorf("subscription ID is empty") | ||
} | ||
|
||
if cfg.ResourceGroup == "" { | ||
return fmt.Errorf("resource group is empty") | ||
} | ||
|
||
if !cfg.UseManagedIdentityExtension { | ||
if cfg.UserAssignedIdentityID != "" { | ||
return fmt.Errorf("useManagedIdentityExtension needs to be true when userAssignedIdentityID is provided") | ||
} | ||
if cfg.AADClientID == "" || cfg.AADClientSecret == "" { | ||
return fmt.Errorf("AAD client ID or AAD client secret is empty") | ||
} | ||
} | ||
|
||
// default values | ||
if cfg.UserAgent == "" { | ||
cfg.UserAgent = DefaultUserAgent | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (cfg *CloudConfig) trimSpace() { | ||
cfg.Cloud = strings.TrimSpace(cfg.Cloud) | ||
cfg.TenantID = strings.TrimSpace(cfg.TenantID) | ||
cfg.UserAgent = strings.TrimSpace(cfg.UserAgent) | ||
cfg.SubscriptionID = strings.TrimSpace(cfg.SubscriptionID) | ||
cfg.Location = strings.TrimSpace(cfg.Location) | ||
cfg.ResourceGroup = strings.TrimSpace(cfg.ResourceGroup) | ||
cfg.UserAssignedIdentityID = strings.TrimSpace(cfg.UserAssignedIdentityID) | ||
cfg.AADClientID = strings.TrimSpace(cfg.AADClientID) | ||
cfg.AADClientSecret = strings.TrimSpace(cfg.AADClientSecret) | ||
} |
Oops, something went wrong.