forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.go
56 lines (47 loc) · 1.36 KB
/
lookup.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
package rkenodeconfigserver
import (
"fmt"
"github.com/rancher/kontainer-engine/cluster"
kecerts "github.com/rancher/kontainer-engine/drivers/rke/rkecerts"
"github.com/rancher/rancher/pkg/controllers/management/clusterprovisioner"
"github.com/rancher/rancher/pkg/rkecerts"
"github.com/rancher/rke/pki"
v1 "github.com/rancher/types/apis/core/v1"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
)
type BundleLookup struct {
engineStore cluster.PersistentStore
}
func NewLookup(namespaces v1.NamespaceInterface, secrets v1.SecretsGetter) *BundleLookup {
return &BundleLookup{
engineStore: clusterprovisioner.NewPersistentStore(namespaces, secrets),
}
}
func (r *BundleLookup) Lookup(cluster *v3.Cluster) (*rkecerts.Bundle, error) {
c, err := r.engineStore.Get(cluster.Name)
if err != nil {
return nil, err
}
certs, ok := c.Metadata["Certs"]
if !ok {
return nil, fmt.Errorf("waiting for certs to be generated for cluster %s", cluster.Name)
}
certMap, err := kecerts.LoadString(certs)
if err != nil {
return nil, err
}
newCertMap := map[string]pki.CertificatePKI{}
for k, v := range certMap {
if v.Config != "" {
v.ConfigPath = pki.GetConfigPath(k)
}
if v.Key != nil {
v.KeyPath = pki.GetKeyPath(k)
}
if v.Certificate != nil {
v.Path = pki.GetCertPath(k)
}
newCertMap[k] = v
}
return rkecerts.NewBundle(newCertMap), nil
}