From ac7eaea9eaf9e5c6294a0713088a67b1e5e777ca Mon Sep 17 00:00:00 2001 From: galal-hussein Date: Sat, 6 Jun 2020 00:24:32 +0200 Subject: [PATCH] upgrade helm to v0.6.1 --- go.mod | 2 +- go.sum | 4 +- .../pkg/apis/helm.cattle.io/v1/types.go | 1 + .../controllers/helm.cattle.io/factory.go | 35 ++++++++++----- .../helm.cattle.io/v1/helmchart.go | 45 ++++++++++--------- .../helm-controller/pkg/helm/controller.go | 22 +++++++++ vendor/modules.txt | 2 +- 7 files changed, 75 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 14e140908a..d198a3178a 100644 --- a/go.mod +++ b/go.mod @@ -100,7 +100,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/rakelkar/gonetsh v0.0.0-20190719023240-501daadcadf8 // indirect github.com/rancher/dynamiclistener v0.2.0 - github.com/rancher/helm-controller v0.6.0 + github.com/rancher/helm-controller v0.6.1 github.com/rancher/kine v0.4.0 github.com/rancher/remotedialer v0.2.0 github.com/rancher/wrangler v0.6.1 diff --git a/go.sum b/go.sum index 4c18fa86f0..2026795515 100644 --- a/go.sum +++ b/go.sum @@ -635,8 +635,8 @@ github.com/rancher/dynamiclistener v0.2.0 h1:KucYwJXVVGhZ/NndfMCeQoCafT/VN7kvqSG github.com/rancher/dynamiclistener v0.2.0/go.mod h1:fs/dxyNcB3YT6W9fVz4bDGfhmSQS17QQup6BIcGF++s= github.com/rancher/flannel v0.11.0-k3s.2 h1:0GVr5ORAIvcri1LYTE8eMQ+NrRbuPeIniPaW51IzLco= github.com/rancher/flannel v0.11.0-k3s.2/go.mod h1:Hn4ZV+eq0LhLZP63xZnxdGwXEoRSxs5sxELxu27M3UA= -github.com/rancher/helm-controller v0.6.0 h1:nFptBZFWpHga65M6bP04BZGLlzeMgezAXdsOwaB8t+4= -github.com/rancher/helm-controller v0.6.0/go.mod h1:ZylsxIMGNADRPRNW+NiBWhrwwks9vnKLQiCHYWb6Bi0= +github.com/rancher/helm-controller v0.6.1 h1:Cle27kA+yBZao6EAE8zN9NDEwrPkLp6m39EX5YpPRVM= +github.com/rancher/helm-controller v0.6.1/go.mod h1:ZylsxIMGNADRPRNW+NiBWhrwwks9vnKLQiCHYWb6Bi0= github.com/rancher/kine v0.4.0 h1:1IhWy3TzjExG8xnj46eyUEWdzqNAD1WrgL4eEBKm6Uc= github.com/rancher/kine v0.4.0/go.mod h1:IImtCJ68AIkE+VY/kUI0NkyJL5q5WzO8QvMsSXqbrpA= github.com/rancher/kubernetes v1.18.3-k3s1 h1:QYh2MY+odOzBQedwClFdX1tRtYQADaFRWi+etbBJvuU= diff --git a/vendor/github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1/types.go b/vendor/github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1/types.go index ccb05e35c8..2928beb0c0 100644 --- a/vendor/github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1/types.go +++ b/vendor/github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1/types.go @@ -24,6 +24,7 @@ type HelmChartSpec struct { Set map[string]intstr.IntOrString `json:"set,omitempty"` ValuesContent string `json:"valuesContent,omitempty"` HelmVersion string `json:"helmVersion,omitempty"` + Bootstrap bool `json:"bootstrap,omitempty"` } type HelmChartStatus struct { diff --git a/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/factory.go b/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/factory.go index 76d9467a66..a77b70c221 100644 --- a/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/factory.go +++ b/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/factory.go @@ -52,18 +52,23 @@ func NewFactoryFromConfigOrDie(config *rest.Config) *Factory { } func NewFactoryFromConfig(config *rest.Config) (*Factory, error) { - cs, err := clientset.NewForConfig(config) - if err != nil { - return nil, err - } - - informerFactory := informers.NewSharedInformerFactory(cs, 2*time.Hour) - return NewFactory(cs, informerFactory), nil + return NewFactoryFromConfigWithOptions(config, nil) } func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) { - if namespace == "" { - return NewFactoryFromConfig(config) + return NewFactoryFromConfigWithOptions(config, &FactoryOptions{ + Namespace: namespace, + }) +} + +type FactoryOptions struct { + Namespace string + Resync time.Duration +} + +func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) { + if opts == nil { + opts = &FactoryOptions{} } cs, err := clientset.NewForConfig(config) @@ -71,7 +76,17 @@ func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (* return nil, err } - informerFactory := informers.NewSharedInformerFactoryWithOptions(cs, 2*time.Hour, informers.WithNamespace(namespace)) + resync := opts.Resync + if resync == 0 { + resync = 2 * time.Hour + } + + if opts.Namespace == "" { + informerFactory := informers.NewSharedInformerFactory(cs, resync) + return NewFactory(cs, informerFactory), nil + } + + informerFactory := informers.NewSharedInformerFactoryWithOptions(cs, resync, informers.WithNamespace(opts.Namespace)) return NewFactory(cs, informerFactory), nil } diff --git a/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go b/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go index 58c79cad92..0650a6a4c9 100644 --- a/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go +++ b/vendor/github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go @@ -29,6 +29,7 @@ import ( "github.com/rancher/wrangler/pkg/apply" "github.com/rancher/wrangler/pkg/condition" "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/pkg/kv" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -267,6 +268,7 @@ func RegisterHelmChartGeneratingHandler(ctx context.Context, controller HelmChar if opts != nil { statusHandler.opts = *opts } + controller.OnChange(ctx, name, statusHandler.Remove) RegisterHelmChartStatusHandler(ctx, controller, condition, name, statusHandler.Handle) } @@ -281,7 +283,7 @@ func (a *helmChartStatusHandler) sync(key string, obj *v1.HelmChart) (*v1.HelmCh return obj, nil } - origStatus := obj.Status + origStatus := obj.Status.DeepCopy() obj = obj.DeepCopy() newStatus, err := a.handler(obj, obj.Status) if err != nil { @@ -289,16 +291,16 @@ func (a *helmChartStatusHandler) sync(key string, obj *v1.HelmChart) (*v1.HelmCh newStatus = *origStatus.DeepCopy() } - obj.Status = newStatus if a.condition != "" { if errors.IsConflict(err) { - a.condition.SetError(obj, "", nil) + a.condition.SetError(&newStatus, "", nil) } else { - a.condition.SetError(obj, "", err) + a.condition.SetError(&newStatus, "", err) } } - if !equality.Semantic.DeepEqual(origStatus, obj.Status) { + if !equality.Semantic.DeepEqual(origStatus, &newStatus) { var newErr error + obj.Status = newStatus obj, newErr = a.client.UpdateStatus(obj) if err == nil { err = newErr @@ -315,29 +317,28 @@ type helmChartGeneratingHandler struct { name string } +func (a *helmChartGeneratingHandler) Remove(key string, obj *v1.HelmChart) (*v1.HelmChart, error) { + if obj != nil { + return obj, nil + } + + obj = &v1.HelmChart{} + obj.Namespace, obj.Name = kv.RSplit(key, "/") + obj.SetGroupVersionKind(a.gvk) + + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects() +} + func (a *helmChartGeneratingHandler) Handle(obj *v1.HelmChart, status v1.HelmChartStatus) (v1.HelmChartStatus, error) { objs, newStatus, err := a.HelmChartGeneratingHandler(obj, status) if err != nil { return newStatus, err } - apply := a.apply - - if !a.opts.DynamicLookup { - apply = apply.WithStrictCaching() - } - - if !a.opts.AllowCrossNamespace && !a.opts.AllowClusterScoped { - apply = apply.WithSetOwnerReference(true, false). - WithDefaultNamespace(obj.GetNamespace()). - WithListerNamespace(obj.GetNamespace()) - } - - if !a.opts.AllowClusterScoped { - apply = apply.WithRestrictClusterScoped() - } - - return newStatus, apply. + return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). WithOwner(obj). WithSetID(a.name). ApplyObjects(objs...) diff --git a/vendor/github.com/rancher/helm-controller/pkg/helm/controller.go b/vendor/github.com/rancher/helm-controller/pkg/helm/controller.go index 3bbf5df4a2..91a4101ace 100644 --- a/vendor/github.com/rancher/helm-controller/pkg/helm/controller.go +++ b/vendor/github.com/rancher/helm-controller/pkg/helm/controller.go @@ -155,6 +155,7 @@ func job(chart *helmv1.HelmChart) (*batch.Job, *core.ConfigMap) { if chart.DeletionTimestamp != nil { action = "delete" } + job := &batch.Job{ TypeMeta: meta.TypeMeta{ APIVersion: "batch/v1", @@ -224,6 +225,27 @@ func job(chart *helmv1.HelmChart) (*batch.Job, *core.ConfigMap) { }, }, } + + if chart.Spec.Bootstrap { + job.Spec.Template.Spec.HostNetwork = true + job.Spec.Template.Spec.Tolerations = []core.Toleration{ + { + Key: "node.kubernetes.io/not-ready", + Effect: "NoSchedule", + }, + } + job.Spec.Template.Spec.Containers[0].Env = append(job.Spec.Template.Spec.Containers[0].Env, []core.EnvVar{ + { + Name: "KUBERNETES_SERVICE_HOST", + Value: "127.0.0.1"}, + { + Name: "KUBERNETES_SERVICE_PORT", + Value: "6443"}, + }...) + job.Spec.Template.Spec.NodeSelector = make(map[string]string) + job.Spec.Template.Spec.NodeSelector["node-role.kubernetes.io/master"] = "true" + } + setProxyEnv(job) configMap := configMap(chart) if configMap == nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 5914e1a582..b2320dada4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -724,7 +724,7 @@ github.com/rancher/dynamiclistener/factory github.com/rancher/dynamiclistener/storage/file github.com/rancher/dynamiclistener/storage/kubernetes github.com/rancher/dynamiclistener/storage/memory -# github.com/rancher/helm-controller v0.6.0 +# github.com/rancher/helm-controller v0.6.1 github.com/rancher/helm-controller/pkg/apis/helm.cattle.io github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1 github.com/rancher/helm-controller/pkg/generated/clientset/versioned