Skip to content

Commit

Permalink
add rule to manage secrets in the kubeapps namespace (#268)
Browse files Browse the repository at this point in the history
* import fixes from vmware-archive/helm-crd/pull/23

* add rule to manage secrets in the kubeapps namespace

* address review comments
  • Loading branch information
Sameer Naik authored Apr 24, 2018
1 parent 05a4f32 commit 28a50ac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cmd/apprepository-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,10 @@ func apprepoSyncJobEnvVars(apprepo *apprepov1alpha1.AppRepository) []corev1.EnvV
})
if apprepo.Spec.Auth.Header != nil {
envVars = append(envVars, corev1.EnvVar{
Name: "AUTHORIZATION_HEADER",
ValueFrom: apprepo.Spec.Auth.Header,
Name: "AUTHORIZATION_HEADER",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &apprepo.Spec.Auth.Header.SecretKeyRef,
},
})
}
return envVars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ type AppRepositorySpec struct {

// AppRepositoryAuth is the auth for an AppRepository resource
type AppRepositoryAuth struct {
Header *corev1.EnvVarSource `json:"header,omitempty"`
Header *AppRepositoryAuthHeader `json:"header,omitempty"`
}

type AppRepositoryAuthHeader struct {
// Selects a key of a secret in the pod's namespace
SecretKeyRef corev1.SecretKeySelector `json:"secretKeyRef,omitempty"`
}

// AppRepositoryStatus is the status for an AppRepository resource
Expand Down
15 changes: 10 additions & 5 deletions cmd/chart-repo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ import (
)

const (
chartCollection = "charts"
chartFilesCollection = "files"
chartCollection = "charts"
chartFilesCollection = "files"
defaultTimeoutSeconds = 10
)

type importChartFilesJob struct {
Expand All @@ -56,7 +57,7 @@ type httpClient interface {
}

var netClient httpClient = &http.Client{
Timeout: time.Second * 10,
Timeout: time.Second * defaultTimeoutSeconds,
}

func parseRepoUrl(repoURL string) (*url.URL, error) {
Expand Down Expand Up @@ -170,6 +171,9 @@ func fetchRepoIndex(r repo) (*helmrepo.IndexFile, error) {
req.Header.Set("Authorization", r.AuthorizationHeader)
}
res, err := netClient.Do(req)
if res != nil {
defer res.Body.Close()
}
if err != nil {
log.WithFields(log.Fields{"url": req.URL.String()}).WithError(err).Error("error requesting repo index")
return nil, err
Expand All @@ -180,7 +184,6 @@ func fetchRepoIndex(r repo) (*helmrepo.IndexFile, error) {
return nil, errors.New("repo index request failed")
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
Expand Down Expand Up @@ -281,10 +284,12 @@ func fetchAndImportIcon(dbSession datastore.Session, c chart) error {
}

res, err := netClient.Do(req)
if res != nil {
defer res.Body.Close()
}
if err != nil {
return err
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return fmt.Errorf("%d %s", res.StatusCode, c.Icon)
Expand Down
6 changes: 6 additions & 0 deletions manifests/kube-api.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ local kube = import "kube.libsonnet";
resources: ["configmaps"],
verbs: ["get", "list"],
},
// Kubeapps creates Secrets with authorization token data for private chart repos
{
apiGroups: [""],
resources: ["secrets"],
verbs: ["create"],
},
// Kubeapps creates and manages AppRepository CRD objects that define
// which application (e.g. chart) repositories will be indexed.
{
Expand Down

0 comments on commit 28a50ac

Please sign in to comment.