This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 525
/
defaults-custom-cloud-profile.go
196 lines (172 loc) · 11.2 KB
/
defaults-custom-cloud-profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package api
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
"github.com/Azure/aks-engine/pkg/helpers"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/pkg/errors"
)
// CustomCloudProfileDefaultsParams is the parameters when we set the cloud profile defaults for ContainerService.
type CustomCloudProfileDefaultsParams struct {
IsUpgrade bool
IsScale bool
}
func (cs *ContainerService) setCustomCloudProfileDefaults(params CustomCloudProfileDefaultsParams) error {
p := cs.Properties
if p.IsAzureStackCloud() {
p.CustomCloudProfile.AuthenticationMethod = helpers.EnsureString(p.CustomCloudProfile.AuthenticationMethod, ClientSecretAuthMethod)
p.CustomCloudProfile.IdentitySystem = helpers.EnsureString(p.CustomCloudProfile.IdentitySystem, AzureADIdentitySystem)
p.CustomCloudProfile.DependenciesLocation = DependenciesLocation(helpers.EnsureString(string(p.CustomCloudProfile.DependenciesLocation), AzureStackDependenciesLocationPublic))
err := cs.SetCustomCloudProfileEnvironment()
if err != nil {
return fmt.Errorf("Failed to set environment - %s", err)
}
err = p.SetAzureStackCloudSpec(AzureStackCloudSpecParams(params))
if err != nil {
return fmt.Errorf("Failed to set cloud spec - %s", err)
}
}
return nil
}
// SetCustomCloudProfileEnvironment retrieves the endpoints from Azure Stack metadata endpoint and sets the values for azure.Environment
func (cs *ContainerService) SetCustomCloudProfileEnvironment() error {
p := cs.Properties
if p.IsAzureStackCloud() {
if p.CustomCloudProfile.Environment == nil {
p.CustomCloudProfile.Environment = &azure.Environment{}
}
env := p.CustomCloudProfile.Environment
if env.Name == "" || env.ResourceManagerEndpoint == "" || env.ServiceManagementEndpoint == "" || env.ActiveDirectoryEndpoint == "" || env.GraphEndpoint == "" || env.ResourceManagerVMDNSSuffix == "" {
env.Name = AzureStackCloud
if !strings.HasPrefix(p.CustomCloudProfile.PortalURL, fmt.Sprintf("https://portal.%s.", cs.Location)) {
return fmt.Errorf("portalURL needs to start with https://portal.%s. ", cs.Location)
}
azsFQDNSuffix := strings.Replace(p.CustomCloudProfile.PortalURL, fmt.Sprintf("https://portal.%s.", cs.Location), "", -1)
azsFQDNSuffix = strings.TrimSuffix(azsFQDNSuffix, "/")
env.ResourceManagerEndpoint = fmt.Sprintf("https://management.%s.%s/", cs.Location, azsFQDNSuffix)
metadataURL := fmt.Sprintf("%s/metadata/endpoints?api-version=1.0", strings.TrimSuffix(env.ResourceManagerEndpoint, "/"))
// Retrieve the metadata
httpClient := &http.Client{
Timeout: 30 * time.Second,
}
endpointsresp, err := httpClient.Get(metadataURL)
if err != nil || endpointsresp.StatusCode != 200 {
return fmt.Errorf("%s . apimodel invalid: failed to retrieve Azure Stack endpoints from %s", err, metadataURL)
}
body, err := ioutil.ReadAll(endpointsresp.Body)
if err != nil {
return fmt.Errorf("%s . apimodel invalid: failed to read the response from %s", err, metadataURL)
}
endpoints := AzureStackMetadataEndpoints{}
err = json.Unmarshal(body, &endpoints)
if err != nil {
return fmt.Errorf("%s . apimodel invalid: failed to parse the response from %s", err, metadataURL)
}
if endpoints.GraphEndpoint == "" || endpoints.Authentication == nil || endpoints.Authentication.LoginEndpoint == "" || len(endpoints.Authentication.Audiences) == 0 || endpoints.Authentication.Audiences[0] == "" {
return fmt.Errorf("%s . apimodel invalid: invalid response from %s", err, metadataURL)
}
env.GraphEndpoint = endpoints.GraphEndpoint
env.ServiceManagementEndpoint = endpoints.Authentication.Audiences[0]
env.GalleryEndpoint = endpoints.GalleryEndpoint
env.ActiveDirectoryEndpoint = endpoints.Authentication.LoginEndpoint
if p.CustomCloudProfile.IdentitySystem == ADFSIdentitySystem {
env.ActiveDirectoryEndpoint = strings.TrimSuffix(env.ActiveDirectoryEndpoint, "/")
env.ActiveDirectoryEndpoint = strings.TrimSuffix(env.ActiveDirectoryEndpoint, "adfs")
}
env.ManagementPortalURL = endpoints.PortalEndpoint
env.ResourceManagerVMDNSSuffix = fmt.Sprintf("cloudapp.%s", azsFQDNSuffix)
env.StorageEndpointSuffix = fmt.Sprintf("%s.%s", cs.Location, azsFQDNSuffix)
env.KeyVaultDNSSuffix = fmt.Sprintf("vault.%s.%s", cs.Location, azsFQDNSuffix)
}
}
return nil
}
// AzureStackCloudSpecParams is the parameters when we set the azure stack cloud spec defaults for ContainerService.
type AzureStackCloudSpecParams struct {
IsUpgrade bool
IsScale bool
}
// SetAzureStackCloudSpec sets the cloud spec for Azure Stack .
func (p *Properties) SetAzureStackCloudSpec(params AzureStackCloudSpecParams) error {
if p.IsAzureStackCloud() {
var azureStackCloudSpec AzureEnvironmentSpecConfig
switch p.CustomCloudProfile.DependenciesLocation {
case AzureStackDependenciesLocationPublic:
azureStackCloudSpec = AzureCloudSpecEnvMap[AzurePublicCloud]
case AzureStackDependenciesLocationChina:
azureStackCloudSpec = AzureCloudSpecEnvMap[AzureChinaCloud]
case AzureStackDependenciesLocationGerman:
azureStackCloudSpec = AzureCloudSpecEnvMap[AzureGermanCloud]
case AzureStackDependenciesLocationUSGovernment:
azureStackCloudSpec = AzureCloudSpecEnvMap[AzureUSGovernmentCloud]
default:
azureStackCloudSpec = AzureCloudSpecEnvMap[AzurePublicCloud]
}
if p.CustomCloudProfile.Environment == nil || p.CustomCloudProfile.Environment.ResourceManagerVMDNSSuffix == "" {
return errors.New("Failed to set Cloud Spec for Azure Stack due to invalid environment")
}
azureStackCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix = p.CustomCloudProfile.Environment.ResourceManagerVMDNSSuffix
azureStackCloudSpec.CloudName = AzureStackCloud
//Sets default values for telemetry PID where none is set
if p.CustomCloudProfile.AzureEnvironmentSpecConfig == nil {
switch {
case params.IsScale:
azureStackCloudSpec.KubernetesSpecConfig.AzureTelemetryPID = DefaultAzureStackScaleTelemetryPID
case params.IsUpgrade:
azureStackCloudSpec.KubernetesSpecConfig.AzureTelemetryPID = DefaultAzureStackUpgradeTelemetryPID
default:
azureStackCloudSpec.KubernetesSpecConfig.AzureTelemetryPID = DefaultAzureStackDeployTelemetryPID
}
}
// Use the custom input to overwrite the default values in AzureStackCloudSpec
if p.CustomCloudProfile.AzureEnvironmentSpecConfig != nil {
ascc := p.CustomCloudProfile.AzureEnvironmentSpecConfig
azureStackCloudSpec.CloudName = helpers.EnsureString(ascc.CloudName, azureStackCloudSpec.CloudName)
// DockerSpecConfig
asccDockerSpecConfig := ascc.DockerSpecConfig
azsDockerSpecConfig := azureStackCloudSpec.DockerSpecConfig
azureStackCloudSpec.DockerSpecConfig.DockerComposeDownloadURL = helpers.EnsureString(asccDockerSpecConfig.DockerComposeDownloadURL, azsDockerSpecConfig.DockerComposeDownloadURL)
azureStackCloudSpec.DockerSpecConfig.DockerEngineRepo = helpers.EnsureString(asccDockerSpecConfig.DockerEngineRepo, azsDockerSpecConfig.DockerComposeDownloadURL)
//KubernetesSpecConfig
asccKubernetesSpecConfig := ascc.KubernetesSpecConfig
azsKubernetesSpecConfig := azureStackCloudSpec.KubernetesSpecConfig
azureStackCloudSpec.KubernetesSpecConfig.AzureTelemetryPID = helpers.EnsureString(asccKubernetesSpecConfig.AzureTelemetryPID, DefaultAzureStackDeployTelemetryPID)
azureStackCloudSpec.KubernetesSpecConfig.ACIConnectorImageBase = helpers.EnsureString(asccKubernetesSpecConfig.ACIConnectorImageBase, azsKubernetesSpecConfig.ACIConnectorImageBase)
azureStackCloudSpec.KubernetesSpecConfig.AzureCNIImageBase = helpers.EnsureString(asccKubernetesSpecConfig.AzureCNIImageBase, azsKubernetesSpecConfig.AzureCNIImageBase)
azureStackCloudSpec.KubernetesSpecConfig.CalicoImageBase = helpers.EnsureString(asccKubernetesSpecConfig.CalicoImageBase, azsKubernetesSpecConfig.CalicoImageBase)
azureStackCloudSpec.KubernetesSpecConfig.CNIPluginsDownloadURL = helpers.EnsureString(asccKubernetesSpecConfig.CNIPluginsDownloadURL, azsKubernetesSpecConfig.CNIPluginsDownloadURL)
azureStackCloudSpec.KubernetesSpecConfig.ContainerdDownloadURLBase = helpers.EnsureString(asccKubernetesSpecConfig.ContainerdDownloadURLBase, azsKubernetesSpecConfig.ContainerdDownloadURLBase)
azureStackCloudSpec.KubernetesSpecConfig.CSIProxyDownloadURL = helpers.EnsureString(asccKubernetesSpecConfig.CSIProxyDownloadURL, azsKubernetesSpecConfig.CSIProxyDownloadURL)
azureStackCloudSpec.KubernetesSpecConfig.EtcdDownloadURLBase = helpers.EnsureString(asccKubernetesSpecConfig.EtcdDownloadURLBase, azsKubernetesSpecConfig.EtcdDownloadURLBase)
azureStackCloudSpec.KubernetesSpecConfig.KubeBinariesSASURLBase = helpers.EnsureString(asccKubernetesSpecConfig.KubeBinariesSASURLBase, azsKubernetesSpecConfig.KubeBinariesSASURLBase)
azureStackCloudSpec.KubernetesSpecConfig.KubernetesImageBase = helpers.EnsureString(asccKubernetesSpecConfig.KubernetesImageBase, azsKubernetesSpecConfig.KubernetesImageBase)
azureStackCloudSpec.KubernetesSpecConfig.MCRKubernetesImageBase = helpers.EnsureString(asccKubernetesSpecConfig.MCRKubernetesImageBase, azsKubernetesSpecConfig.MCRKubernetesImageBase)
azureStackCloudSpec.KubernetesSpecConfig.NVIDIAImageBase = helpers.EnsureString(asccKubernetesSpecConfig.NVIDIAImageBase, azsKubernetesSpecConfig.NVIDIAImageBase)
azureStackCloudSpec.KubernetesSpecConfig.TillerImageBase = helpers.EnsureString(asccKubernetesSpecConfig.TillerImageBase, azsKubernetesSpecConfig.TillerImageBase)
azureStackCloudSpec.KubernetesSpecConfig.VnetCNILinuxPluginsDownloadURL = helpers.EnsureString(asccKubernetesSpecConfig.VnetCNILinuxPluginsDownloadURL, azsKubernetesSpecConfig.VnetCNILinuxPluginsDownloadURL)
azureStackCloudSpec.KubernetesSpecConfig.VnetCNIWindowsPluginsDownloadURL = helpers.EnsureString(asccKubernetesSpecConfig.VnetCNIWindowsPluginsDownloadURL, azsKubernetesSpecConfig.VnetCNIWindowsPluginsDownloadURL)
azureStackCloudSpec.KubernetesSpecConfig.WindowsTelemetryGUID = helpers.EnsureString(asccKubernetesSpecConfig.WindowsTelemetryGUID, azsKubernetesSpecConfig.WindowsTelemetryGUID)
azureStackCloudSpec.KubernetesSpecConfig.WindowsProvisioningScriptsPackageURL = helpers.EnsureString(asccKubernetesSpecConfig.WindowsProvisioningScriptsPackageURL, azsKubernetesSpecConfig.WindowsProvisioningScriptsPackageURL)
azureStackCloudSpec.KubernetesSpecConfig.WindowsPauseImageURL = helpers.EnsureString(asccKubernetesSpecConfig.WindowsPauseImageURL, azsKubernetesSpecConfig.WindowsPauseImageURL)
azureStackCloudSpec.KubernetesSpecConfig.AlwaysPullWindowsPauseImage = asccKubernetesSpecConfig.AlwaysPullWindowsPauseImage
//EndpointConfig
asccEndpointConfig := ascc.EndpointConfig
azsEndpointConfig := azureStackCloudSpec.EndpointConfig
azureStackCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix = helpers.EnsureString(asccEndpointConfig.ResourceManagerVMDNSSuffix, azsEndpointConfig.ResourceManagerVMDNSSuffix)
//OSImageConfig
azureStackCloudSpec.OSImageConfig = make(map[Distro]AzureOSImageConfig)
for k, v := range ascc.OSImageConfig {
azureStackCloudSpec.OSImageConfig[k] = v
}
p.CustomCloudProfile.AzureEnvironmentSpecConfig = &azureStackCloudSpec
}
AzureCloudSpecEnvMap[AzureStackCloud] = azureStackCloudSpec
}
return nil
}