-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
213 lines (183 loc) · 6.98 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
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
package kargo
import (
"fmt"
)
const (
// FieldTagKargo is used to defining kargo flags.
// Currently, this is used to exclude the field from the field-to-flag conversion.
// Example: Name `yaml:"name" kargo:""`
FieldTagKargo = "kargo"
// FieldTagArgoCD is used to defining helm-upgrade flags
FieldTagCompose = "compose"
FieldTagHelm = "helm"
FieldTagKustomize = "kustomize"
FieldTagKompose = "kompose"
// FieldTagArgoCDApp is used to defining argocd-app-create flags
FieldTagArgoCDApp = "argocd-app"
)
type Config struct {
// Name is the application name.
// It defaults to the basename of the path if
// kargo is run as a command.
Name string `yaml:"name" argocd-app:",arg"`
Path string `yaml:"path" kargo:""`
PathFrom string `yaml:"pathFrom" kargo:""`
Env []Env `yaml:"env" argocd-app:"plugin-env"`
Compose *Compose `yaml:"compose"`
Kompose *Kompose `yaml:"kompose"`
Kustomize *Kustomize `yaml:"kustomize"`
Helm *Helm `yaml:"helm"`
ArgoCD *ArgoCD `yaml:"argocd"`
}
type Env struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
ValueFrom string `yaml:"valueFrom"`
}
func (e Env) KargoValue(get GetValue) (string, error) {
v := e.Value
if e.ValueFrom != "" {
var err error
v, err = get(e.ValueFrom)
if err != nil {
return "", err
}
}
return fmt.Sprintf("%s=%s", e.Name, v), nil
}
type Compose struct {
EnableVals bool `yaml:"enableVals" kargo:""`
}
type Kompose struct {
EnableVals bool `yaml:"enableVals" kargo:""`
}
const (
KustomizeStrategyBuildAndKubectlApply = "BuildAndKubectlApply"
KustomizeStrategySetImageAndCreatePR = "SetImageAndCreatePullRequest"
)
type Kustomize struct {
// Strategy is the strategy to be used for the deployment.
//
// The supported values are:
// - BuildAndKubectlApply
// - SetImageAndCreatePullRequest
//
// BuildAndKubectlApply is the default strategy.
// It runs kustomize build and kubectl apply to deploy the application.
//
// SetImageAndCreatePullRequest runs kustomize edit set image and creates a pull request.
// It's useful to trigger a deployment workflow in CI/CD.
Strategy string `yaml:"strategy" kargo:""`
Images KustomizeImages `yaml:"images" argocd-app:"kustomize-image"`
Git KustomizeGit `yaml:"git" kargo:""`
}
type KustomizeGit struct {
Repo string `yaml:"repo" kargo:""`
Branch string `yaml:"branch" kargo:""`
Path string `yaml:"path" kargo:""`
}
type KustomizeImages []KustomizeImage
func (i KustomizeImages) KargoAppendArgs(args *Args, key string) (*Args, error) {
var images *Args
for _, img := range i {
var s *Args
s = s.AppendStrings(img.Name)
if img.NewName != "" {
s = s.AppendStrings("=" + img.NewName)
}
if img.NewTag != "" {
s = s.AppendStrings(":")
s = s.AppendStrings(img.NewTag)
} else if img.NewDigestFrom != "" {
s = s.AppendStrings("@")
s = s.AppendValueFromOutput(img.NewDigestFrom)
} else if img.NewTagFrom != "" {
s = s.AppendStrings(":")
s = s.AppendValueFromOutput(img.NewTagFrom)
} else {
return nil, fmt.Errorf("either newTag or newDigestFrom must be set")
}
images = images.Append(NewJoin(s))
}
if key == "argocd" {
args = args.Append(args, "--kustomize-image")
}
args = args.Append(args, images)
return args, nil
}
var _ KargoArgsAppender = KustomizeImages{}
type KustomizeImage struct {
Name string `yaml:"name"`
NewName string `yaml:"newName"`
NewTag string `yaml:"newTag"`
NewTagFrom string `yaml:"newTagFrom"`
NewDigestFrom string `yaml:"newDigestFrom"`
}
type Helm struct {
Repo string `yaml:"repo" helm:""`
Chart string `yaml:"chart" helm:"" argocd-app:"helm-chart"`
Version string `yaml:"version" argocd-app:"revision"`
Set []Set `yaml:"set" helm:"set" argocd-app:"helm-set"`
ValuesFiles []string `yaml:"valuesFiles" helm:"values" argocd-app:"values"`
}
func (s Set) KargoValue(get GetValue) (string, error) {
return fmt.Sprintf("%s=%s", s.Name, s.Value), nil
}
type ArgoCD struct {
Repo string `yaml:"repo" kargo:""`
// Branch is the branch to be used for the deployment.
// This isn't part of the arguments for argocd-repo-add because
// it doesn't support branch.
// However, we use it when you want to push manifests to a branch
// and trigger a deployment.
Branch string `yaml:"branch" kargo:""`
RepoFrom string `yaml:"repoFrom" kargo:""`
RepoSSHPrivateKeyPath string `yaml:"repoSSHPrivateKeyPath" kargo:""`
RepoSSHPrivateKeyPathFrom string `yaml:"repoSSHPrivateKeyPathFrom" kargo:""`
Path string `yaml:"path" kargo:""`
PathFrom string `yaml:"pathFrom" kargo:""`
Upload []Upload `yaml:"upload" kargo:""`
DirRecurse bool `yaml:"dirRecurse" argocd-app:"directory-recurse,paramless"`
// Server is the ArgoCD server to be used for the deployment.
Server string `yaml:"server" kargo:""`
// ServerFrom is the key to be used to get the ArgoCD server from the environment.
ServerFrom string `yaml:"serverFrom" kargo:""`
// Username is the username to be used for the deployment.
Username string `yaml:"username" kargo:""`
// UsernameFrom is the key to be used to get the username from the environment.
UsernameFrom string `yaml:"usernameFrom" kargo:""`
// Password is the password to be used for the deployment.
Password string `yaml:"password" kargo:""`
// PasswordFrom is the key to be used to get the password from the environment.
PasswordFrom string `yaml:"passwordFrom" kargo:""`
// Insecure is set to true if the user wants to skip TLS verification.
Insecure bool `yaml:"insecure" kargo:""`
// InsecureFrom is the key to be used to get the insecure flag from the environment.
InsecureFrom string `yaml:"insecureFrom" kargo:""`
// Project is the ArgoCD project to be used for the deployment.
Project string `yaml:"project" argocd-app:"project"`
// Push is set to true if the user wants kargo to automatically
// - git-clone the repo
// - git-add the files in the config.Path
// - git-commit
// - git-push
// so that it triggers the deployment.
Push bool `yaml:"push" kargo:""`
// DestName is the name of the K8s cluster where the deployment is to be done.
DestName string `yaml:"name" kargo:""`
// DestNameFrom is the key to be used to get the target K8s cluster name from the environment.
DestNameFrom string `yaml:"nameFrom" kargo:""`
// DestNamespace is the namespace to be used for the deployment.
DestNamespace string `yaml:"namespace" kargo:""`
// DestServer is the Kubernetes API endpoint of the cluster where the deployment is to be done.
DestServer string `yaml:"destServer" kargo:""`
// DestServerFrom is the key to be used to get the target Kubernetes API endpoint from the environment.
DestServerFrom string `yaml:"destServerFrom" kargo:""`
// ConfigManagementPlugin is the config management plugin to be used.
ConfigManagementPlugin string `yaml:"configManagementPlugin" argocd-app:"config-management-plugin"`
}
type Upload struct {
Local string `yaml:"local" kargo:""`
Remote string `yaml:"remote" kargo:""`
}
type GetValue func(key string) (string, error)