Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart version #6

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FROM index.alauda.cn/alaudaorg/alaudabase-alpine-run:alpine3.9.3
WORKDIR /captain

COPY --from=0 /go/src/github.com/alauda/captain/captain /captain/
COPY artifacts/helm/repositories.yaml /captain/.helm/repository/
COPY artifacts/helm/repositories.yaml /root/.config/helm/
RUN chmod a+x /captain/captain


Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ replace k8s.io/apiserver => k8s.io/apiserver v0.0.0-20190606205144-71ebb8303503

replace sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.2.0-beta.3

replace helm.sh/helm => github.com/alauda/helm v3.0.0-alpha.1.0.20190806070809-af9bbccc4ffd+incompatible
replace helm.sh/helm => github.com/alauda/helm v3.0.0-alpha.1.0.20190820063735-20f2bc7747e6+incompatible

replace github.com/russross/blackfriday => github.com/russross/blackfriday v1.5.2

replace k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190606210616-f848dc7be4a4

replace github.com/deislabs/oras => github.com/deislabs/oras v0.6.0

require (
github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e // indirect
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.4.2 // indirect
github.com/Masterminds/sprig v2.18.0+incompatible // indirect
github.com/Microsoft/hcsshim v0.8.6 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/alauda/component-base v0.0.0-20190628064654-a4dafcfd3446
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/Masterminds/sprig v2.18.0+incompatible h1:QoGhlbC6pter1jxKnjMFxT8EqsL
github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6nK2Q=
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/Microsoft/hcsshim v0.8.6 h1:ZfF0+zZeYdzMIVMZHKtDKJvLHj76XCuVae/jNkjj0IA=
github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4=
Expand All @@ -28,8 +30,8 @@ github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/O
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/alauda/component-base v0.0.0-20190628064654-a4dafcfd3446 h1:gtzuHCPURUuSWz5y/gkLQyxJn/W3pqG74YpzghVG7bY=
github.com/alauda/component-base v0.0.0-20190628064654-a4dafcfd3446/go.mod h1:tbaXeIWDl6zX1b7O53FSXClDS1YmEDRnVJszgcLXzpk=
github.com/alauda/helm v3.0.0-alpha.1.0.20190806070809-af9bbccc4ffd+incompatible h1:QVylONSBF3PZQrgMOa36qfPFFh/yfRl5wn7tQIzqO2o=
github.com/alauda/helm v3.0.0-alpha.1.0.20190806070809-af9bbccc4ffd+incompatible/go.mod h1:puN71hQ/dtLbcyDOPyhZw19FrLSYCak3EvJBT2OaRvQ=
github.com/alauda/helm v3.0.0-alpha.1.0.20190820063735-20f2bc7747e6+incompatible h1:94VY2g7SoUL7Tz/8t0rWWjkULuZNODbvg2OHQ6LrFWo=
github.com/alauda/helm v3.0.0-alpha.1.0.20190820063735-20f2bc7747e6+incompatible/go.mod h1:puN71hQ/dtLbcyDOPyhZw19FrLSYCak3EvJBT2OaRvQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand Down Expand Up @@ -70,8 +72,8 @@ github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deislabs/oras v0.5.0 h1:u6sDqqW8n15v7rG3EbFNSGwHI7rEC4frBhD0w18RXp8=
github.com/deislabs/oras v0.5.0/go.mod h1:84GkbaZ8ZNw18+Clb7hpHffPr4ei+PqXdwvLeTiTm+I=
github.com/deislabs/oras v0.6.0 h1:gwkhlJHaqYIVuqHMOocUuMmf5XUzssL3FJDJpUXagyU=
github.com/deislabs/oras v0.6.0/go.mod h1:84GkbaZ8ZNw18+Clb7hpHffPr4ei+PqXdwvLeTiTm+I=
github.com/dgrijalva/jwt-go v0.0.0-20160705203006-01aeca54ebda h1:NyywMz59neOoVRFDz+ccfKWxn784fiHMDnZSy6T+JXY=
github.com/dgrijalva/jwt-go v0.0.0-20160705203006-01aeca54ebda/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/app/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ type ReleaseStatus struct {
Description string `json:"Description,omitempty"`
// Status is the current state of the release
Status release.Status `json:"status,omitempty"`
// Cluster resources as kubectl would print them.
Resources string `json:"resources,omitempty"`
// Contains the rendered templates/NOTES.txt if available
Notes string `json:"notes,omitempty"`
}
Expand All @@ -75,7 +73,6 @@ func (in *ReleaseStatus) CopyFromReleaseInfo(info *release.Info) {
in.Description = info.Description
in.FirstDeployed = metav1.NewTime(info.FirstDeployed)
in.LastDeployed = metav1.NewTime(info.LastDeployed)
in.Resources = info.Resources
in.Notes = info.Notes
}

Expand All @@ -87,7 +84,6 @@ func (in *ReleaseStatus) ToReleaseInfo() *release.Info {
info.Description = in.Description
info.FirstDeployed = in.FirstDeployed.Time
info.LastDeployed = in.LastDeployed.Time
info.Resources = in.Resources
info.Notes = in.Notes
return &info
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"fmt"
"os"

"github.com/alauda/captain/pkg/apis/app/v1alpha1"
Expand All @@ -9,6 +10,7 @@ import (
"github.com/alauda/captain/pkg/release"
funk "github.com/thoas/go-funk"
"helm.sh/helm/pkg/action"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/klog"
)
Expand Down Expand Up @@ -81,6 +83,10 @@ func (c *Controller) sync(info *cluster.Info, helmRequest *v1alpha1.HelmRequest)
return err
}

// record chart version for un-specified ones
msg := fmt.Sprintf("Choose chart version: %s %s", rel.Chart.Metadata.Name, rel.Chart.Metadata.Version)
c.recorder.Event(helmRequest, corev1.EventTypeNormal, SuccessSynced, msg)

action.PrintRelease(os.Stdout, rel)
return nil
}
Expand Down
9 changes: 2 additions & 7 deletions pkg/helm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
// 2. update repo index
// we will mount the repo file from a ConfigMap by default, so this function will do the index update
func Init() {
path := string(getHelmHome()) + "/repository/repositories.yaml"
path := helmpath.RepositoryFile()
err := system.CreatePathIfNotExist(path)
if err != nil {
panic(err)
}

path = string(getHelmHome()) + "/repository/cache/"
path = helmpath.RepositoryCache() + "/"
if err := system.CreatePathIfNotExist(path); err != nil {
panic(err)
}
Expand All @@ -53,11 +53,6 @@ func Init() {
}
}

// getHelmHome return the helm dir, default use the same as cli
func getHelmHome() helmpath.Home {
return helmpath.Home(".helm")
}

// getNamespace get the namespaces from ..... This may be a little unnecessary, may be we can just
// use the one we know.
func getNamespace(flags *genericclioptions.ConfigFlags) string {
Expand Down
18 changes: 13 additions & 5 deletions pkg/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helm

import (
"os"
"strings"
"time"

"github.com/alauda/captain/pkg/apis/app/v1alpha1"
Expand All @@ -28,7 +29,6 @@ func install(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, er
client.Timeout = 180 * time.Second
out := os.Stdout
settings := cli.EnvSettings{
Home: getHelmHome(),
Debug: true,
}

Expand Down Expand Up @@ -57,7 +57,17 @@ func install(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, er
cp, err := client.ChartPathOptions.LocateChart(chrt, settings)
if err != nil {
klog.Errorf("locate chart %s error: %s", cp, err.Error())
return nil, err
// a simple string match
if client.Version == "" && strings.Contains(err.Error(), " no chart version found for") {
klog.Info("no normal version found, try using devel flag")
client.Version = ">0.0.0-0"
cp, err = client.ChartPathOptions.LocateChart(chrt, settings)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}

klog.V(9).Infof("CHART PATH: %s\n", cp)
Expand All @@ -66,7 +76,6 @@ func install(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, er
if err != nil {
return nil, err
}
client.ValueOptions = action.NewValueOptions(values)

// Check chart dependencies to make sure all are present in /charts
chartRequested, err := loader.Load(cp)
Expand All @@ -92,7 +101,6 @@ func install(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, er
man := &downloader.Manager{
Out: out,
ChartPath: cp,
HelmHome: settings.Home,
Keyring: client.ChartPathOptions.Keyring,
SkipUpdate: false,
Getters: getter.All(settings),
Expand All @@ -106,7 +114,7 @@ func install(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, er
}
}

return client.Run(chartRequested)
return client.Run(chartRequested, values)
}

// isChartInstallable validates if a chart can be installed
Expand Down
25 changes: 7 additions & 18 deletions pkg/helm/repo_add.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package helm

import (
"path/filepath"
"sync"

"github.com/pkg/errors"
Expand All @@ -15,35 +14,33 @@ var lock sync.Mutex

// AddBasicAuthRepository add a repo with basic auth
func AddBasicAuthRepository(name, url, username, password string) error {
return addRepository(name, url, username, password, getHelmHome(), "", "", "", false)
return addRepository(name, url, username, password, "", "", "", false)
}

// RemoveRepository remove a repo from helm
func RemoveRepository(name string) error {
lock.Lock()
defer lock.Unlock()

home := getHelmHome()

f, err := repo.LoadFile(home.RepositoryFile())
f, err := repo.LoadFile(helmpath.RepositoryFile())
if err != nil {
return err
}

found := f.Remove(name)
if found {
return f.WriteFile(home.RepositoryFile(), 0644)
return f.WriteFile(helmpath.RepositoryFile(), 0644)
}

return nil
}

// addRepository add a repo and update index ( the repo already exist, we only need to update-index part)
func addRepository(name, url, username, password string, home helmpath.Home, certFile, keyFile, caFile string, noUpdate bool) error {
func addRepository(name, url, username, password string, certFile, keyFile, caFile string, noUpdate bool) error {
lock.Lock()
defer lock.Unlock()

f, err := repo.LoadFile(home.RepositoryFile())
f, err := repo.LoadFile(helmpath.RepositoryFile())
if err != nil {
return err
}
Expand All @@ -52,15 +49,8 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
return errors.Errorf("repository name (%s) already exists, please specify a different name", name)
}

cif := home.CacheIndex(name)
absCif, err := filepath.Abs(cif)
if err != nil {
return err
}

c := repo.Entry{
Name: name,
Cache: absCif,
URL: url,
Username: username,
Password: password,
Expand All @@ -70,7 +60,6 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
}

settings := cli.EnvSettings{
Home: getHelmHome(),
Debug: true,
}

Expand All @@ -79,11 +68,11 @@ func addRepository(name, url, username, password string, home helmpath.Home, cer
return err
}

if err := r.DownloadIndexFile(home.Cache()); err != nil {
if err := r.DownloadIndexFile(); err != nil {
return errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", url)
}

f.Update(&c)

return f.WriteFile(home.RepositoryFile(), 0644)
return f.WriteFile(helmpath.RepositoryFile(), 0644)
}
6 changes: 4 additions & 2 deletions pkg/helm/repo_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package helm
import (
"time"

"helm.sh/helm/pkg/helmpath"

"helm.sh/helm/pkg/repo"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"
Expand Down Expand Up @@ -42,15 +44,15 @@ func (i *IndexSyncer) Start(stop <-chan struct{}) error {

// initReposIndex update index for all the known repos. This happens when captain starts.
func initReposIndex() error {
f, err := repo.LoadFile(getHelmHome().RepositoryFile())
f, err := repo.LoadFile(helmpath.RepositoryFile())
if err != nil {
return err
}
if len(f.Repositories) == 0 {
return nil
}
for _, re := range f.Repositories {
err := addRepository(re.Name, re.URL, re.Username, re.Password, getHelmHome(), "", "", "", false)
err := addRepository(re.Name, re.URL, re.Username, re.Password, "", "", "", false)
if err != nil {
klog.Warningf("repo index update error for %s: %s", re.Name, err.Error())
continue
Expand Down
17 changes: 13 additions & 4 deletions pkg/helm/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helm

import (
"os"
"strings"

"github.com/alauda/captain/pkg/apis/app/v1alpha1"
"github.com/alauda/captain/pkg/cluster"
Expand All @@ -22,7 +23,6 @@ func Sync(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, error

// helm settings
settings := cli.EnvSettings{
Home: getHelmHome(),
Debug: true,
}

Expand All @@ -47,15 +47,24 @@ func Sync(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, error
if err != nil {
return nil, err
}
client.ValueOptions = action.NewValueOptions(values)
client.ResetValues = true

// locate chart
chrt := hr.Spec.Chart
chartPath, err := client.ChartPathOptions.LocateChart(chrt, settings)
if err != nil {
klog.Errorf("locate chart %s error: %s", chartPath, err.Error())
return nil, err
// a simple string match
if client.Version == "" && strings.Contains(err.Error(), " no chart version found for") {
klog.Info("no normal version found, try using devel flag")
client.Version = ">0.0.0-0"
chartPath, err = client.ChartPathOptions.LocateChart(chrt, settings)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}

// load
Expand Down Expand Up @@ -89,7 +98,7 @@ func Sync(hr *v1alpha1.HelmRequest, info *cluster.Info) (*release.Release, error
}

// run upgrade/install
resp, err := client.Run(name, ch)
resp, err := client.Run(name, ch, values)
if err != nil {
return nil, errors.Wrap(err, "UPGRADE FAILED")
}
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/Microsoft/go-winio/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading