fixed to track all namespaces
parent
05357f9715
commit
370779e5b7
2
go.mod
2
go.mod
|
@ -57,6 +57,7 @@ require (
|
||||||
github.com/rusenask/docker-registry-client v0.0.0-20200210164146-049272422097
|
github.com/rusenask/docker-registry-client v0.0.0-20200210164146-049272422097
|
||||||
github.com/ryanuber/go-glob v1.0.0
|
github.com/ryanuber/go-glob v1.0.0
|
||||||
github.com/sirupsen/logrus v1.6.0
|
github.com/sirupsen/logrus v1.6.0
|
||||||
|
github.com/stretchr/testify v1.5.1
|
||||||
github.com/tbruyelle/hipchat-go v0.0.0-20170717082847-35aebc99209a
|
github.com/tbruyelle/hipchat-go v0.0.0-20170717082847-35aebc99209a
|
||||||
github.com/urfave/negroni v1.0.0
|
github.com/urfave/negroni v1.0.0
|
||||||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
|
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
|
||||||
|
@ -66,6 +67,7 @@ require (
|
||||||
helm.sh/helm/v3 v3.0.0-00010101000000-000000000000
|
helm.sh/helm/v3 v3.0.0-00010101000000-000000000000
|
||||||
k8s.io/api v0.17.2
|
k8s.io/api v0.17.2
|
||||||
k8s.io/apimachinery v0.17.2
|
k8s.io/apimachinery v0.17.2
|
||||||
|
k8s.io/cli-runtime v0.17.2
|
||||||
k8s.io/client-go v0.17.2
|
k8s.io/client-go v0.17.2
|
||||||
k8s.io/helm v0.0.0-00010101000000-000000000000
|
k8s.io/helm v0.0.0-00010101000000-000000000000
|
||||||
sigs.k8s.io/yaml v1.1.0
|
sigs.k8s.io/yaml v1.1.0
|
||||||
|
|
|
@ -286,6 +286,7 @@ func (p *Provider) createUpdatePlans(event *types.Event) ([]*UpdatePlan, error)
|
||||||
}).Error("provider.helm3: failed to process versioned release")
|
}).Error("provider.helm3: failed to process versioned release")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if update {
|
if update {
|
||||||
helm3VersionedUpdatesCounter.With(prometheus.Labels{"chart": fmt.Sprintf("%s/%s", release.Namespace, release.Name)}).Inc()
|
helm3VersionedUpdatesCounter.With(prometheus.Labels{"chart": fmt.Sprintf("%s/%s", release.Namespace, release.Name)}).Inc()
|
||||||
plans = append(plans, plan)
|
plans = append(plans, plan)
|
||||||
|
@ -314,9 +315,8 @@ func (p *Provider) applyPlans(plans []*UpdatePlan) error {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// err := updateHelmRelease(p.implementer, plan.Name, plan.Chart, plan.Values)
|
// err := updateHelmRelease(p.implementer, plan.Name, plan.Chart, plan.Values)
|
||||||
err := updateHelmRelease(p.implementer, plan.Name, plan.Chart, plan.Values, plan.EmptyConfig)
|
err := updateHelmRelease(p.implementer, plan.Name, plan.Chart, plan.Values, plan.Namespace, plan.EmptyConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"error": err,
|
"error": err,
|
||||||
|
@ -379,14 +379,14 @@ func (p *Provider) applyPlans(plans []*UpdatePlan) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateHelmRelease(implementer Implementer, releaseName string, chart *hapi_chart.Chart, overrideValues map[string]string, opts ...bool) error {
|
func updateHelmRelease(implementer Implementer, releaseName string, chart *hapi_chart.Chart, overrideValues map[string]string, namespace string, opts ...bool) error {
|
||||||
|
|
||||||
// set reuse values to false if currentRelease.config is nil
|
// set reuse values to false if currentRelease.config is nil
|
||||||
emptyConfig := false
|
emptyConfig := false
|
||||||
if len(opts) == 1 && opts[0] {
|
if len(opts) == 1 && opts[0] {
|
||||||
emptyConfig = opts[0]
|
emptyConfig = opts[0]
|
||||||
}
|
}
|
||||||
resp, err := implementer.UpdateReleaseFromChart(releaseName, chart, overrideValues, emptyConfig)
|
resp, err := implementer.UpdateReleaseFromChart(releaseName, chart, overrideValues, namespace, emptyConfig)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (i *fakeImplementer) ListReleases() ([]*release.Release, error) {
|
||||||
return i.listReleasesResponse, nil
|
return i.listReleasesResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *fakeImplementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, opts ...bool) (*release.Release, error) {
|
func (i *fakeImplementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, namespace string, opts ...bool) (*release.Release, error) {
|
||||||
// func (i *fakeImplementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...helm.UpdateOption) (*rls.UpdateReleaseResponse, error) {
|
// func (i *fakeImplementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts ...helm.UpdateOption) (*rls.UpdateReleaseResponse, error) {
|
||||||
i.updatedRlsName = rlsName
|
i.updatedRlsName = rlsName
|
||||||
i.updatedChart = chart
|
i.updatedChart = chart
|
||||||
|
|
|
@ -10,7 +10,9 @@ import (
|
||||||
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
"helm.sh/helm/v3/pkg/action"
|
||||||
"helm.sh/helm/v3/pkg/release"
|
"helm.sh/helm/v3/pkg/release"
|
||||||
"helm.sh/helm/v3/pkg/cli"
|
// "helm.sh/helm/v3/pkg/cli"
|
||||||
|
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
// to do:
|
// to do:
|
||||||
|
@ -23,33 +25,41 @@ const DefaultUpdateTimeout = 300
|
||||||
type Implementer interface {
|
type Implementer interface {
|
||||||
// ListReleases(opts ...helm.ReleaseListOption) ([]*release.Release, error)
|
// ListReleases(opts ...helm.ReleaseListOption) ([]*release.Release, error)
|
||||||
ListReleases() ([]*release.Release, error)
|
ListReleases() ([]*release.Release, error)
|
||||||
UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, opts ...bool) (*release.Release, error)
|
UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, namespace string, opts ...bool) (*release.Release, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helm3Implementer - actual helm3 implementer
|
// Helm3Implementer - actual helm3 implementer
|
||||||
type Helm3Implementer struct {
|
type Helm3Implementer struct {
|
||||||
actionConfig *action.Configuration
|
// actionConfig *action.Configuration
|
||||||
|
HelmDriver string
|
||||||
|
KubeContext string
|
||||||
|
KubeToken string
|
||||||
|
KubeAPIServer string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHelm3Implementer - get new helm implementer
|
// NewHelm3Implementer - get new helm implementer
|
||||||
func NewHelm3Implementer() *Helm3Implementer {
|
func NewHelm3Implementer() *Helm3Implementer {
|
||||||
settings := cli.New()
|
// settings := cli.New()
|
||||||
|
|
||||||
actionConfig := &action.Configuration{}
|
// actionConfig := &action.Configuration{}
|
||||||
// You can pass an empty string instead of settings.Namespace() to list
|
// // You can pass an empty string instead of settings.Namespace() to list
|
||||||
// all namespaces
|
// // all namespaces
|
||||||
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
|
// if err := actionConfig.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
|
||||||
log.Printf("%+v", err)
|
// log.Printf("%+v", err)
|
||||||
os.Exit(1)
|
// os.Exit(1)
|
||||||
}
|
// }
|
||||||
return &Helm3Implementer{
|
return &Helm3Implementer{
|
||||||
actionConfig: actionConfig,
|
HelmDriver: os.Getenv("HELM_DRIVER"),
|
||||||
|
KubeContext: os.Getenv("HELM_KUBECONTEXT"),
|
||||||
|
KubeToken: os.Getenv("HELM_KUBETOKEN"),
|
||||||
|
KubeAPIServer: os.Getenv("HELM_KUBEAPISERVER"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListReleases - list available releases
|
// ListReleases - list available releases
|
||||||
func (i *Helm3Implementer) ListReleases() ([]*release.Release, error) {
|
func (i *Helm3Implementer) ListReleases() ([]*release.Release, error) {
|
||||||
client := action.NewList(i.actionConfig)
|
actionConfig := i.generateConfig("")
|
||||||
|
client := action.NewList(actionConfig)
|
||||||
results, err := client.Run()
|
results, err := client.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
@ -62,8 +72,10 @@ func (i *Helm3Implementer) ListReleases() ([]*release.Release, error) {
|
||||||
|
|
||||||
// UpdateReleaseFromChart - update release from chart
|
// UpdateReleaseFromChart - update release from chart
|
||||||
// func (i *Helm3Implementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string) (*release.Release, error) {
|
// func (i *Helm3Implementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string) (*release.Release, error) {
|
||||||
func (i *Helm3Implementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, opts ...bool) (*release.Release, error) {
|
func (i *Helm3Implementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, namespace string, opts ...bool) (*release.Release, error) {
|
||||||
client := action.NewUpgrade(i.actionConfig)
|
actionConfig := i.generateConfig(namespace)
|
||||||
|
client := action.NewUpgrade(actionConfig)
|
||||||
|
client.Namespace = namespace
|
||||||
client.Force = true
|
client.Force = true
|
||||||
client.Timeout = DefaultUpdateTimeout;
|
client.Timeout = DefaultUpdateTimeout;
|
||||||
client.ReuseValues = true
|
client.ReuseValues = true
|
||||||
|
@ -86,6 +98,25 @@ func (i *Helm3Implementer) UpdateReleaseFromChart(rlsName string, chart *chart.C
|
||||||
return results, err
|
return results, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Helm3Implementer) generateConfig(namespace string) (*action.Configuration) {
|
||||||
|
// settings := cli.New()
|
||||||
|
config := &genericclioptions.ConfigFlags{
|
||||||
|
Namespace: &namespace,
|
||||||
|
Context: &i.KubeContext,
|
||||||
|
BearerToken: &i.KubeToken,
|
||||||
|
APIServer: &i.KubeAPIServer,
|
||||||
|
}
|
||||||
|
|
||||||
|
actionConfig := &action.Configuration{}
|
||||||
|
|
||||||
|
if err := actionConfig.Init(config, namespace, i.HelmDriver, log.Printf); err != nil {
|
||||||
|
log.Printf("%+v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return actionConfig
|
||||||
|
}
|
||||||
|
|
||||||
// convert map[string]string to map[string]interface
|
// convert map[string]string to map[string]interface
|
||||||
// converts:
|
// converts:
|
||||||
// map[string]string{"image.tag": "0.1.0"}
|
// map[string]string{"image.tag": "0.1.0"}
|
||||||
|
|
Loading…
Reference in New Issue