Skip to content

Commit

Permalink
Handle the error for private helm repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Daishan committed Apr 16, 2021
1 parent 4632bb0 commit 9d9fe2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/bundle/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func chartURL(location *fleet.HelmOptions, auth Auth) (string, error) {
return "", err
}

if resp.StatusCode != 200 {
return "", fmt.Errorf("failed to read helm repo from %s, error code: %v, response body: %s", location.Repo+"index.yaml", resp.StatusCode, bytes)
}

repo := &repo.IndexFile{}
if err := yaml.Unmarshal(bytes, repo); err != nil {
return "", err
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ func Register(ctx context.Context, systemNamespace string, cfg clientcmd.ClientC
appCtx.BundleDeployment(),
appCtx.GitRepoRestriction().Cache(),
appCtx.Bundle(),
appCtx.GitRepo())
appCtx.GitRepo(),
appCtx.Core.Secret().Cache())

bootstrap.Register(ctx,
systemNamespace,
Expand Down
12 changes: 11 additions & 1 deletion pkg/controllers/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
v1 "github.com/rancher/gitjob/pkg/generated/controllers/gitjob.cattle.io/v1"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/wrangler/pkg/apply"
corev1controller "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/genericcondition"
"github.com/rancher/wrangler/pkg/kv"
"github.com/rancher/wrangler/pkg/name"
Expand All @@ -41,14 +42,16 @@ func Register(ctx context.Context,
bundleDeployments fleetcontrollers.BundleDeploymentController,
gitRepoRestrictions fleetcontrollers.GitRepoRestrictionCache,
bundles fleetcontrollers.BundleController,
gitRepos fleetcontrollers.GitRepoController) {
gitRepos fleetcontrollers.GitRepoController,
secrets corev1controller.SecretCache) {
h := &handler{
gitjobCache: gitJobs.Cache(),
bundleCache: bundles.Cache(),
bundles: bundles,
bundleDeployments: bundleDeployments.Cache(),
gitRepoRestrictions: gitRepoRestrictions,
display: display.NewFactory(bundles.Cache()),
secrets: secrets,
}

gitRepos.OnChange(ctx, "gitjob-purge", h.DeleteOnChange)
Expand All @@ -74,6 +77,7 @@ func resolveGitRepo(namespace, name string, obj runtime.Object) ([]relatedresour
type handler struct {
shareClientFactory client.SharedClientFactory
gitjobCache v1.GitJobCache
secrets corev1controller.SecretCache
bundleCache fleetcontrollers.BundleCache
bundles fleetcontrollers.BundleClient
gitRepoRestrictions fleetcontrollers.GitRepoRestrictionCache
Expand Down Expand Up @@ -258,6 +262,12 @@ func (h *handler) OnChange(gitrepo *fleet.GitRepo, status fleet.GitRepoStatus) (
return nil, status, nil
}

if gitrepo.Spec.HelmSecretName != "" {
if _, err := h.secrets.Get(gitrepo.Namespace, gitrepo.Spec.HelmSecretName); err != nil {
return nil, status, fmt.Errorf("failed to look up helmSecretName, error: %v", err)
}
}

gitrepo, err := h.authorizeAndAssignDefaults(gitrepo)
if err != nil {
return nil, status, err
Expand Down

0 comments on commit 9d9fe2d

Please sign in to comment.