-
Notifications
You must be signed in to change notification settings - Fork 29
/
sync.go
54 lines (47 loc) · 1.32 KB
/
sync.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
package chart
import (
"path"
"github.com/juju/errors"
"k8s.io/klog"
"github.com/bitnami-labs/charts-syncer/api"
"github.com/bitnami-labs/charts-syncer/internal/utils"
)
// ChangeReferences changes the references of a chart tgz file from the source
// repo to the target repo
func ChangeReferences(chartPath, name, version string, source *api.Source, target *api.Target) error {
// Update values*.yaml
if target.GetContainerRegistry() == "" && target.GetContainerRepository() == "" {
// Skip modify value.yaml and readme
return nil
}
for _, f := range []string{
path.Join(chartPath, ValuesFilename),
path.Join(chartPath, ValuesProductionFilename),
} {
if ok, err := utils.FileExists(f); err != nil {
return errors.Trace(err)
} else if ok {
klog.V(5).Infof("Processing %q file...", f)
if err := updateValuesFile(f, target); err != nil {
return errors.Trace(err)
}
}
}
// Update README.md
readmeFile := path.Join(chartPath, ReadmeFilename)
if ok, err := utils.FileExists(readmeFile); err != nil {
return errors.Trace(err)
} else if ok {
klog.V(5).Infof("Processing %q file...", readmeFile)
if err := updateReadmeFile(
readmeFile,
source.GetRepo().GetUrl(),
target.GetRepo().GetUrl(),
name,
target.GetRepoName(),
); err != nil {
return errors.Trace(err)
}
}
return nil
}