forked from openshift/hive
/
azure.go
103 lines (87 loc) · 2.6 KB
/
azure.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
package createcluster
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
hivev1 "github.com/openshift/hive/pkg/apis/hive/v1"
hivev1azure "github.com/openshift/hive/pkg/apis/hive/v1/azure"
installertypes "github.com/openshift/installer/pkg/types"
azureinstallertypes "github.com/openshift/installer/pkg/types/azure"
)
const (
azureCredFile = "osServicePrincipal.json"
azureRegion = "centralus"
azureInstanceType = "Standard_D2s_v3"
)
var _ cloudProvider = (*azureCloudProvider)(nil)
type azureCloudProvider struct {
}
func (p *azureCloudProvider) generateCredentialsSecret(o *Options) (*corev1.Secret, error) {
credsFilePath := filepath.Join(os.Getenv("HOME"), ".azure", azureCredFile)
if l := os.Getenv("AZURE_AUTH_LOCATION"); l != "" {
credsFilePath = l
}
if o.CredsFile != "" {
credsFilePath = o.CredsFile
}
log.Infof("Loading Azure service principal from: %s", credsFilePath)
spFileContents, err := ioutil.ReadFile(credsFilePath)
if err != nil {
return nil, err
}
return &corev1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: p.credsSecretName(o),
Namespace: o.Namespace,
},
Type: corev1.SecretTypeOpaque,
Data: map[string][]byte{
azureCredFile: spFileContents,
},
}, nil
}
func (p *azureCloudProvider) addPlatformDetails(
o *Options,
cd *hivev1.ClusterDeployment,
machinePool *hivev1.MachinePool,
installConfig *installertypes.InstallConfig,
) error {
cd.Spec.Platform = hivev1.Platform{
Azure: &hivev1azure.Platform{
CredentialsSecretRef: corev1.LocalObjectReference{
Name: p.credsSecretName(o),
},
Region: azureRegion,
BaseDomainResourceGroupName: o.AzureBaseDomainResourceGroupName,
},
}
machinePool.Spec.Platform.Azure = &hivev1azure.MachinePool{
InstanceType: azureInstanceType,
OSDisk: hivev1azure.OSDisk{
DiskSizeGB: 128,
},
}
// Inject platform details into InstallConfig:
installConfig.Platform = installertypes.Platform{
Azure: &azureinstallertypes.Platform{
Region: azureRegion,
BaseDomainResourceGroupName: o.AzureBaseDomainResourceGroupName,
},
}
// Used for both control plane and workers.
mpp := &azureinstallertypes.MachinePool{}
installConfig.ControlPlane.Platform.Azure = mpp
installConfig.Compute[0].Platform.Azure = mpp
return nil
}
func (p *azureCloudProvider) credsSecretName(o *Options) string {
return fmt.Sprintf("%s-azure-creds", o.Name)
}