forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaults.go
100 lines (84 loc) · 2.54 KB
/
defaults.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
package release39
import (
"bytes"
"fmt"
"net"
"github.com/Azure/acs-engine/pkg/api"
"github.com/Azure/acs-engine/pkg/openshift/filesystem"
)
// OpenShiftSetDefaultCerts sets default certificate and configuration properties in the
// openshift orchestrator for 3.9.
func OpenShiftSetDefaultCerts(a *api.Properties, orchestratorName, clusterID string) (bool, error) {
if len(a.OrchestratorProfile.OpenShiftConfig.ConfigBundles["master"]) > 0 &&
len(a.OrchestratorProfile.OpenShiftConfig.ConfigBundles["bootstrap"]) > 0 {
return true, nil
}
c := Config{
Master: &Master{
Hostname: fmt.Sprintf("%s-master-%s-0", orchestratorName, clusterID),
IPs: []net.IP{
net.ParseIP(a.MasterProfile.FirstConsecutiveStaticIP),
},
Port: 8443,
},
ExternalMasterHostname: fmt.Sprintf("%s.%s.cloudapp.azure.com", a.MasterProfile.DNSPrefix, a.AzProfile.Location),
ClusterUsername: a.OrchestratorProfile.OpenShiftConfig.ClusterUsername,
ClusterPassword: a.OrchestratorProfile.OpenShiftConfig.ClusterPassword,
EnableAADAuthentication: a.OrchestratorProfile.OpenShiftConfig.EnableAADAuthentication,
AzureConfig: AzureConfig{
TenantID: a.AzProfile.TenantID,
SubscriptionID: a.AzProfile.SubscriptionID,
AADClientID: a.ServicePrincipalProfile.ClientID,
AADClientSecret: a.ServicePrincipalProfile.Secret,
ResourceGroup: a.AzProfile.ResourceGroup,
Location: a.AzProfile.Location,
},
}
err := c.PrepareMasterCerts()
if err != nil {
return false, err
}
err = c.PrepareMasterKubeConfigs()
if err != nil {
return false, err
}
err = c.PrepareMasterFiles()
if err != nil {
return false, err
}
err = c.PrepareBootstrapKubeConfig()
if err != nil {
return false, err
}
if a.OrchestratorProfile.OpenShiftConfig.ConfigBundles == nil {
a.OrchestratorProfile.OpenShiftConfig.ConfigBundles = make(map[string][]byte)
}
masterBundle, err := getConfigBundle(c.WriteMaster)
if err != nil {
return false, err
}
a.OrchestratorProfile.OpenShiftConfig.ConfigBundles["master"] = masterBundle
nodeBundle, err := getConfigBundle(c.WriteNode)
if err != nil {
return false, err
}
a.OrchestratorProfile.OpenShiftConfig.ConfigBundles["bootstrap"] = nodeBundle
return true, nil
}
type writeFn func(filesystem.Writer) error
func getConfigBundle(write writeFn) ([]byte, error) {
b := &bytes.Buffer{}
fs, err := filesystem.NewTGZWriter(b)
if err != nil {
return nil, err
}
err = write(fs)
if err != nil {
return nil, err
}
err = fs.Close()
if err != nil {
return nil, err
}
return b.Bytes(), nil
}