-
Notifications
You must be signed in to change notification settings - Fork 67
/
config.go
132 lines (127 loc) · 4.06 KB
/
config.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package container
import (
"encoding/base64"
"net/url"
"github.com/crossplane/upjet/pkg/config"
"github.com/pkg/errors"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"github.com/upbound/provider-gcp/config/common"
)
// Configure configures individual resources by adding custom
// ResourceConfigurators.
func Configure(p *config.Provider) { //nolint:gocyclo
p.AddResourceConfigurator("google_container_cluster", func(r *config.Resource) {
r.Kind = "Cluster"
r.LateInitializer = config.LateInitializer{
IgnoredFields: []string{
"cluster_ipv4_cidr",
"ip_allocation_policy",
"node_config",
"node_version",
"enable_autopilot",
"workload_identity_config",
"addons_config.network_policy_config",
"addons_config.gcp_filestore_csi_driver_config",
"addons_config.gcs_fuse_csi_driver_config",
"addons_config.dns_cache_config",
"default_max_pods_per_node",
"cluster_autoscaling.enabled",
"cluster_autoscaling.resource_limits",
"enable_intranode_visibility",
"network_policy",
"enable_shielded_nodes",
},
}
config.MoveToStatus(r.TerraformResource, "node_pool")
r.Sensitive.AdditionalConnectionDetailsFn = func(attr map[string]interface{}) (map[string][]byte, error) {
name, err := common.GetField(attr, "name")
if err != nil {
return nil, err
}
endpoint, err := common.GetField(attr, "endpoint")
if err != nil {
return nil, err
}
server, err := url.Parse(endpoint)
if err != nil {
return nil, errors.Wrapf(err, "cannot parse API server endpoint")
}
// NOTE(hasheddan): the endpoint returned is just an IP address, and
// clients will default to http, causing any authentication
// information to be omitted. We set to https to allow
// authentication.
server.Scheme = "https"
caData, err := common.GetField(attr, "master_auth[0].cluster_ca_certificate")
if err != nil {
return nil, err
}
caDataBytes, err := base64.StdEncoding.DecodeString(caData)
if err != nil {
return nil, errors.Wrapf(err, "cannot serialize cluster ca data")
}
clientCertData, err := common.GetField(attr, "master_auth[0].client_certificate")
if err != nil {
return nil, err
}
clientCertDataBytes, err := base64.StdEncoding.DecodeString(clientCertData)
if err != nil {
return nil, errors.Wrapf(err, "cannot serialize cluster client cert data")
}
clientKeyData, err := common.GetField(attr, "master_auth[0].client_key")
if err != nil {
return nil, err
}
clientKeyDataBytes, err := base64.StdEncoding.DecodeString(clientKeyData)
if err != nil {
return nil, errors.Wrapf(err, "cannot serialize cluster client key data")
}
kc := clientcmdapi.Config{
Kind: "Config",
APIVersion: "v1",
Clusters: map[string]*clientcmdapi.Cluster{
name: {
Server: server.String(),
CertificateAuthorityData: caDataBytes,
},
},
AuthInfos: map[string]*clientcmdapi.AuthInfo{
name: {
ClientCertificateData: clientCertDataBytes,
ClientKeyData: clientKeyDataBytes,
},
},
Contexts: map[string]*clientcmdapi.Context{
name: {
Cluster: name,
AuthInfo: name,
},
},
CurrentContext: name,
}
kcb, err := clientcmd.Write(kc)
if err != nil {
return nil, errors.Wrap(err, "cannot serialize kubeconfig")
}
return map[string][]byte{
"kubeconfig": kcb,
}, nil
}
r.References["network"] = config.Reference{
Type: "github.com/upbound/provider-gcp/apis/compute/v1beta1.Network",
Extractor: common.PathSelfLinkExtractor,
}
r.References["subnetwork"] = config.Reference{
Type: "github.com/upbound/provider-gcp/apis/compute/v1beta1.Subnetwork",
Extractor: common.PathSelfLinkExtractor,
}
config.MarkAsRequired(r.TerraformResource, "location")
})
p.AddResourceConfigurator("google_container_node_pool", func(r *config.Resource) {
r.Kind = "NodePool"
r.References["cluster"] = config.Reference{
Type: "Cluster",
Extractor: common.ExtractResourceIDFuncPath,
}
})
}