-
Notifications
You must be signed in to change notification settings - Fork 207
/
output.go
97 lines (81 loc) · 2.92 KB
/
output.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package engine
import (
"fmt"
"path"
"github.com/Azure/agentbaker/pkg/agent/datamodel"
"github.com/Azure/agentbaker/pkg/aks-engine/api"
"github.com/Azure/agentbaker/pkg/aks-engine/helpers"
)
// ArtifactWriter represents the object that writes artifacts
type ArtifactWriter struct{}
// WriteTLSArtifacts saves TLS certificates and keys to the server filesystem
func (w *ArtifactWriter) WriteTLSArtifacts(containerService *datamodel.ContainerService, apiVersion, template, parameters, artifactsDir string, certsGenerated bool, parametersOnly bool,
cloudSpecConfig *datamodel.AzureEnvironmentSpecConfig) error {
if len(artifactsDir) == 0 {
artifactsDir = fmt.Sprintf("%s-%s", containerService.Properties.OrchestratorProfile.OrchestratorType, containerService.Properties.GetClusterID())
artifactsDir = path.Join("_output", artifactsDir)
}
f := &helpers.FileSaver{}
// convert back the API object, and write it
var b []byte
var err error
if !parametersOnly {
apiloader := &api.Apiloader{}
b, err = apiloader.SerializeContainerService(containerService, apiVersion)
if err != nil {
return err
}
if e := f.SaveFile(artifactsDir, "apimodel.json", b); e != nil {
return e
}
if e := f.SaveFileString(artifactsDir, "azuredeploy.json", template); e != nil {
return e
}
}
if e := f.SaveFileString(artifactsDir, "azuredeploy.parameters.json", parameters); e != nil {
return e
}
if !certsGenerated {
return nil
}
properties := containerService.Properties
if properties.OrchestratorProfile.IsKubernetes() {
directory := path.Join(artifactsDir, "kubeconfig")
var locations []string
if containerService.Location != "" {
locations = []string{containerService.Location}
} else {
locations = helpers.GetAzureLocations()
}
for _, location := range locations {
b, gkcerr := GenerateKubeConfig(properties, location, cloudSpecConfig)
if gkcerr != nil {
return gkcerr
}
if e := f.SaveFileString(directory, fmt.Sprintf("kubeconfig.%s.json", location), b); e != nil {
return e
}
}
if e := f.SaveFileString(artifactsDir, "ca.crt", properties.CertificateProfile.CaCertificate); e != nil {
return e
}
if e := f.SaveFileString(artifactsDir, "apiserver.crt", properties.CertificateProfile.APIServerCertificate); e != nil {
return e
}
if e := f.SaveFileString(artifactsDir, "client.key", properties.CertificateProfile.ClientPrivateKey); e != nil {
return e
}
if e := f.SaveFileString(artifactsDir, "client.crt", properties.CertificateProfile.ClientCertificate); e != nil {
return e
}
if e := f.SaveFileString(artifactsDir, "kubectlClient.key", properties.CertificateProfile.KubeConfigPrivateKey); e != nil {
return e
}
if e := f.SaveFileString(artifactsDir, "kubectlClient.crt", properties.CertificateProfile.KubeConfigCertificate); e != nil {
return e
}
}
return nil
}