Skip to content

Commit 7965149

Browse files
authored
chore(ci): buildtools update addon command fails (#3100)
1 parent c7f01c0 commit 7965149

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

cmd/buildtools/utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func GetGreatestTagFromRegistry(ctx context.Context, ref string, constraints *se
355355

356356
func LatestChartVersion(ctx context.Context, hcli helm.Client, repo *repo.Entry, name string) (string, error) {
357357
logrus.Infof("adding helm repo %s", repo.Name)
358-
err := hcli.AddRepo(ctx, repo)
358+
err := hcli.AddRepoBin(ctx, repo)
359359
if err != nil {
360360
return "", fmt.Errorf("add helm repo: %w", err)
361361
}
@@ -479,6 +479,10 @@ func MirrorChart(ctx context.Context, hcli helm.Client, repo *repo.Entry, name,
479479
logrus.Infof("downloaded %s chart: %s", name, chpath)
480480
defer os.Remove(chpath)
481481

482+
err = hcli.AddRepoBin(ctx, repo)
483+
if err != nil {
484+
return fmt.Errorf("add helm repo: %w", err)
485+
}
482486
srcMeta, err := hcli.GetChartMetadata(ctx, chpath, ver)
483487
if err != nil {
484488
return fmt.Errorf("get source chart metadata: %w", err)

pkg/helm/client.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,40 @@ func (h *HelmClient) AddRepo(_ context.Context, repo *repo.Entry) error {
205205
return nil
206206
}
207207

208+
// AddRepoBin adds a repository to the helm client using the helm binary. This is necessary because
209+
// the AddRepo method does not work with other methods using the binary executor.
210+
func (h *HelmClient) AddRepoBin(ctx context.Context, repo *repo.Entry) error {
211+
// Use helm repo add command to add the repository
212+
args := []string{"repo", "add", repo.Name, repo.URL}
213+
214+
// Add username/password if provided
215+
if repo.Username != "" {
216+
args = append(args, "--username", repo.Username)
217+
}
218+
if repo.Password != "" {
219+
args = append(args, "--password", repo.Password)
220+
}
221+
222+
// Add insecure flag if needed
223+
if repo.InsecureSkipTLSverify {
224+
args = append(args, "--insecure-skip-tls-verify")
225+
}
226+
227+
// Add pass-credentials flag if needed
228+
if repo.PassCredentialsAll {
229+
args = append(args, "--pass-credentials")
230+
}
231+
232+
_, _, err := h.executor.ExecuteCommand(ctx, nil, nil, args...)
233+
if err != nil {
234+
return fmt.Errorf("helm repo add: %w", err)
235+
}
236+
237+
// Store the repository entry for future reference
238+
h.repositories = append(h.repositories, repo)
239+
return nil
240+
}
241+
208242
func (h *HelmClient) Latest(ctx context.Context, reponame, chart string) (string, error) {
209243
// Use helm search repo with JSON output to find the latest version
210244
args := []string{"search", "repo", fmt.Sprintf("%s/%s", reponame, chart), "--version", ">0.0.0", "--versions", "--output", "json"}

pkg/helm/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var (
1515
type Client interface {
1616
Close() error
1717
AddRepo(ctx context.Context, repo *repo.Entry) error
18+
AddRepoBin(ctx context.Context, repo *repo.Entry) error
1819
Latest(ctx context.Context, reponame, chart string) (string, error)
1920
Pull(ctx context.Context, reponame, chart string, version string) (string, error)
2021
PullByRef(ctx context.Context, ref string, version string) (string, error)

pkg/helm/mock_client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func (m *MockClient) AddRepo(ctx context.Context, repo *repo.Entry) error {
2525
return args.Error(0)
2626
}
2727

28+
func (m *MockClient) AddRepoBin(ctx context.Context, repo *repo.Entry) error {
29+
args := m.Called(ctx, repo)
30+
return args.Error(0)
31+
}
32+
2833
func (m *MockClient) Latest(ctx context.Context, reponame, chart string) (string, error) {
2934
args := m.Called(ctx, reponame, chart)
3035
return args.String(0), args.Error(1)

0 commit comments

Comments
 (0)