forked from argoproj/argo-cd
/
repository.go
691 lines (639 loc) · 20 KB
/
repository.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
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
package repository
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"github.com/TomOnTime/utfutil"
argoexec "github.com/argoproj/pkg/exec"
"github.com/ghodss/yaml"
"github.com/google/go-jsonnet"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/semaphore"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"github.com/argoproj/argo-cd/common"
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/util"
"github.com/argoproj/argo-cd/util/cache"
"github.com/argoproj/argo-cd/util/config"
"github.com/argoproj/argo-cd/util/git"
"github.com/argoproj/argo-cd/util/helm"
"github.com/argoproj/argo-cd/util/ksonnet"
"github.com/argoproj/argo-cd/util/kube"
"github.com/argoproj/argo-cd/util/kustomize"
)
const (
PluginEnvAppName = "ARGOCD_APP_NAME"
PluginEnvAppNamespace = "ARGOCD_APP_NAMESPACE"
)
// Service implements ManifestService interface
type Service struct {
repoLock *util.KeyLock
gitFactory git.ClientFactory
cache *cache.Cache
parallelismLimitSemaphore *semaphore.Weighted
}
// NewService returns a new instance of the Manifest service
func NewService(gitFactory git.ClientFactory, cache *cache.Cache, parallelismLimit int64) *Service {
var parallelismLimitSemaphore *semaphore.Weighted
if parallelismLimit > 0 {
parallelismLimitSemaphore = semaphore.NewWeighted(parallelismLimit)
}
return &Service{
parallelismLimitSemaphore: parallelismLimitSemaphore,
repoLock: util.NewKeyLock(),
gitFactory: gitFactory,
cache: cache,
}
}
// ListDir lists the contents of a GitHub repo
func (s *Service) ListDir(ctx context.Context, q *ListDirRequest) (*FileList, error) {
gitClient, commitSHA, err := s.newClientResolveRevision(q.Repo, q.Revision)
if err != nil {
return nil, err
}
if files, err := s.cache.GetGitListDir(commitSHA, q.Path); err == nil {
log.Infof("listdir cache hit: %s/%s", commitSHA, q.Path)
return &FileList{Items: files}, nil
}
s.repoLock.Lock(gitClient.Root())
defer s.repoLock.Unlock(gitClient.Root())
commitSHA, err = checkoutRevision(gitClient, commitSHA)
if err != nil {
return nil, err
}
lsFiles, err := gitClient.LsFiles(q.Path)
if err != nil {
return nil, err
}
res := FileList{Items: lsFiles}
err = s.cache.SetListDir(commitSHA, q.Path, res.Items)
if err != nil {
log.Warnf("listdir cache set error %s/%s: %v", commitSHA, q.Path, err)
}
return &res, nil
}
func (s *Service) GetFile(ctx context.Context, q *GetFileRequest) (*GetFileResponse, error) {
gitClient, commitSHA, err := s.newClientResolveRevision(q.Repo, q.Revision)
if err != nil {
return nil, err
}
if data, err := s.cache.GetGitFile(commitSHA, q.Path); err == nil {
log.Infof("getfile cache hit: %s/%s", commitSHA, q.Path)
return &GetFileResponse{Data: data}, nil
}
s.repoLock.Lock(gitClient.Root())
defer s.repoLock.Unlock(gitClient.Root())
commitSHA, err = checkoutRevision(gitClient, commitSHA)
if err != nil {
return nil, err
}
data, err := ioutil.ReadFile(filepath.Join(gitClient.Root(), q.Path))
if err != nil {
return nil, err
}
res := GetFileResponse{
Data: data,
}
err = s.cache.SetGitFile(commitSHA, q.Path, data)
if err != nil {
log.Warnf("getfile cache set error %s/%s: %v", commitSHA, q.Path, err)
}
return &res, nil
}
func (s *Service) GenerateManifest(c context.Context, q *ManifestRequest) (*ManifestResponse, error) {
gitClient, commitSHA, err := s.newClientResolveRevision(q.Repo, q.Revision)
if err != nil {
return nil, err
}
getCached := func() *ManifestResponse {
var res ManifestResponse
if !q.NoCache {
err = s.cache.GetManifests(commitSHA, q.ApplicationSource, q.Namespace, q.AppLabelKey, q.AppLabelValue, &res)
if err == nil {
log.Infof("manifest cache hit: %s/%s", q.ApplicationSource.String(), commitSHA)
return &res
}
if err != cache.ErrCacheMiss {
log.Warnf("manifest cache error %s: %v", q.ApplicationSource.String(), err)
} else {
log.Infof("manifest cache miss: %s/%s", q.ApplicationSource.String(), commitSHA)
}
}
return nil
}
cached := getCached()
if cached != nil {
return cached, nil
}
s.repoLock.Lock(gitClient.Root())
defer s.repoLock.Unlock(gitClient.Root())
cached = getCached()
if cached != nil {
return cached, nil
}
if s.parallelismLimitSemaphore != nil {
err = s.parallelismLimitSemaphore.Acquire(c, 1)
if err != nil {
return nil, err
}
defer s.parallelismLimitSemaphore.Release(1)
}
commitSHA, err = checkoutRevision(gitClient, commitSHA)
if err != nil {
return nil, err
}
appPath := filepath.Join(gitClient.Root(), q.ApplicationSource.Path)
genRes, err := GenerateManifests(appPath, q)
if err != nil {
return nil, err
}
res := *genRes
res.Revision = commitSHA
err = s.cache.SetManifests(commitSHA, q.ApplicationSource, q.Namespace, q.AppLabelKey, q.AppLabelValue, &res)
if err != nil {
log.Warnf("manifest cache set error %s/%s: %v", q.ApplicationSource.String(), commitSHA, err)
}
return &res, nil
}
// GenerateManifests generates manifests from a path
func GenerateManifests(appPath string, q *ManifestRequest) (*ManifestResponse, error) {
var targetObjs []*unstructured.Unstructured
var dest *v1alpha1.ApplicationDestination
appSourceType, err := GetAppSourceType(q.ApplicationSource, appPath)
creds := newCreds(q.Repo)
switch appSourceType {
case v1alpha1.ApplicationSourceTypeKsonnet:
targetObjs, dest, err = ksShow(q.AppLabelKey, appPath, q.ApplicationSource.Ksonnet)
case v1alpha1.ApplicationSourceTypeHelm:
h := helm.NewHelmApp(appPath, q.HelmRepos)
err := h.Init()
if err != nil {
return nil, err
}
defer h.Dispose()
targetObjs, err = h.Template(q.AppLabelValue, q.Namespace, q.ApplicationSource.Helm)
if err != nil {
if !helm.IsMissingDependencyErr(err) {
return nil, err
}
err = h.DependencyBuild()
if err != nil {
return nil, err
}
targetObjs, err = h.Template(q.AppLabelValue, q.Namespace, q.ApplicationSource.Helm)
if err != nil {
return nil, err
}
}
case v1alpha1.ApplicationSourceTypeKustomize:
k := kustomize.NewKustomizeApp(appPath, creds)
targetObjs, _, _, err = k.Build(q.ApplicationSource.Kustomize)
case v1alpha1.ApplicationSourceTypePlugin:
targetObjs, err = runConfigManagementPlugin(appPath, q, creds, q.Plugins)
case v1alpha1.ApplicationSourceTypeDirectory:
var directory *v1alpha1.ApplicationSourceDirectory
if directory = q.ApplicationSource.Directory; directory == nil {
directory = &v1alpha1.ApplicationSourceDirectory{}
}
targetObjs, err = findManifests(appPath, *directory)
}
if err != nil {
return nil, err
}
manifests := make([]string, 0)
for _, obj := range targetObjs {
var targets []*unstructured.Unstructured
if obj.IsList() {
err = obj.EachListItem(func(object runtime.Object) error {
unstructuredObj, ok := object.(*unstructured.Unstructured)
if ok {
targets = append(targets, unstructuredObj)
return nil
}
return fmt.Errorf("resource list item has unexpected type")
})
if err != nil {
return nil, err
}
} else if isNullList(obj) {
// noop
} else {
targets = []*unstructured.Unstructured{obj}
}
for _, target := range targets {
if q.AppLabelKey != "" && q.AppLabelValue != "" && !kube.IsCRD(target) {
err = kube.SetAppInstanceLabel(target, q.AppLabelKey, q.AppLabelValue)
if err != nil {
return nil, err
}
}
manifestStr, err := json.Marshal(target.Object)
if err != nil {
return nil, err
}
manifests = append(manifests, string(manifestStr))
}
}
res := ManifestResponse{
Manifests: manifests,
SourceType: string(appSourceType),
}
if dest != nil {
res.Namespace = dest.Namespace
res.Server = dest.Server
}
return &res, nil
}
// tempRepoPath returns a formulated temporary directory location to clone a repository
func tempRepoPath(repo string) string {
return filepath.Join(os.TempDir(), strings.Replace(repo, "/", "_", -1))
}
// GetAppSourceType returns explicit application source type or examines a directory and determines its application source type
func GetAppSourceType(source *v1alpha1.ApplicationSource, appDirPath string) (v1alpha1.ApplicationSourceType, error) {
appSourceType, err := source.ExplicitType()
if err != nil {
return "", err
}
if appSourceType != nil {
return *appSourceType, nil
}
if pathExists(appDirPath, "app.yaml") {
return v1alpha1.ApplicationSourceTypeKsonnet, nil
}
if pathExists(appDirPath, "Chart.yaml") {
return v1alpha1.ApplicationSourceTypeHelm, nil
}
for _, kustomization := range kustomize.KustomizationNames {
if pathExists(appDirPath, kustomization) {
return v1alpha1.ApplicationSourceTypeKustomize, nil
}
}
return v1alpha1.ApplicationSourceTypeDirectory, nil
}
// isNullList checks if the object is a "List" type where items is null instead of an empty list.
// Handles a corner case where obj.IsList() returns false when a manifest is like:
// ---
// apiVersion: v1
// items: null
// kind: ConfigMapList
func isNullList(obj *unstructured.Unstructured) bool {
if _, ok := obj.Object["spec"]; ok {
return false
}
if _, ok := obj.Object["status"]; ok {
return false
}
field, ok := obj.Object["items"]
if !ok {
return false
}
return field == nil
}
// checkoutRevision is a convenience function to initialize a repo, fetch, and checkout a revision
// Returns the 40 character commit SHA after the checkout has been performed
func checkoutRevision(gitClient git.Client, commitSHA string) (string, error) {
err := gitClient.Init()
if err != nil {
return "", status.Errorf(codes.Internal, "Failed to initialize git repo: %v", err)
}
err = gitClient.Fetch()
if err != nil {
return "", status.Errorf(codes.Internal, "Failed to fetch git repo: %v", err)
}
err = gitClient.Checkout(commitSHA)
if err != nil {
return "", status.Errorf(codes.Internal, "Failed to checkout %s: %v", commitSHA, err)
}
return gitClient.CommitSHA()
}
// ksShow runs `ks show` in an app directory after setting any component parameter overrides
func ksShow(appLabelKey, appPath string, ksonnetOpts *v1alpha1.ApplicationSourceKsonnet) ([]*unstructured.Unstructured, *v1alpha1.ApplicationDestination, error) {
ksApp, err := ksonnet.NewKsonnetApp(appPath)
if err != nil {
return nil, nil, status.Errorf(codes.FailedPrecondition, "unable to load application from %s: %v", appPath, err)
}
if ksonnetOpts == nil {
return nil, nil, status.Errorf(codes.InvalidArgument, "Ksonnet environment not set")
}
for _, override := range ksonnetOpts.Parameters {
err = ksApp.SetComponentParams(ksonnetOpts.Environment, override.Component, override.Name, override.Value)
if err != nil {
return nil, nil, err
}
}
dest, err := ksApp.Destination(ksonnetOpts.Environment)
if err != nil {
return nil, nil, status.Errorf(codes.InvalidArgument, err.Error())
}
targetObjs, err := ksApp.Show(ksonnetOpts.Environment)
if err == nil && appLabelKey == common.LabelKeyLegacyApplicationName {
// Address https://github.com/ksonnet/ksonnet/issues/707
for _, d := range targetObjs {
kube.UnsetLabel(d, "ksonnet.io/component")
}
}
if err != nil {
return nil, nil, err
}
return targetObjs, dest, nil
}
var manifestFile = regexp.MustCompile(`^.*\.(yaml|yml|json|jsonnet)$`)
// findManifests looks at all yaml files in a directory and unmarshals them into a list of unstructured objects
func findManifests(appPath string, directory v1alpha1.ApplicationSourceDirectory) ([]*unstructured.Unstructured, error) {
var objs []*unstructured.Unstructured
err := filepath.Walk(appPath, func(path string, f os.FileInfo, err error) error {
if err != nil {
return err
}
if f.IsDir() {
if path != appPath && !directory.Recurse {
return filepath.SkipDir
} else {
return nil
}
}
if !manifestFile.MatchString(f.Name()) {
return nil
}
out, err := utfutil.ReadFile(path, utfutil.UTF8)
if err != nil {
return err
}
if strings.HasSuffix(f.Name(), ".json") {
var obj unstructured.Unstructured
err = json.Unmarshal(out, &obj)
if err != nil {
return status.Errorf(codes.FailedPrecondition, "Failed to unmarshal %q: %v", f.Name(), err)
}
objs = append(objs, &obj)
} else if strings.HasSuffix(f.Name(), ".jsonnet") {
vm := makeJsonnetVm(directory.Jsonnet)
vm.Importer(&jsonnet.FileImporter{
JPaths: []string{appPath},
})
jsonStr, err := vm.EvaluateSnippet(f.Name(), string(out))
if err != nil {
return status.Errorf(codes.FailedPrecondition, "Failed to evaluate jsonnet %q: %v", f.Name(), err)
}
// attempt to unmarshal either array or single object
var jsonObjs []*unstructured.Unstructured
err = json.Unmarshal([]byte(jsonStr), &jsonObjs)
if err == nil {
objs = append(objs, jsonObjs...)
} else {
var jsonObj unstructured.Unstructured
err = json.Unmarshal([]byte(jsonStr), &jsonObj)
if err != nil {
return status.Errorf(codes.FailedPrecondition, "Failed to unmarshal generated json %q: %v", f.Name(), err)
}
objs = append(objs, &jsonObj)
}
} else {
yamlObjs, err := kube.SplitYAML(string(out))
if err != nil {
if len(yamlObjs) > 0 {
// If we get here, we had a multiple objects in a single YAML file which had some
// valid k8s objects, but errors parsing others (within the same file). It's very
// likely the user messed up a portion of the YAML, so report on that.
return status.Errorf(codes.FailedPrecondition, "Failed to unmarshal %q: %v", f.Name(), err)
}
// Otherwise, it might be a unrelated YAML file which we will ignore
return nil
}
objs = append(objs, yamlObjs...)
}
return nil
})
if err != nil {
return nil, err
}
return objs, nil
}
func makeJsonnetVm(sourceJsonnet v1alpha1.ApplicationSourceJsonnet) *jsonnet.VM {
vm := jsonnet.MakeVM()
for _, arg := range sourceJsonnet.TLAs {
if arg.Code {
vm.TLACode(arg.Name, arg.Value)
} else {
vm.TLAVar(arg.Name, arg.Value)
}
}
for _, extVar := range sourceJsonnet.ExtVars {
if extVar.Code {
vm.ExtCode(extVar.Name, extVar.Value)
} else {
vm.ExtVar(extVar.Name, extVar.Value)
}
}
return vm
}
// pathExists reports whether the file or directory at the named concatenation of paths exists.
func pathExists(ss ...string) bool {
name := filepath.Join(ss...)
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// newClientResolveRevision is a helper to perform the common task of instantiating a git client
// and resolving a revision to a commit SHA
func (s *Service) newClientResolveRevision(repo *v1alpha1.Repository, revision string) (git.Client, string, error) {
repoURL := git.NormalizeGitURL(repo.Repo)
appRepoPath := tempRepoPath(repoURL)
gitClient, err := s.gitFactory.NewClient(repo.Repo, appRepoPath, repo.Username, repo.Password, repo.SSHPrivateKey, repo.InsecureIgnoreHostKey)
if err != nil {
return nil, "", err
}
commitSHA, err := gitClient.LsRemote(revision)
if err != nil {
return nil, "", err
}
return gitClient, commitSHA, nil
}
func runCommand(command v1alpha1.Command, path string, env []string) (string, error) {
if len(command.Command) == 0 {
return "", fmt.Errorf("Command is empty")
}
cmd := exec.Command(command.Command[0], append(command.Command[1:], command.Args...)...)
cmd.Env = env
cmd.Dir = path
return argoexec.RunCommandExt(cmd, config.CmdOpts())
}
func runConfigManagementPlugin(appPath string, q *ManifestRequest, creds git.Creds, plugins []*v1alpha1.ConfigManagementPlugin) ([]*unstructured.Unstructured, error) {
var plugin *v1alpha1.ConfigManagementPlugin
for i := range plugins {
if plugins[i].Name == q.ApplicationSource.Plugin.Name {
plugin = plugins[i]
break
}
}
if plugin == nil {
return nil, fmt.Errorf("Config management plugin with name '%s' is not supported.", q.ApplicationSource.Plugin.Name)
}
env := append(os.Environ(), fmt.Sprintf("%s=%s", PluginEnvAppName, q.AppLabelValue), fmt.Sprintf("%s=%s", PluginEnvAppNamespace, q.Namespace))
if creds != nil {
closer, environ, err := creds.Environ()
if err != nil {
return nil, err
}
defer func() { _ = closer.Close() }()
env = append(env, environ...)
}
if plugin.Init != nil {
_, err := runCommand(*plugin.Init, appPath, env)
if err != nil {
return nil, err
}
}
out, err := runCommand(plugin.Generate, appPath, env)
if err != nil {
return nil, err
}
return kube.SplitYAML(out)
}
func (s *Service) GetAppDetails(ctx context.Context, q *RepoServerAppDetailsQuery) (*RepoAppDetailsResponse, error) {
revision := q.Revision
if revision == "" {
revision = "HEAD"
}
gitClient, commitSHA, err := s.newClientResolveRevision(q.Repo, revision)
if err != nil {
return nil, err
}
getCached := func() *RepoAppDetailsResponse {
var res RepoAppDetailsResponse
err = s.cache.GetAppDetails(commitSHA, q.Path, q.valueFiles(), &res)
if err == nil {
log.Infof("manifest cache hit: %s/%s", commitSHA, q.Path)
return &res
}
if err != cache.ErrCacheMiss {
log.Warnf("manifest cache error %s: %v", commitSHA, q.Path)
} else {
log.Infof("manifest cache miss: %s/%s", commitSHA, q.Path)
}
return nil
}
cached := getCached()
if cached != nil {
return cached, nil
}
s.repoLock.Lock(gitClient.Root())
defer s.repoLock.Unlock(gitClient.Root())
cached = getCached()
if cached != nil {
return cached, nil
}
commitSHA, err = checkoutRevision(gitClient, commitSHA)
if err != nil {
return nil, err
}
appPath := filepath.Join(gitClient.Root(), q.Path)
appSourceType, err := GetAppSourceType(&v1alpha1.ApplicationSource{}, appPath)
if err != nil {
return nil, err
}
res := RepoAppDetailsResponse{
Type: string(appSourceType),
}
switch appSourceType {
case v1alpha1.ApplicationSourceTypeKsonnet:
var ksonnetAppSpec KsonnetAppSpec
data, err := ioutil.ReadFile(filepath.Join(appPath, "app.yaml"))
if err != nil {
return nil, err
}
err = yaml.Unmarshal(data, &ksonnetAppSpec)
if err != nil {
return nil, err
}
ksApp, err := ksonnet.NewKsonnetApp(appPath)
if err != nil {
return nil, status.Errorf(codes.FailedPrecondition, "unable to load application from %s: %v", appPath, err)
}
env := ""
if q.Ksonnet != nil {
env = q.Ksonnet.Environment
}
params, err := ksApp.ListParams(env)
if err != nil {
return nil, err
}
ksonnetAppSpec.Parameters = params
res.Ksonnet = &ksonnetAppSpec
case v1alpha1.ApplicationSourceTypeHelm:
res.Helm = &HelmAppSpec{}
res.Helm.Path = q.Path
files, err := ioutil.ReadDir(appPath)
if err != nil {
return nil, err
}
for _, f := range files {
if f.IsDir() {
continue
}
fName := f.Name()
if strings.Contains(fName, "values") && (filepath.Ext(fName) == ".yaml" || filepath.Ext(fName) == ".yml") {
res.Helm.ValueFiles = append(res.Helm.ValueFiles, fName)
}
}
h := helm.NewHelmApp(appPath, q.HelmRepos)
err = h.Init()
if err != nil {
return nil, err
}
defer h.Dispose()
params, err := h.GetParameters(q.valueFiles())
if err != nil {
return nil, err
}
res.Helm.Parameters = params
case v1alpha1.ApplicationSourceTypeKustomize:
res.Kustomize = &KustomizeAppSpec{}
res.Kustomize.Path = q.Path
k := kustomize.NewKustomizeApp(appPath, newCreds(q.Repo))
_, imageTags, images, err := k.Build(nil)
if err != nil {
return nil, err
}
res.Kustomize.ImageTags = kustomizeImageTags(imageTags)
res.Kustomize.Images = images
}
return &res, nil
}
func kustomizeImageTags(imageTags []kustomize.ImageTag) []*v1alpha1.KustomizeImageTag {
output := make([]*v1alpha1.KustomizeImageTag, len(imageTags))
for i, imageTag := range imageTags {
output[i] = &v1alpha1.KustomizeImageTag{Name: imageTag.Name, Value: imageTag.Value}
}
return output
}
func (q *RepoServerAppDetailsQuery) valueFiles() []string {
if q.Helm == nil {
return nil
}
return q.Helm.ValueFiles
}
func newCreds(repo *v1alpha1.Repository) git.Creds {
if repo == nil {
return git.NopCreds{}
}
if repo.Username != "" && repo.Password != "" {
return git.NewHTTPSCreds(repo.Username, repo.Password)
}
if repo.SSHPrivateKey != "" {
return git.NewSSHCreds(repo.SSHPrivateKey, repo.InsecureIgnoreHostKey)
}
return git.NopCreds{}
}