Skip to content

Commit 03df29c

Browse files
authored
Merge pull request #802 from alexeldeib/ace/cloud
✨ automatically generate azure.json
2 parents 6db35b4 + 013374c commit 03df29c

File tree

56 files changed

+1616
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1616
-621
lines changed

Tiltfile

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ def deploy_worker_templates(flavor, substitutions):
270270
"AZURE_CONTROL_PLANE_MACHINE_TYPE": "Standard_D2s_v3",
271271
"WORKER_MACHINE_COUNT": "2",
272272
"AZURE_NODE_MACHINE_TYPE": "Standard_D2s_v3",
273-
"AZURE_JSON_B64": base64_encode(azure_json(flavor, substitutions)),
274273
}
275274

276275
for substitution in substitutions:
@@ -288,35 +287,6 @@ def deploy_worker_templates(flavor, substitutions):
288287
)
289288

290289

291-
def azure_json(flavor, substitutions):
292-
azure_settings = {
293-
"cloud": substitutions.get("AZURE_ENVIRONMENT"),
294-
"tenantId": substitutions.get("AZURE_TENANT_ID"),
295-
"subscriptionId": substitutions.get("AZURE_SUBSCRIPTION_ID"),
296-
"resourceGroup": substitutions.get("CLUSTER_NAME"),
297-
"securityGroupName": "{}-node-nsg".format(substitutions.get("CLUSTER_NAME")),
298-
"location": substitutions.get("AZURE_LOCATION"),
299-
"vmType": "vmss",
300-
"vnetName": "{}-vnet".format(substitutions.get("CLUSTER_NAME")),
301-
"vnetResourceGroup": substitutions.get("CLUSTER_NAME"),
302-
"subnetName": "{}-node-subnet".format(substitutions.get("CLUSTER_NAME")),
303-
"routeTableName": "{}-node-routetable".format(substitutions.get("CLUSTER_NAME")),
304-
"loadBalancerSku": "standard",
305-
"maximumLoadBalancerRuleCount": 250,
306-
"useManagedIdentityExtension": False,
307-
"useInstanceMetadata": True
308-
}
309-
310-
if flavor not in ["system-assigned-identity", "user-assigned-identity"]:
311-
azure_settings["aadClientId"] = substitutions.get("AZURE_CLIENT_ID}")
312-
azure_settings["aadClientSecret"] = substitutions.get("AZURE_CLIENT_SECRET}")
313-
314-
if flavor == "user-assigned-identity":
315-
azure_settings["userAssignedIdentityID"] = substitutions.get("AZURE_USER_ASSIGNED_ID")
316-
317-
return str(encode_json(azure_settings))
318-
319-
320290
def base64_encode(to_encode):
321291
encode_blob = local("echo '{}' | tr -d '\n' | base64 - | tr -d '\n'".format(to_encode), quiet=True)
322292
return str(encode_blob)

cloud/interfaces.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ type CredentialGetter interface {
5555
// Authorizer is an interface which can get the subscription ID, base URI, and authorizer for an Azure service.
5656
type Authorizer interface {
5757
SubscriptionID() string
58+
ClientID() string
59+
ClientSecret() string
60+
CloudEnvironment() string
61+
TenantID() string
5862
BaseURI() string
5963
Authorizer() autorest.Authorizer
6064
}

cloud/scope/clients.go

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ limitations under the License.
1717
package scope
1818

1919
import (
20-
"os"
20+
"fmt"
21+
"strings"
2122

2223
"github.com/Azure/go-autorest/autorest"
24+
"github.com/Azure/go-autorest/autorest/azure"
2325
"github.com/Azure/go-autorest/autorest/azure/auth"
24-
"github.com/pkg/errors"
2526
)
2627

2728
const (
@@ -37,40 +38,73 @@ const (
3738

3839
// AzureClients contains all the Azure clients used by the scopes.
3940
type AzureClients struct {
40-
SubscriptionID string
41+
Authorizer autorest.Authorizer
42+
environment string
4143
ResourceManagerEndpoint string
4244
ResourceManagerVMDNSSuffix string
43-
Authorizer autorest.Authorizer
45+
subscriptionID string
46+
tenantID string
47+
clientID string
48+
clientSecret string
49+
}
50+
51+
// CloudEnvironment returns the Azure environment the controller runs in.
52+
func (c *AzureClients) CloudEnvironment() string {
53+
return c.environment
54+
}
55+
56+
// SubscriptionID returns the Azure subscription id from the controller environment
57+
func (c *AzureClients) SubscriptionID() string {
58+
return c.subscriptionID
59+
}
60+
61+
// TenantID returns the Azure tenant id the controller runs in.
62+
func (c *AzureClients) TenantID() string {
63+
return c.tenantID
64+
}
65+
66+
// ClientID returns the Azure client id from the controller environment
67+
func (c *AzureClients) ClientID() string {
68+
return c.clientID
69+
}
70+
71+
// ClientSecret returns the Azure client secret from the controller environment
72+
func (c *AzureClients) ClientSecret() string {
73+
return c.clientSecret
4474
}
4575

4676
func (c *AzureClients) setCredentials(subscriptionID string) error {
47-
subID, err := getSubscriptionID(subscriptionID)
48-
if err != nil {
49-
return err
50-
}
51-
c.SubscriptionID = subID
5277
settings, err := auth.GetSettingsFromEnvironment()
5378
if err != nil {
5479
return err
5580
}
81+
82+
if subscriptionID == "" {
83+
subscriptionID = settings.GetSubscriptionID()
84+
if subscriptionID == "" {
85+
return fmt.Errorf("error creating azure services. subscriptionID is not set in cluster or AZURE_SUBSCRIPTION_ID env var")
86+
}
87+
}
88+
89+
c.subscriptionID = subscriptionID
90+
c.tenantID = strings.TrimSuffix(settings.Values[auth.TenantID], "\n")
91+
c.clientID = strings.TrimSuffix(settings.Values[auth.ClientID], "\n")
92+
c.clientSecret = strings.TrimSuffix(settings.Values[auth.ClientSecret], "\n")
93+
94+
c.environment = settings.Values[auth.EnvironmentName]
95+
if c.environment == "" {
96+
c.environment = azure.PublicCloud.Name
97+
}
98+
5699
c.ResourceManagerEndpoint = settings.Environment.ResourceManagerEndpoint
57100
c.ResourceManagerVMDNSSuffix = GetAzureDNSZoneForEnvironment(settings.Environment.Name)
58101
settings.Values[auth.SubscriptionID] = subscriptionID
102+
settings.Values[auth.TenantID] = c.tenantID
103+
59104
c.Authorizer, err = settings.GetAuthorizer()
60105
return err
61106
}
62107

63-
func getSubscriptionID(subscriptionID string) (string, error) {
64-
if subscriptionID != "" {
65-
return subscriptionID, nil
66-
}
67-
subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID")
68-
if subscriptionID == "" {
69-
return "", errors.New("error creating azure services. Environment variable AZURE_SUBSCRIPTION_ID is not set")
70-
}
71-
return subscriptionID, nil
72-
}
73-
74108
// GetAzureDNSZoneForEnvironment returnes the DNSZone to be used with the
75109
// cloud environment, the default is the public cloud
76110
func GetAzureDNSZoneForEnvironment(environmentName string) string {

cloud/scope/cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
6666

6767
return &ClusterScope{
6868
Logger: params.Logger,
69-
client: params.Client,
69+
Client: params.Client,
7070
AzureClients: params.AzureClients,
7171
Cluster: params.Cluster,
7272
AzureCluster: params.AzureCluster,
@@ -77,7 +77,7 @@ func NewClusterScope(params ClusterScopeParams) (*ClusterScope, error) {
7777
// ClusterScope defines the basic context for an actuator to operate upon.
7878
type ClusterScope struct {
7979
logr.Logger
80-
client client.Client
80+
Client client.Client
8181
patchHelper *patch.Helper
8282

8383
AzureClients
@@ -87,7 +87,7 @@ type ClusterScope struct {
8787

8888
// SubscriptionID returns the Azure client Subscription ID.
8989
func (s *ClusterScope) SubscriptionID() string {
90-
return s.AzureClients.SubscriptionID
90+
return s.AzureClients.SubscriptionID()
9191
}
9292

9393
// BaseURI returns the Azure ResourceManagerEndpoint.

cloud/scope/managedcontrolplane.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scope
1818

1919
import (
2020
"context"
21+
2122
"github.com/Azure/go-autorest/autorest"
2223
"github.com/go-logr/logr"
2324
"github.com/pkg/errors"
@@ -96,7 +97,7 @@ type ManagedControlPlaneScope struct {
9697

9798
// SubscriptionID returns the Azure client Subscription ID.
9899
func (s *ManagedControlPlaneScope) SubscriptionID() string {
99-
return s.AzureClients.SubscriptionID
100+
return s.AzureClients.SubscriptionID()
100101
}
101102

102103
// BaseURI returns the Azure ResourceManagerEndpoint.

cloud/services/disks/mock_disks/disks_mock.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/services/groups/mock_groups/groups_mock.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/services/inboundnatrules/mock_inboundnatrules/inboundnatrules_mock.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)