-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathoperators.go
More file actions
411 lines (361 loc) · 13.8 KB
/
operators.go
File metadata and controls
411 lines (361 loc) · 13.8 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
// Package manifests deals with creating manifests for all manifests to be installed for the cluster
package manifests
import (
"bytes"
"context"
"encoding/base64"
"path"
"path/filepath"
"strings"
"text/template"
"time"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/yaml"
"github.com/openshift/api/features"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/rhcos"
"github.com/openshift/installer/pkg/asset/templates/content/bootkube"
"github.com/openshift/installer/pkg/asset/templates/content/manifests"
"github.com/openshift/installer/pkg/asset/tls"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/nutanix"
"github.com/openshift/installer/pkg/types/vsphere"
"github.com/openshift/library-go/pkg/crypto"
)
const (
manifestDir = "manifests"
)
var (
kubeSysConfigPath = path.Join(manifestDir, "cluster-config.yaml")
_ asset.WritableAsset = (*Manifests)(nil)
customTmplFuncs = template.FuncMap{
"indent": indent,
"add": func(i, j int) int {
return i + j
},
}
)
// Manifests generates the dependent operator config.yaml files
type Manifests struct {
KubeSysConfig *configurationObject
FileList []*asset.File
}
type genericData map[string]string
// Name returns a human friendly name for the operator
func (m *Manifests) Name() string {
return "Common Manifests"
}
// Dependencies returns all of the dependencies directly needed by a
// Manifests asset.
func (m *Manifests) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.ClusterID{},
&installconfig.InstallConfig{},
&manifests.MCO{},
&Ingress{},
&DNS{},
&Infrastructure{},
&Networking{},
&Proxy{},
&Scheduler{},
&ImageContentSourcePolicy{},
&ClusterCSIDriverConfig{},
&ImageDigestMirrorSet{},
&tls.RootCA{},
&tls.MCSCertKey{},
&tls.IRICertKey{},
&tls.IRIRegistryAuth{},
&manifests.InternalReleaseImage{},
new(rhcos.Image),
&bootkube.CVOOverrides{},
&bootkube.KubeCloudConfig{},
&bootkube.KubeSystemConfigmapRootCA{},
&bootkube.MachineConfigServerCASecret{},
&bootkube.MachineConfigServerCAConfigMap{},
&bootkube.MachineConfigServerTLSSecret{},
&bootkube.OpenshiftConfigSecretPullSecret{},
&bootkube.InternalReleaseImageTLSSecret{},
&bootkube.InternalReleaseImageRegistryAuthSecret{},
&BMCVerifyCAConfigMap{},
}
}
// Generate generates the respective operator config.yml files
func (m *Manifests) Generate(_ context.Context, dependencies asset.Parents) error {
ingress := &Ingress{}
dns := &DNS{}
network := &Networking{}
infra := &Infrastructure{}
installConfig := &installconfig.InstallConfig{}
proxy := &Proxy{}
scheduler := &Scheduler{}
imageContentSourcePolicy := &ImageContentSourcePolicy{}
clusterCSIDriverConfig := &ClusterCSIDriverConfig{}
imageDigestMirrorSet := &ImageDigestMirrorSet{}
mcoCfgTemplate := &manifests.MCO{}
bmcVerifyCAConfigMap := &BMCVerifyCAConfigMap{}
dependencies.Get(installConfig, ingress, dns, network, infra, proxy, scheduler, imageContentSourcePolicy, imageDigestMirrorSet, clusterCSIDriverConfig, mcoCfgTemplate, bmcVerifyCAConfigMap)
redactedConfig, err := redactedInstallConfig(*installConfig.Config)
if err != nil {
return errors.Wrap(err, "failed to redact install-config")
}
// mao go to kube-system config map
m.KubeSysConfig = configMap("kube-system", "cluster-config-v1", genericData{
"install-config": string(redactedConfig),
})
if m.KubeSysConfig.Metadata.Annotations == nil {
m.KubeSysConfig.Metadata.Annotations = make(map[string]string, 1)
}
m.KubeSysConfig.Metadata.Annotations["kubernetes.io/description"] = "The install-config content used to create the cluster. The cluster configuration may have evolved since installation, so check cluster configuration resources directly if you are interested in the current cluster state."
kubeSysConfigData, err := yaml.Marshal(m.KubeSysConfig)
if err != nil {
return errors.Wrap(err, "failed to create kube-system/cluster-config-v1 configmap")
}
m.FileList = []*asset.File{
{
Filename: kubeSysConfigPath,
Data: kubeSysConfigData,
},
}
m.FileList = append(m.FileList, m.generateBootKubeManifests(dependencies)...)
m.FileList = append(m.FileList, generateMCOManifest(installConfig.Config, mcoCfgTemplate.Files())...)
m.FileList = append(m.FileList, ingress.Files()...)
m.FileList = append(m.FileList, dns.Files()...)
m.FileList = append(m.FileList, network.Files()...)
m.FileList = append(m.FileList, infra.Files()...)
m.FileList = append(m.FileList, proxy.Files()...)
m.FileList = append(m.FileList, scheduler.Files()...)
m.FileList = append(m.FileList, imageContentSourcePolicy.Files()...)
m.FileList = append(m.FileList, clusterCSIDriverConfig.Files()...)
m.FileList = append(m.FileList, imageDigestMirrorSet.Files()...)
m.FileList = append(m.FileList, bmcVerifyCAConfigMap.Files()...)
asset.SortFiles(m.FileList)
return nil
}
// Files returns the files generated by the asset.
func (m *Manifests) Files() []*asset.File {
return m.FileList
}
func (m *Manifests) generateBootKubeManifests(dependencies asset.Parents) []*asset.File {
clusterID := &installconfig.ClusterID{}
installConfig := &installconfig.InstallConfig{}
mcsCertKey := &tls.MCSCertKey{}
rootCA := &tls.RootCA{}
dependencies.Get(
clusterID,
installConfig,
mcsCertKey,
rootCA,
)
templateData := &bootkubeTemplateData{
CVOCapabilities: installConfig.Config.Capabilities,
CVOClusterID: clusterID.UUID,
McsTLSCert: base64.StdEncoding.EncodeToString(mcsCertKey.Cert()),
McsTLSKey: base64.StdEncoding.EncodeToString(mcsCertKey.Key()),
PullSecretBase64: base64.StdEncoding.EncodeToString([]byte(installConfig.Config.PullSecret)),
RootCaCert: string(rootCA.Cert()),
RootCACertBase64: base64.StdEncoding.EncodeToString(rootCA.Cert()),
RootCASignerKeyBase64: base64.StdEncoding.EncodeToString(rootCA.Key()),
IsSCOS: installConfig.Config.IsSCOS(),
IsOKD: installConfig.Config.IsOKD(),
}
// Populate MCS CA(also called root-CA) specifics
if rootCAPair, err := crypto.GetCAFromBytes(rootCA.Cert(), rootCA.Key()); err == nil {
templateData.RootCAIssuerName = rootCAPair.Config.Certs[0].Issuer.CommonName
templateData.RootCANotAfter = rootCAPair.Config.Certs[0].NotAfter.Format(time.RFC3339)
templateData.RootCANotBefore = rootCAPair.Config.Certs[0].NotBefore.Format(time.RFC3339)
logrus.Infof("Successfully populated MCS CA cert information: %s %s %s", templateData.RootCAIssuerName, templateData.RootCANotAfter, templateData.RootCANotBefore)
} else {
logrus.Errorf("error populating MCS CA cert details: %v", err)
}
// Populate MCS TLS Cert specifics
if MCSTLSCertPair, err := crypto.GetCAFromBytes(mcsCertKey.Cert(), mcsCertKey.Key()); err == nil {
// Hostname annottation need a little massaging
hostnames := sets.Set[string]{}
for _, ip := range MCSTLSCertPair.Config.Certs[0].IPAddresses {
hostnames.Insert(ip.String())
}
for _, dnsName := range MCSTLSCertPair.Config.Certs[0].DNSNames {
hostnames.Insert(dnsName)
}
templateData.McsHostName = strings.Join(sets.List(hostnames), ",")
templateData.McsTLSCertNotAfter = MCSTLSCertPair.Config.Certs[0].NotAfter.Format(time.RFC3339)
templateData.McsTLSCertNotBefore = MCSTLSCertPair.Config.Certs[0].NotBefore.Format(time.RFC3339)
logrus.Infof("Successfully populated MCS TLS cert information: %s %s %s", templateData.RootCAIssuerName, templateData.RootCANotAfter, templateData.RootCANotBefore)
} else {
logrus.Errorf("error populating MCS TLS cert details: %v", err)
}
files := []*asset.File{}
for _, a := range []asset.WritableAsset{
&bootkube.CVOOverrides{},
&bootkube.KubeCloudConfig{},
&bootkube.MachineConfigServerCASecret{},
&bootkube.MachineConfigServerCAConfigMap{},
&bootkube.KubeSystemConfigmapRootCA{},
&bootkube.MachineConfigServerTLSSecret{},
&bootkube.OpenshiftConfigSecretPullSecret{},
} {
dependencies.Get(a)
for _, f := range a.Files() {
files = append(files, &asset.File{
Filename: path.Join(manifestDir, strings.TrimSuffix(filepath.Base(f.Filename), ".template")),
Data: applyTemplateData(f.Data, templateData),
})
}
}
if installConfig.Config.EnabledFeatureGates().Enabled(features.FeatureGateNoRegistryClusterInstall) {
iri := &manifests.InternalReleaseImage{}
dependencies.Get(iri)
// Skip if InternalReleaseImage manifest wasn't found.
if len(iri.FileList) > 0 {
files = append(files, appendIRIcerts(dependencies))
files = append(files, appendIRIRegistryAuth(dependencies))
}
}
return files
}
func appendIRIcerts(dependencies asset.Parents) *asset.File {
iriCertKey := &tls.IRICertKey{}
iriTLSSecret := &bootkube.InternalReleaseImageTLSSecret{}
dependencies.Get(iriCertKey, iriTLSSecret)
f := iriTLSSecret.Files()[0]
templateData := struct {
IriTLSCert string
IriTLSKey string
}{
IriTLSCert: base64.StdEncoding.EncodeToString(iriCertKey.Cert()),
IriTLSKey: base64.StdEncoding.EncodeToString(iriCertKey.Key()),
}
fileData := applyTemplateData(f.Data, templateData)
return &asset.File{
Filename: path.Join(manifestDir, strings.TrimSuffix(filepath.Base(f.Filename), ".template")),
Data: fileData,
}
}
// appendIRIRegistryAuth renders the IRI registry auth secret template with the generated credentials.
func appendIRIRegistryAuth(dependencies asset.Parents) *asset.File {
iriAuth := &tls.IRIRegistryAuth{}
iriAuthSecret := &bootkube.InternalReleaseImageRegistryAuthSecret{}
dependencies.Get(iriAuth, iriAuthSecret)
f := iriAuthSecret.Files()[0]
templateData := struct {
IriRegistryHtpasswd string
IriRegistryPassword string
}{
IriRegistryHtpasswd: base64.StdEncoding.EncodeToString([]byte(iriAuth.HtpasswdContent)),
IriRegistryPassword: base64.StdEncoding.EncodeToString([]byte(iriAuth.Password)),
}
fileData := applyTemplateData(f.Data, templateData)
return &asset.File{
Filename: path.Join(manifestDir, strings.TrimSuffix(filepath.Base(f.Filename), ".template")),
Data: fileData,
}
}
func applyTemplateData(data []byte, templateData interface{}) []byte {
template := template.Must(template.New("template").Funcs(customTmplFuncs).Parse(string(data)))
buf := &bytes.Buffer{}
if err := template.Execute(buf, templateData); err != nil {
panic(err)
}
return buf.Bytes()
}
// Load returns the manifests asset from disk.
func (m *Manifests) Load(f asset.FileFetcher) (bool, error) {
yamlFileList, err := f.FetchByPattern(filepath.Join(manifestDir, "*.yaml"))
if err != nil {
return false, errors.Wrap(err, "failed to load *.yaml files")
}
ymlFileList, err := f.FetchByPattern(filepath.Join(manifestDir, "*.yml"))
if err != nil {
return false, errors.Wrap(err, "failed to load *.yml files")
}
jsonFileList, err := f.FetchByPattern(filepath.Join(manifestDir, "*.json"))
if err != nil {
return false, errors.Wrap(err, "failed to load *.json files")
}
fileList := append(yamlFileList, ymlFileList...)
fileList = append(fileList, jsonFileList...)
if len(fileList) == 0 {
return false, nil
}
kubeSysConfig := &configurationObject{}
var found bool
for _, file := range fileList {
if file.Filename == kubeSysConfigPath {
if err := yaml.Unmarshal(file.Data, kubeSysConfig); err != nil {
return false, errors.Wrapf(err, "failed to unmarshal %s", kubeSysConfigPath)
}
found = true
}
}
if !found {
return false, nil
}
m.FileList, m.KubeSysConfig = fileList, kubeSysConfig
asset.SortFiles(m.FileList)
return true, nil
}
func redactedInstallConfig(config types.InstallConfig) ([]byte, error) {
newConfig := config
newConfig.PullSecret = ""
switch {
case newConfig.Platform.VSphere != nil:
p := config.VSphere
newVCenters := make([]vsphere.VCenter, len(p.VCenters))
for i, v := range p.VCenters {
newVCenters[i].Server = v.Server
newVCenters[i].Datacenters = v.Datacenters
}
newVSpherePlatform := vsphere.Platform{
DeprecatedVCenter: p.DeprecatedVCenter,
DeprecatedUsername: "",
DeprecatedPassword: "",
DeprecatedDatacenter: p.DeprecatedDatacenter,
DeprecatedDefaultDatastore: p.DeprecatedDefaultDatastore,
DeprecatedFolder: p.DeprecatedFolder,
DeprecatedCluster: p.DeprecatedCluster,
DeprecatedResourcePool: p.DeprecatedResourcePool,
ClusterOSImage: p.ClusterOSImage,
DeprecatedAPIVIP: p.DeprecatedAPIVIP,
APIVIPs: p.APIVIPs,
DeprecatedIngressVIP: p.DeprecatedIngressVIP,
IngressVIPs: p.IngressVIPs,
DefaultMachinePlatform: p.DefaultMachinePlatform,
DeprecatedNetwork: p.DeprecatedNetwork,
DiskType: p.DiskType,
VCenters: newVCenters,
FailureDomains: p.FailureDomains,
}
newConfig.Platform.VSphere = &newVSpherePlatform
case newConfig.Platform.Nutanix != nil:
p := config.Nutanix
newPrismCentral := nutanix.PrismCentral{
Endpoint: p.PrismCentral.Endpoint,
Username: "",
Password: "",
}
newNutanixPlatform := nutanix.Platform{
PrismCentral: newPrismCentral,
PrismElements: p.PrismElements,
ClusterOSImage: p.ClusterOSImage,
PreloadedOSImageName: p.PreloadedOSImageName,
DeprecatedAPIVIP: p.DeprecatedAPIVIP,
APIVIPs: p.APIVIPs,
DeprecatedIngressVIP: p.DeprecatedIngressVIP,
IngressVIPs: p.IngressVIPs,
DefaultMachinePlatform: p.DefaultMachinePlatform,
SubnetUUIDs: p.SubnetUUIDs,
LoadBalancer: p.LoadBalancer,
FailureDomains: p.FailureDomains,
PrismAPICallTimeout: p.PrismAPICallTimeout,
}
newConfig.Platform.Nutanix = &newNutanixPlatform
}
return yaml.Marshal(newConfig)
}
func indent(indention int, v string) string {
newline := "\n" + strings.Repeat(" ", indention)
return strings.Replace(v, "\n", newline, -1)
}