Merge pull request #183 from ibuildthecloud/helm

Various helm fixes
This commit is contained in:
Darren Shepherd 2019-03-07 13:04:42 -07:00 committed by GitHub
commit 937b379605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -52,21 +52,15 @@ func WatchFiles(ctx context.Context, skips []string, bases ...string) error {
addons.Enqueue("", startKey) addons.Enqueue("", startKey)
addons.Interface().AddHandler(ctx, "addon-start", func(key string, _ *v1.Addon) (runtime.Object, error) { addons.Interface().AddHandler(ctx, "addon-start", func(key string, _ *v1.Addon) (runtime.Object, error) {
if key == startKey { if key == startKey {
if err := w.listFiles(true); err != nil { go w.start(ctx)
return nil, err
}
w.started = true
return nil, nil
} }
return nil, nil return nil, nil
}) })
w.start(ctx)
return nil return nil
} }
type watcher struct { type watcher struct {
started bool
addonCache v1.AddonClientCache addonCache v1.AddonClientCache
addons v1.AddonClient addons v1.AddonClient
bases []string bases []string
@ -77,14 +71,17 @@ type watcher struct {
} }
func (w *watcher) start(ctx context.Context) { func (w *watcher) start(ctx context.Context) {
force := true
for { for {
if err := w.listFiles(force); err == nil {
force = false
} else {
logrus.Errorf("failed to process config: %v", err)
}
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case <-time.After(15 * time.Second): case <-time.After(15 * time.Second):
if err := w.listFiles(false); err != nil {
logrus.Errorf("failed to process config: %v", err)
}
} }
} }
} }
@ -101,10 +98,6 @@ func (w *watcher) listFiles(force bool) error {
} }
func (w *watcher) listFilesIn(base string, force bool) error { func (w *watcher) listFilesIn(base string, force bool) error {
if !w.started {
return nil
}
files, err := ioutil.ReadDir(base) files, err := ioutil.ReadDir(base)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil return nil

View File

@ -2,6 +2,8 @@ package helm
import ( import (
"context" "context"
"crypto/sha256"
"encoding/hex"
"fmt" "fmt"
"sort" "sort"
@ -22,7 +24,7 @@ import (
const ( const (
namespace = "kube-system" namespace = "kube-system"
image = "rancher/klipper-helm:v0.1.2" image = "rancher/klipper-helm:v0.1.3"
label = "helm.k3s.cattle.io/chart" label = "helm.k3s.cattle.io/chart"
) )
@ -124,6 +126,7 @@ func (h *handler) onRemove(chart *k3s.HelmChart) (runtime.Object, error) {
func job(chart *k3s.HelmChart) (*batch.Job, *core.ConfigMap) { func job(chart *k3s.HelmChart) (*batch.Job, *core.ConfigMap) {
oneThousand := int32(1000) oneThousand := int32(1000)
valuesHash := sha256.Sum256([]byte(chart.Spec.ValuesContent))
action := "install" action := "install"
if chart.DeletionTimestamp != nil { if chart.DeletionTimestamp != nil {
@ -170,6 +173,10 @@ func job(chart *k3s.HelmChart) (*batch.Job, *core.ConfigMap) {
Name: "REPO", Name: "REPO",
Value: chart.Spec.Repo, Value: chart.Spec.Repo,
}, },
{
Name: "VALUES_HASH",
Value: hex.EncodeToString(valuesHash[:]),
},
}, },
}, },
}, },