forked from openshift/hive
/
azure.go
76 lines (65 loc) · 1.83 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
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/v1alpha1"
hivev1azure "github.com/openshift/hive/pkg/apis/hive/v1alpha1/azure"
)
const (
azureCredFile = "osServicePrincipal.json"
)
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) error {
cd.Spec.Platform = hivev1.Platform{
Azure: &hivev1azure.Platform{
Region: "centralus",
BaseDomainResourceGroupName: o.AzureBaseDomainResourceGroupName,
},
}
cd.Spec.PlatformSecrets = hivev1.PlatformSecrets{
Azure: &hivev1azure.PlatformSecrets{
Credentials: corev1.LocalObjectReference{
Name: p.credsSecretName(o),
},
},
}
return nil
}
func (p *azureCloudProvider) credsSecretName(o *Options) string {
return fmt.Sprintf("%s-azure-creds", o.Name)
}