@@ -25,8 +25,8 @@ type RelocationResult struct {
25
25
Count int
26
26
}
27
27
28
- func relocateChart (chart * cu.Chart , prefix string , cfg * RelocateConfig ) error {
29
- valuesReplRes , err := relocateValues (chart , prefix )
28
+ func relocateChart (chart * cu.Chart , newRegistry string , cfg * RelocateConfig ) error {
29
+ valuesReplRes , err := relocateValues (chart , newRegistry )
30
30
if err != nil {
31
31
return fmt .Errorf ("failed to relocate chart: %v" , err )
32
32
}
@@ -42,7 +42,7 @@ func relocateChart(chart *cu.Chart, prefix string, cfg *RelocateConfig) error {
42
42
var allErrors error
43
43
44
44
// TODO: Compare annotations with values replacements
45
- annotationsRelocResult , err := relocateAnnotations (chart , prefix )
45
+ annotationsRelocResult , err := relocateAnnotations (chart , newRegistry )
46
46
if err != nil {
47
47
allErrors = errors .Join (allErrors , fmt .Errorf ("failed to relocate Helm chart: %v" , err ))
48
48
} else {
@@ -58,19 +58,27 @@ func relocateChart(chart *cu.Chart, prefix string, cfg *RelocateConfig) error {
58
58
59
59
lockFile := chart .LockFilePath ()
60
60
if utils .FileExists (lockFile ) {
61
- err = RelocateLockFile (lockFile , prefix )
61
+ err = RelocateLockFile (lockFile , newRegistry )
62
62
if err != nil {
63
63
allErrors = errors .Join (allErrors , fmt .Errorf ("failed to relocate Images.lock file: %v" , err ))
64
64
}
65
65
}
66
66
67
+ if cfg .Recursive {
68
+ for _ , dep := range chart .Dependencies () {
69
+ if err := relocateChart (dep , newRegistry , cfg ); err != nil {
70
+ allErrors = errors .Join (allErrors , fmt .Errorf ("failed to relocate Helm SubChart %q: %v" , dep .Chart ().ChartFullPath (), err ))
71
+ }
72
+ }
73
+ }
74
+
67
75
return allErrors
68
76
}
69
77
70
78
// RelocateChartDir relocates the chart (Chart.yaml annotations, Images.lock and values.yaml) specified
71
79
// by chartPath using the provided prefix
72
- func RelocateChartDir (chartPath string , prefix string , opts ... RelocateOption ) error {
73
- prefix = normalizeRelocateURL (prefix )
80
+ func RelocateChartDir (chartPath string , newRegistry string , opts ... RelocateOption ) error {
81
+ newRegistry = normalizeRelocateURL (newRegistry )
74
82
75
83
cfg := NewRelocateConfig (opts ... )
76
84
@@ -79,39 +87,30 @@ func RelocateChartDir(chartPath string, prefix string, opts ...RelocateOption) e
79
87
return fmt .Errorf ("failed to load Helm chart: %v" , err )
80
88
}
81
89
82
- err = relocateChart (chart , prefix , cfg )
90
+ err = relocateChart (chart , newRegistry , cfg )
83
91
if err != nil {
84
92
return err
85
93
}
86
94
if utils .FileExists (filepath .Join (chartPath , carvel .CarvelImagesFilePath )) {
87
- err = relocateCarvelBundle (chartPath , prefix )
95
+ err = relocateCarvelBundle (chartPath , newRegistry )
88
96
89
97
if err != nil {
90
98
return err
91
99
}
92
100
}
93
101
94
- var allErrors error
95
-
96
- if cfg .Recursive {
97
- for _ , dep := range chart .Dependencies () {
98
- if err := relocateChart (dep , prefix , cfg ); err != nil {
99
- allErrors = errors .Join (allErrors , fmt .Errorf ("failed to reloacte Helm SubChart %q: %v" , dep .Chart ().ChartFullPath (), err ))
100
- }
101
- }
102
- }
103
- return allErrors
102
+ return err
104
103
}
105
104
106
- func relocateCarvelBundle (chartRoot string , prefix string ) error {
105
+ func relocateCarvelBundle (chartRoot string , newRegistry string ) error {
107
106
108
107
//TODO: Do better detection here, imgpkg probably has something
109
108
carvelImagesFile := filepath .Join (chartRoot , carvel .CarvelImagesFilePath )
110
109
lock , err := lockconfig .NewImagesLockFromPath (carvelImagesFile )
111
110
if err != nil {
112
111
return fmt .Errorf ("failed to load Carvel images lock: %v" , err )
113
112
}
114
- result , err := RelocateCarvelImagesLock (& lock , prefix )
113
+ result , err := RelocateCarvelImagesLock (& lock , newRegistry )
115
114
if err != nil {
116
115
return err
117
116
}
@@ -125,9 +124,9 @@ func relocateCarvelBundle(chartRoot string, prefix string) error {
125
124
}
126
125
127
126
// RelocateCarvelImagesLock rewrites the images urls in the provided lock using prefix
128
- func RelocateCarvelImagesLock (lock * lockconfig.ImagesLock , prefix string ) (* RelocationResult , error ) {
127
+ func RelocateCarvelImagesLock (lock * lockconfig.ImagesLock , newRegistry string ) (* RelocationResult , error ) {
129
128
130
- count , err := relocateCarvelImages (lock .Images , prefix )
129
+ count , err := relocateCarvelImages (lock .Images , newRegistry )
131
130
if err != nil {
132
131
return nil , fmt .Errorf ("failed to relocate Carvel images lock file: %v" , err )
133
132
}
@@ -141,10 +140,10 @@ func RelocateCarvelImagesLock(lock *lockconfig.ImagesLock, prefix string) (*Relo
141
140
142
141
}
143
142
144
- func relocateCarvelImages (images []lockconfig.ImageRef , prefix string ) (count int , err error ) {
143
+ func relocateCarvelImages (images []lockconfig.ImageRef , newRegistry string ) (count int , err error ) {
145
144
var allErrors error
146
145
for i , img := range images {
147
- norm , err := utils .RelocateImageURL (img .Image , prefix , true )
146
+ norm , err := utils .RelocateImageURL (img .Image , newRegistry , true )
148
147
if err != nil {
149
148
allErrors = errors .Join (allErrors , err )
150
149
continue
0 commit comments