/
machine.go
78 lines (69 loc) · 2.29 KB
/
machine.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
package machine
import (
"encoding/base64"
"fmt"
"github.com/crc-org/crc/v2/pkg/crc/cluster"
"github.com/crc-org/crc/v2/pkg/crc/constants"
"github.com/crc-org/crc/v2/pkg/crc/machine/bundle"
"github.com/crc-org/crc/v2/pkg/crc/machine/types"
"github.com/crc-org/crc/v2/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/v2/pkg/libmachine"
"github.com/crc-org/machine/libmachine/drivers"
)
func getClusterConfig(bundleInfo *bundle.CrcBundleInfo) (*types.ClusterConfig, error) {
if !bundleInfo.IsOpenShift() {
return &types.ClusterConfig{
ClusterType: bundleInfo.GetBundleType(),
ProxyConfig: &httpproxy.ProxyConfig{},
}, nil
}
kubeadminPassword, err := cluster.GetKubeadminPassword()
if err != nil {
return nil, fmt.Errorf("Error reading kubeadmin password from bundle %v", err)
}
proxyConfig, err := getProxyConfig(bundleInfo)
if err != nil {
return nil, err
}
clusterCACert, err := certificateAuthority(bundleInfo.GetKubeConfigPath())
if err != nil {
return nil, err
}
return &types.ClusterConfig{
ClusterType: bundleInfo.GetBundleType(),
ClusterCACert: base64.StdEncoding.EncodeToString(clusterCACert),
KubeConfig: bundleInfo.GetKubeConfigPath(),
KubeAdminPass: kubeadminPassword,
WebConsoleURL: fmt.Sprintf("https://%s", bundleInfo.GetAppHostname("console-openshift-console")),
ClusterAPI: fmt.Sprintf("https://%s:6443", bundleInfo.GetAPIHostname()),
ProxyConfig: proxyConfig,
}, nil
}
func getBundleMetadataFromDriver(driver drivers.Driver) (*bundle.CrcBundleInfo, error) {
bundleName, err := driver.GetBundleName()
if err != nil {
err := fmt.Errorf("Error getting bundle name from CRC instance, make sure you ran 'crc setup' and are using the latest bundle")
return nil, err
}
metadata, err := bundle.Get(bundleName)
if err != nil {
return nil, err
}
return metadata, err
}
func createLibMachineClient() (libmachine.API, func()) {
client := libmachine.NewClient(constants.MachineBaseDir)
return client, func() {
client.Close()
}
}
func getProxyConfig(bundleInfo *bundle.CrcBundleInfo) (*httpproxy.ProxyConfig, error) {
proxy, err := httpproxy.NewProxyConfig()
if err != nil {
return nil, err
}
if proxy.IsEnabled() && bundleInfo.IsOpenShift() {
proxy.AddNoProxy(fmt.Sprintf(".%s", bundleInfo.ClusterInfo.BaseDomain))
}
return proxy, nil
}