diff --git a/integrationtests/cli/apply/helm_test.go b/integrationtests/cli/apply/helm_test.go index e873ec8443..2b6544c2a3 100644 --- a/integrationtests/cli/apply/helm_test.go +++ b/integrationtests/cli/apply/helm_test.go @@ -1,7 +1,9 @@ package apply import ( + "fmt" "io/fs" + "os" "path/filepath" . "github.com/onsi/ginkgo/v2" @@ -9,6 +11,8 @@ import ( "github.com/rancher/fleet/integrationtests/cli" "github.com/rancher/fleet/internal/bundlereader" "github.com/rancher/fleet/internal/cmd/cli/apply" + fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" + "sigs.k8s.io/yaml" ) const ( @@ -162,7 +166,17 @@ func testHelmRepo(path, port string) { BeforeEach(func() { authEnabled = true }) - It("fleet apply fails when --helm-repo-url-regex is not valid", func() { + FIt("fleet apply fails when --helm-repo-url-regex is not valid", func() { + // read the fleet.yaml file, so we can later check if the error message + // contains the expected chart information + assetsDir := filepath.Join(cli.AssetsPath, path) + data, err := os.ReadFile(filepath.Join(assetsDir, "fleet.yaml")) + Expect(err).ToNot(HaveOccurred()) + + fy := &fleet.FleetYAML{} + err = yaml.Unmarshal(data, fy) + Expect(err).ToNot(HaveOccurred()) + Eventually(func() string { err := fleetApply("helm", []string{cli.AssetsPath + path}, apply.Options{ Auth: bundlereader.Auth{Username: username, Password: password}, @@ -170,7 +184,13 @@ func testHelmRepo(path, port string) { }) Expect(err).To(HaveOccurred()) return err.Error() - }).Should(Equal("error parsing regexp: missing closing ): `a(b`")) + }).Should(Equal( + fmt.Sprintf( + "repo=%s chart=%s version=%s: error parsing regexp: missing closing ): `a(b`", + fy.Helm.Repo, + fy.Helm.Chart, + fy.Helm.Version, + ))) }) }) diff --git a/internal/bundlereader/resources.go b/internal/bundlereader/resources.go index 55d4b3185a..a513e53204 100644 --- a/internal/bundlereader/resources.go +++ b/internal/bundlereader/resources.go @@ -154,7 +154,7 @@ func addRemoteCharts(directories []directory, base string, charts []*fleet.HelmO if _, err := os.Stat(filepath.Join(base, chart.Chart)); os.IsNotExist(err) || chart.Repo != "" { shouldAddAuthToRequest, err := shouldAddAuthToRequest(helmRepoURLRegex, chart.Repo, chart.Chart) if err != nil { - return nil, err + return nil, downloadChartError(*chart, err) } if !shouldAddAuthToRequest { auth = Auth{} @@ -162,7 +162,7 @@ func addRemoteCharts(directories []directory, base string, charts []*fleet.HelmO chartURL, err := chartURL(*chart, auth) if err != nil { - return nil, err + return nil, downloadChartError(*chart, err) } directories = append(directories, directory{ @@ -178,6 +178,16 @@ func addRemoteCharts(directories []directory, base string, charts []*fleet.HelmO return directories, nil } +func downloadChartError(c fleet.HelmOptions, e error) error { + return fmt.Errorf( + "repo=%s chart=%s version=%s: %w", + c.Repo, + c.Chart, + c.Version, + e, + ) +} + func shouldAddAuthToRequest(helmRepoURLRegex, repo, chart string) (bool, error) { if helmRepoURLRegex == "" { return true, nil