forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
render.go
85 lines (69 loc) · 1.92 KB
/
render.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
package assets
import (
"net"
"net/url"
assetslib "github.com/openshift/library-go/pkg/assets"
"github.com/openshift/origin/pkg/oc/clusterup/coreinstall/assets/tlsutil"
)
type TLSAssetsRenderOptions struct {
AltNames tlsutil.AltNames
config tlsAssetsRenderConfig
}
type tlsAssetsRenderConfig struct {
EtcdServerURL string
ServerURL string
AdminKey []byte
AdminCert []byte
CACert []byte
}
func NewTLSAssetsRenderer(hostname string) *TLSAssetsRenderOptions {
var altNames tlsutil.AltNames
if len(hostname) > 0 {
if ip := net.ParseIP(hostname); ip == nil {
altNames.DNSNames = append(altNames.DNSNames, hostname)
} else {
altNames.IPs = append(altNames.IPs, ip)
}
}
altNames.DNSNames = append(altNames.DNSNames, "localhost")
altNames.IPs = append(altNames.IPs, net.ParseIP("127.0.0.1"), net.ParseIP("10.3.0.1"))
return &TLSAssetsRenderOptions{
AltNames: altNames,
config: tlsAssetsRenderConfig{
ServerURL: "https://" + hostname + ":6443",
EtcdServerURL: "https://" + hostname + ":2379",
},
}
}
func (r *TLSAssetsRenderOptions) Render() (*assetslib.Assets, error) {
result := assetslib.Assets{}
// Generate CA
caPrivateKey, caCert, err := r.newCACert()
if err != nil {
return nil, err
}
r.config.CACert = tlsutil.EncodeCertificatePEM(caCert)
// Generate apiserver certs and keys
if files, err := r.newTLSAssets(caCert, caPrivateKey, r.AltNames); err != nil {
return nil, err
} else {
result = append(result, files...)
}
etcdURL, err := url.Parse(r.config.EtcdServerURL)
if err != nil {
return nil, err
}
localEtcdURL, _ := url.Parse("https://127.0.0.1:2379")
// Generate etcd certs
if files, err := r.newEtcdTLSAssets(caCert, caPrivateKey, []*url.URL{
etcdURL,
localEtcdURL,
}); err != nil {
return nil, err
} else {
result = append(result, files...)
}
// Generate admin.kubeconfig
result = append(result, r.newAdminKubeConfig()...)
return &result, nil
}