Unverified Commit c980fa68 authored by Brad Davidson's avatar Brad Davidson Committed by GitHub

Update helm-controller for HelmChartConfig CRD (#2114)

* Update helm-controller for HelmChartConfig CRD Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent a2471a1f
......@@ -95,7 +95,7 @@ require (
github.com/opencontainers/selinux v1.5.3-0.20200613095409-bb88c45a3863
github.com/pkg/errors v0.9.1
github.com/rancher/dynamiclistener v0.2.1
github.com/rancher/helm-controller v0.6.5
github.com/rancher/helm-controller v0.7.0
github.com/rancher/kine v0.4.0
github.com/rancher/remotedialer v0.2.0
github.com/rancher/spur v0.0.0-20200617165101-8702c8e4ce7a
......
......@@ -640,8 +640,8 @@ github.com/rancher/go-powershell v0.0.0-20200701182037-6845e6fcfa79 h1:UeC0rjrIe
github.com/rancher/go-powershell v0.0.0-20200701182037-6845e6fcfa79/go.mod h1:xi4WpK6Op4m1Lknq61/e+VSjYlTs9bulVOaDNyBdzvk=
github.com/rancher/go-powershell v0.0.0-20200701184732-233247d45373 h1:BePi97poJ4hXnkP9yX96EmNQgMg+dGScvB1sqIheJ7w=
github.com/rancher/go-powershell v0.0.0-20200701184732-233247d45373/go.mod h1:Vz8oLnHgttpo/aZrTpjbcpZEDzzElqNau2zmorToY0E=
github.com/rancher/helm-controller v0.6.5 h1:gL6R3fbsBFBnrp2Wc36zn0zLQ8q2ckbLpfaN2XkrLVE=
github.com/rancher/helm-controller v0.6.5/go.mod h1:ZylsxIMGNADRPRNW+NiBWhrwwks9vnKLQiCHYWb6Bi0=
github.com/rancher/helm-controller v0.7.0 h1:UMMRwTpBzUt2mPH89vFNm4pVpUHPaFj1Z5+WnS7jEOk=
github.com/rancher/helm-controller v0.7.0/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.8-k3s1 h1:dqukpA38pR5V7opoTDDslVYIxlM3sP5535u3Zd23W2I=
......
......@@ -63,7 +63,8 @@ func crds(ctx context.Context, config *rest.Config) error {
factory.BatchCreateCRDs(ctx, crd.NamespacedTypes(
"Addon.k3s.cattle.io/v1",
"HelmChart.helm.cattle.io/v1")...)
"HelmChart.helm.cattle.io/v1",
"HelmChartConfig.helm.cattle.io/v1")...)
return factory.BatchWait()
}
......@@ -170,6 +170,7 @@ func masterControllers(ctx context.Context, sc *Context, config *Config) error {
helm.Register(ctx, sc.Apply,
sc.Helm.Helm().V1().HelmChart(),
sc.Helm.Helm().V1().HelmChartConfig(),
sc.Batch.Batch().V1().Job(),
sc.Auth.Rbac().V1().ClusterRoleBinding(),
sc.Core.Core().V1().ServiceAccount(),
......
docker.io/rancher/coredns-coredns:1.6.9
docker.io/rancher/klipper-helm:v0.2.7
docker.io/rancher/klipper-helm:v0.3.0
docker.io/rancher/klipper-lb:v0.1.2
docker.io/rancher/library-traefik:1.7.19
docker.io/rancher/local-path-provisioner:v0.0.14
......
......@@ -31,3 +31,17 @@ type HelmChartSpec struct {
type HelmChartStatus struct {
JobName string `json:"jobName,omitempty"`
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type HelmChartConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec HelmChartConfigSpec `json:"spec,omitempty"`
}
type HelmChartConfigSpec struct {
ValuesContent string `json:"valuesContent,omitempty"`
}
......@@ -54,6 +54,82 @@ func (in *HelmChart) DeepCopyObject() runtime.Object {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HelmChartConfig) DeepCopyInto(out *HelmChartConfig) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartConfig.
func (in *HelmChartConfig) DeepCopy() *HelmChartConfig {
if in == nil {
return nil
}
out := new(HelmChartConfig)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *HelmChartConfig) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HelmChartConfigList) DeepCopyInto(out *HelmChartConfigList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]HelmChartConfig, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartConfigList.
func (in *HelmChartConfigList) DeepCopy() *HelmChartConfigList {
if in == nil {
return nil
}
out := new(HelmChartConfigList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *HelmChartConfigList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HelmChartConfigSpec) DeepCopyInto(out *HelmChartConfigSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartConfigSpec.
func (in *HelmChartConfigSpec) DeepCopy() *HelmChartConfigSpec {
if in == nil {
return nil
}
out := new(HelmChartConfigSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HelmChartList) DeepCopyInto(out *HelmChartList) {
*out = *in
out.TypeMeta = in.TypeMeta
......
......@@ -40,3 +40,20 @@ func NewHelmChart(namespace, name string, obj HelmChart) *HelmChart {
obj.Namespace = namespace
return &obj
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// HelmChartConfigList is a list of HelmChartConfig resources
type HelmChartConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []HelmChartConfig `json:"items"`
}
func NewHelmChartConfig(namespace, name string, obj HelmChartConfig) *HelmChartConfig {
obj.APIVersion, obj.Kind = SchemeGroupVersion.WithKind("HelmChartConfig").ToAPIVersionAndKind()
obj.Name = name
obj.Namespace = namespace
return &obj
}
......@@ -28,7 +28,8 @@ import (
)
var (
HelmChartResourceName = "helmcharts"
HelmChartResourceName = "helmcharts"
HelmChartConfigResourceName = "helmchartconfigs"
)
// SchemeGroupVersion is group version used to register these objects
......@@ -54,6 +55,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&HelmChart{},
&HelmChartList{},
&HelmChartConfig{},
&HelmChartConfigList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
......
......@@ -19,3 +19,5 @@ limitations under the License.
package v1
type HelmChartExpansion interface{}
type HelmChartConfigExpansion interface{}
......@@ -27,6 +27,7 @@ import (
type HelmV1Interface interface {
RESTClient() rest.Interface
HelmChartsGetter
HelmChartConfigsGetter
}
// HelmV1Client is used to interact with features provided by the helm.cattle.io group.
......@@ -38,6 +39,10 @@ func (c *HelmV1Client) HelmCharts(namespace string) HelmChartInterface {
return newHelmCharts(c, namespace)
}
func (c *HelmV1Client) HelmChartConfigs(namespace string) HelmChartConfigInterface {
return newHelmChartConfigs(c, namespace)
}
// NewForConfig creates a new HelmV1Client for the given config.
func NewForConfig(c *rest.Config) (*HelmV1Client, error) {
config := *c
......
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
"time"
v1 "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1"
scheme "github.com/rancher/helm-controller/pkg/generated/clientset/versioned/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// HelmChartConfigsGetter has a method to return a HelmChartConfigInterface.
// A group's client should implement this interface.
type HelmChartConfigsGetter interface {
HelmChartConfigs(namespace string) HelmChartConfigInterface
}
// HelmChartConfigInterface has methods to work with HelmChartConfig resources.
type HelmChartConfigInterface interface {
Create(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.CreateOptions) (*v1.HelmChartConfig, error)
Update(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.UpdateOptions) (*v1.HelmChartConfig, error)
Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error
Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.HelmChartConfig, error)
List(ctx context.Context, opts metav1.ListOptions) (*v1.HelmChartConfigList, error)
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.HelmChartConfig, err error)
HelmChartConfigExpansion
}
// helmChartConfigs implements HelmChartConfigInterface
type helmChartConfigs struct {
client rest.Interface
ns string
}
// newHelmChartConfigs returns a HelmChartConfigs
func newHelmChartConfigs(c *HelmV1Client, namespace string) *helmChartConfigs {
return &helmChartConfigs{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the helmChartConfig, and returns the corresponding helmChartConfig object, and an error if there is any.
func (c *helmChartConfigs) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Get().
Namespace(c.ns).
Resource("helmchartconfigs").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of HelmChartConfigs that match those selectors.
func (c *helmChartConfigs) List(ctx context.Context, opts metav1.ListOptions) (result *v1.HelmChartConfigList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1.HelmChartConfigList{}
err = c.client.Get().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested helmChartConfigs.
func (c *helmChartConfigs) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a helmChartConfig and creates it. Returns the server's representation of the helmChartConfig, and an error, if there is any.
func (c *helmChartConfigs) Create(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.CreateOptions) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Post().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&opts, scheme.ParameterCodec).
Body(helmChartConfig).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a helmChartConfig and updates it. Returns the server's representation of the helmChartConfig, and an error, if there is any.
func (c *helmChartConfigs) Update(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.UpdateOptions) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Put().
Namespace(c.ns).
Resource("helmchartconfigs").
Name(helmChartConfig.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(helmChartConfig).
Do(ctx).
Into(result)
return
}
// Delete takes name of the helmChartConfig and deletes it. Returns an error if one occurs.
func (c *helmChartConfigs) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("helmchartconfigs").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *helmChartConfigs) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched helmChartConfig.
func (c *helmChartConfigs) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("helmchartconfigs").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
"time"
v1 "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1"
clientset "github.com/rancher/helm-controller/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1"
informers "github.com/rancher/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io/v1"
listers "github.com/rancher/helm-controller/pkg/generated/listers/helm.cattle.io/v1"
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
type HelmChartConfigHandler func(string, *v1.HelmChartConfig) (*v1.HelmChartConfig, error)
type HelmChartConfigController interface {
generic.ControllerMeta
HelmChartConfigClient
OnChange(ctx context.Context, name string, sync HelmChartConfigHandler)
OnRemove(ctx context.Context, name string, sync HelmChartConfigHandler)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, duration time.Duration)
Cache() HelmChartConfigCache
}
type HelmChartConfigClient interface {
Create(*v1.HelmChartConfig) (*v1.HelmChartConfig, error)
Update(*v1.HelmChartConfig) (*v1.HelmChartConfig, error)
Delete(namespace, name string, options *metav1.DeleteOptions) error
Get(namespace, name string, options metav1.GetOptions) (*v1.HelmChartConfig, error)
List(namespace string, opts metav1.ListOptions) (*v1.HelmChartConfigList, error)
Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error)
Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.HelmChartConfig, err error)
}
type HelmChartConfigCache interface {
Get(namespace, name string) (*v1.HelmChartConfig, error)
List(namespace string, selector labels.Selector) ([]*v1.HelmChartConfig, error)
AddIndexer(indexName string, indexer HelmChartConfigIndexer)
GetByIndex(indexName, key string) ([]*v1.HelmChartConfig, error)
}
type HelmChartConfigIndexer func(obj *v1.HelmChartConfig) ([]string, error)
type helmChartConfigController struct {
controllerManager *generic.ControllerManager
clientGetter clientset.HelmChartConfigsGetter
informer informers.HelmChartConfigInformer
gvk schema.GroupVersionKind
}
func NewHelmChartConfigController(gvk schema.GroupVersionKind, controllerManager *generic.ControllerManager, clientGetter clientset.HelmChartConfigsGetter, informer informers.HelmChartConfigInformer) HelmChartConfigController {
return &helmChartConfigController{
controllerManager: controllerManager,
clientGetter: clientGetter,
informer: informer,
gvk: gvk,
}
}
func FromHelmChartConfigHandlerToHandler(sync HelmChartConfigHandler) generic.Handler {
return func(key string, obj runtime.Object) (ret runtime.Object, err error) {
var v *v1.HelmChartConfig
if obj == nil {
v, err = sync(key, nil)
} else {
v, err = sync(key, obj.(*v1.HelmChartConfig))
}
if v == nil {
return nil, err
}
return v, err
}
}
func (c *helmChartConfigController) Updater() generic.Updater {
return func(obj runtime.Object) (runtime.Object, error) {
newObj, err := c.Update(obj.(*v1.HelmChartConfig))
if newObj == nil {
return nil, err
}
return newObj, err
}
}
func UpdateHelmChartConfigDeepCopyOnChange(client HelmChartConfigClient, obj *v1.HelmChartConfig, handler func(obj *v1.HelmChartConfig) (*v1.HelmChartConfig, error)) (*v1.HelmChartConfig, error) {
if obj == nil {
return obj, nil
}
copyObj := obj.DeepCopy()
newObj, err := handler(copyObj)
if newObj != nil {
copyObj = newObj
}
if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) {
return client.Update(copyObj)
}
return copyObj, err
}
func (c *helmChartConfigController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, handler)
}
func (c *helmChartConfigController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), handler)
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, removeHandler)
}
func (c *helmChartConfigController) OnChange(ctx context.Context, name string, sync HelmChartConfigHandler) {
c.AddGenericHandler(ctx, name, FromHelmChartConfigHandlerToHandler(sync))
}
func (c *helmChartConfigController) OnRemove(ctx context.Context, name string, sync HelmChartConfigHandler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), FromHelmChartConfigHandlerToHandler(sync))
c.AddGenericHandler(ctx, name, removeHandler)
}
func (c *helmChartConfigController) Enqueue(namespace, name string) {
c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name)
}
func (c *helmChartConfigController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration)
}
func (c *helmChartConfigController) Informer() cache.SharedIndexInformer {
return c.informer.Informer()
}
func (c *helmChartConfigController) GroupVersionKind() schema.GroupVersionKind {
return c.gvk
}
func (c *helmChartConfigController) Cache() HelmChartConfigCache {
return &helmChartConfigCache{
lister: c.informer.Lister(),
indexer: c.informer.Informer().GetIndexer(),
}
}
func (c *helmChartConfigController) Create(obj *v1.HelmChartConfig) (*v1.HelmChartConfig, error) {
return c.clientGetter.HelmChartConfigs(obj.Namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
}
func (c *helmChartConfigController) Update(obj *v1.HelmChartConfig) (*v1.HelmChartConfig, error) {
return c.clientGetter.HelmChartConfigs(obj.Namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
}
func (c *helmChartConfigController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.clientGetter.HelmChartConfigs(namespace).Delete(context.TODO(), name, *options)
}
func (c *helmChartConfigController) Get(namespace, name string, options metav1.GetOptions) (*v1.HelmChartConfig, error) {
return c.clientGetter.HelmChartConfigs(namespace).Get(context.TODO(), name, options)
}
func (c *helmChartConfigController) List(namespace string, opts metav1.ListOptions) (*v1.HelmChartConfigList, error) {
return c.clientGetter.HelmChartConfigs(namespace).List(context.TODO(), opts)
}
func (c *helmChartConfigController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.clientGetter.HelmChartConfigs(namespace).Watch(context.TODO(), opts)
}
func (c *helmChartConfigController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.HelmChartConfig, err error) {
return c.clientGetter.HelmChartConfigs(namespace).Patch(context.TODO(), name, pt, data, metav1.PatchOptions{}, subresources...)
}
type helmChartConfigCache struct {
lister listers.HelmChartConfigLister
indexer cache.Indexer
}
func (c *helmChartConfigCache) Get(namespace, name string) (*v1.HelmChartConfig, error) {
return c.lister.HelmChartConfigs(namespace).Get(name)
}
func (c *helmChartConfigCache) List(namespace string, selector labels.Selector) ([]*v1.HelmChartConfig, error) {
return c.lister.HelmChartConfigs(namespace).List(selector)
}
func (c *helmChartConfigCache) AddIndexer(indexName string, indexer HelmChartConfigIndexer) {
utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{
indexName: func(obj interface{}) (strings []string, e error) {
return indexer(obj.(*v1.HelmChartConfig))
},
}))
}
func (c *helmChartConfigCache) GetByIndex(indexName, key string) (result []*v1.HelmChartConfig, err error) {
objs, err := c.indexer.ByIndex(indexName, key)
if err != nil {
return nil, err
}
result = make([]*v1.HelmChartConfig, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.HelmChartConfig))
}
return result, nil
}
......@@ -27,6 +27,7 @@ import (
type Interface interface {
HelmChart() HelmChartController
HelmChartConfig() HelmChartConfigController
}
func New(controllerManager *generic.ControllerManager, client clientset.HelmV1Interface,
......@@ -47,3 +48,6 @@ type version struct {
func (c *version) HelmChart() HelmChartController {
return NewHelmChartController(v1.SchemeGroupVersion.WithKind("HelmChart"), c.controllerManager, c.client, c.informers.HelmCharts())
}
func (c *version) HelmChartConfig() HelmChartConfigController {
return NewHelmChartConfigController(v1.SchemeGroupVersion.WithKind("HelmChartConfig"), c.controllerManager, c.client, c.informers.HelmChartConfigs())
}
......@@ -55,6 +55,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource
// Group=helm.cattle.io, Version=v1
case v1.SchemeGroupVersion.WithResource("helmcharts"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Helm().V1().HelmCharts().Informer()}, nil
case v1.SchemeGroupVersion.WithResource("helmchartconfigs"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Helm().V1().HelmChartConfigs().Informer()}, nil
}
......
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
"context"
time "time"
helmcattleiov1 "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1"
versioned "github.com/rancher/helm-controller/pkg/generated/clientset/versioned"
internalinterfaces "github.com/rancher/helm-controller/pkg/generated/informers/externalversions/internalinterfaces"
v1 "github.com/rancher/helm-controller/pkg/generated/listers/helm.cattle.io/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
watch "k8s.io/apimachinery/pkg/watch"
cache "k8s.io/client-go/tools/cache"
)
// HelmChartConfigInformer provides access to a shared informer and lister for
// HelmChartConfigs.
type HelmChartConfigInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1.HelmChartConfigLister
}
type helmChartConfigInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
namespace string
}
// NewHelmChartConfigInformer constructs a new informer for HelmChartConfig type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewHelmChartConfigInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredHelmChartConfigInformer(client, namespace, resyncPeriod, indexers, nil)
}
// NewFilteredHelmChartConfigInformer constructs a new informer for HelmChartConfig type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewFilteredHelmChartConfigInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.HelmV1().HelmChartConfigs(namespace).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.HelmV1().HelmChartConfigs(namespace).Watch(context.TODO(), options)
},
},
&helmcattleiov1.HelmChartConfig{},
resyncPeriod,
indexers,
)
}
func (f *helmChartConfigInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredHelmChartConfigInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *helmChartConfigInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&helmcattleiov1.HelmChartConfig{}, f.defaultInformer)
}
func (f *helmChartConfigInformer) Lister() v1.HelmChartConfigLister {
return v1.NewHelmChartConfigLister(f.Informer().GetIndexer())
}
......@@ -26,6 +26,8 @@ import (
type Interface interface {
// HelmCharts returns a HelmChartInformer.
HelmCharts() HelmChartInformer
// HelmChartConfigs returns a HelmChartConfigInformer.
HelmChartConfigs() HelmChartConfigInformer
}
type version struct {
......@@ -43,3 +45,8 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList
func (v *version) HelmCharts() HelmChartInformer {
return &helmChartInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
// HelmChartConfigs returns a HelmChartConfigInformer.
func (v *version) HelmChartConfigs() HelmChartConfigInformer {
return &helmChartConfigInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
......@@ -25,3 +25,11 @@ type HelmChartListerExpansion interface{}
// HelmChartNamespaceListerExpansion allows custom methods to be added to
// HelmChartNamespaceLister.
type HelmChartNamespaceListerExpansion interface{}
// HelmChartConfigListerExpansion allows custom methods to be added to
// HelmChartConfigLister.
type HelmChartConfigListerExpansion interface{}
// HelmChartConfigNamespaceListerExpansion allows custom methods to be added to
// HelmChartConfigNamespaceLister.
type HelmChartConfigNamespaceListerExpansion interface{}
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by main. DO NOT EDIT.
package v1
import (
v1 "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// HelmChartConfigLister helps list HelmChartConfigs.
type HelmChartConfigLister interface {
// List lists all HelmChartConfigs in the indexer.
List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error)
// HelmChartConfigs returns an object that can list and get HelmChartConfigs.
HelmChartConfigs(namespace string) HelmChartConfigNamespaceLister
HelmChartConfigListerExpansion
}
// helmChartConfigLister implements the HelmChartConfigLister interface.
type helmChartConfigLister struct {
indexer cache.Indexer
}
// NewHelmChartConfigLister returns a new HelmChartConfigLister.
func NewHelmChartConfigLister(indexer cache.Indexer) HelmChartConfigLister {
return &helmChartConfigLister{indexer: indexer}
}
// List lists all HelmChartConfigs in the indexer.
func (s *helmChartConfigLister) List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChartConfig))
})
return ret, err
}
// HelmChartConfigs returns an object that can list and get HelmChartConfigs.
func (s *helmChartConfigLister) HelmChartConfigs(namespace string) HelmChartConfigNamespaceLister {
return helmChartConfigNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// HelmChartConfigNamespaceLister helps list and get HelmChartConfigs.
type HelmChartConfigNamespaceLister interface {
// List lists all HelmChartConfigs in the indexer for a given namespace.
List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error)
// Get retrieves the HelmChartConfig from the indexer for a given namespace and name.
Get(name string) (*v1.HelmChartConfig, error)
HelmChartConfigNamespaceListerExpansion
}
// helmChartConfigNamespaceLister implements the HelmChartConfigNamespaceLister
// interface.
type helmChartConfigNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all HelmChartConfigs in the indexer for a given namespace.
func (s helmChartConfigNamespaceLister) List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChartConfig))
})
return ret, err
}
// Get retrieves the HelmChartConfig from the indexer for a given namespace and name.
func (s helmChartConfigNamespaceLister) Get(name string) (*v1.HelmChartConfig, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1.Resource("helmchartconfig"), name)
}
return obj.(*v1.HelmChartConfig), nil
}
......@@ -3,7 +3,6 @@ package helm
import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
"sort"
......@@ -33,25 +32,29 @@ var (
type Controller struct {
namespace string
helmController helmcontroller.HelmChartController
confController helmcontroller.HelmChartConfigController
jobsCache batchcontroller.JobCache
apply apply.Apply
}
const (
image = "rancher/klipper-helm:v0.2.7"
Label = "helmcharts.helm.cattle.io/chart"
CRDName = "helmcharts.helm.cattle.io"
Name = "helm-controller"
image = "rancher/klipper-helm:v0.3.0"
Label = "helmcharts.helm.cattle.io/chart"
Annotation = "helmcharts.helm.cattle.io/configHash"
CRDName = "helmcharts.helm.cattle.io"
ConfigCRDName = "helmchartconfigs.helm.cattle.io"
Name = "helm-controller"
)
func Register(ctx context.Context, apply apply.Apply,
helms helmcontroller.HelmChartController,
confs helmcontroller.HelmChartConfigController,
jobs batchcontroller.JobController,
crbs rbaccontroller.ClusterRoleBindingController,
sas corecontroller.ServiceAccountController,
cm corecontroller.ConfigMapController) {
apply = apply.WithSetID(Name).
WithCacheTypes(helms, jobs, crbs, sas, cm).
WithCacheTypes(helms, confs, jobs, crbs, sas, cm).
WithStrictCaching().WithPatcher(batch.SchemeGroupVersion.WithKind("Job"), func(namespace, name string, pt types.PatchType, data []byte) (runtime.Object, error) {
err := jobs.Delete(namespace, name, &meta.DeleteOptions{})
if err == nil {
......@@ -76,23 +79,25 @@ func Register(ctx context.Context, apply apply.Apply,
return nil, nil
},
helms,
confs,
jobs)
controller := &Controller{
helmController: helms,
confController: confs,
jobsCache: jobs.Cache(),
apply: apply,
}
helms.OnChange(ctx, Name, controller.OnHelmChanged)
helms.OnChange(ctx, Name, controller.OnHelmChange)
helms.OnRemove(ctx, Name, controller.OnHelmRemove)
confs.OnChange(ctx, Name, controller.OnConfChange)
}
func (c *Controller) OnHelmChanged(key string, chart *helmv1.HelmChart) (*helmv1.HelmChart, error) {
func (c *Controller) OnHelmChange(key string, chart *helmv1.HelmChart) (*helmv1.HelmChart, error) {
if chart == nil {
return nil, nil
}
if chart.Spec.Chart == "" && chart.Spec.ChartContent == "" {
return chart, nil
}
......@@ -101,14 +106,21 @@ func (c *Controller) OnHelmChanged(key string, chart *helmv1.HelmChart) (*helmv1
job, valuesConfigMap, contentConfigMap := job(chart)
objs.Add(serviceAccount(chart))
objs.Add(roleBinding(chart))
objs.Add(job)
if valuesConfigMap != nil {
objs.Add(valuesConfigMap)
}
if contentConfigMap != nil {
objs.Add(contentConfigMap)
if config, err := c.confController.Cache().Get(chart.Namespace, chart.Name); err != nil {
if !errors.IsNotFound(err) {
return chart, err
}
} else if config != nil {
valuesConfigMapAddConfig(valuesConfigMap, config)
}
hashConfigMaps(job, contentConfigMap, valuesConfigMap)
objs.Add(contentConfigMap)
objs.Add(valuesConfigMap)
objs.Add(job)
if err := c.apply.WithOwner(chart).Apply(objs); err != nil {
return chart, err
}
......@@ -119,14 +131,18 @@ func (c *Controller) OnHelmChanged(key string, chart *helmv1.HelmChart) (*helmv1
}
func (c *Controller) OnHelmRemove(key string, chart *helmv1.HelmChart) (*helmv1.HelmChart, error) {
if chart == nil {
return nil, nil
}
if chart.Spec.Chart == "" {
return chart, nil
}
job, _, _ := job(chart)
job, err := c.jobsCache.Get(chart.Namespace, job.Name)
if errors.IsNotFound(err) {
_, err := c.OnHelmChanged(key, chart)
_, err := c.OnHelmChange(key, chart)
if err != nil {
return chart, err
}
......@@ -135,7 +151,7 @@ func (c *Controller) OnHelmRemove(key string, chart *helmv1.HelmChart) (*helmv1.
}
if job.Status.Succeeded <= 0 {
return chart, fmt.Errorf("waiting for delete of helm chart %s", chart.Name)
return chart, fmt.Errorf("waiting for delete of helm chart for %s by %s", key, job.Name)
}
chartCopy := chart.DeepCopy()
......@@ -149,9 +165,23 @@ func (c *Controller) OnHelmRemove(key string, chart *helmv1.HelmChart) (*helmv1.
return newChart, c.apply.WithOwner(newChart).Apply(objectset.NewObjectSet())
}
func (c *Controller) OnConfChange(key string, conf *helmv1.HelmChartConfig) (*helmv1.HelmChartConfig, error) {
if conf == nil {
return nil, nil
}
if chart, err := c.helmController.Cache().Get(conf.Namespace, conf.Name); err != nil {
if !errors.IsNotFound(err) {
return conf, err
}
} else if chart != nil {
c.helmController.Enqueue(conf.Namespace, conf.Name)
}
return conf, nil
}
func job(chart *helmv1.HelmChart) (*batch.Job, *core.ConfigMap, *core.ConfigMap) {
oneThousand := int32(1000)
valuesHash := sha256.Sum256([]byte(chart.Spec.ValuesContent))
action := "install"
if chart.DeletionTimestamp != nil {
......@@ -174,6 +204,7 @@ func job(chart *helmv1.HelmChart) (*batch.Job, *core.ConfigMap, *core.ConfigMap)
BackoffLimit: &oneThousand,
Template: core.PodTemplateSpec{
ObjectMeta: meta.ObjectMeta{
Annotations: map[string]string{},
Labels: map[string]string{
Label: chart.Name,
},
......@@ -200,10 +231,6 @@ func job(chart *helmv1.HelmChart) (*batch.Job, *core.ConfigMap, *core.ConfigMap)
Value: chart.Spec.Repo,
},
{
Name: "VALUES_HASH",
Value: hex.EncodeToString(valuesHash[:]),
},
{
Name: "HELM_DRIVER",
Value: "secret",
},
......@@ -262,11 +289,7 @@ func job(chart *helmv1.HelmChart) (*batch.Job, *core.ConfigMap, *core.ConfigMap)
}
func valuesConfigMap(chart *helmv1.HelmChart) *core.ConfigMap {
if chart.Spec.ValuesContent == "" {
return nil
}
return &core.ConfigMap{
var configMap = &core.ConfigMap{
TypeMeta: meta.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
......@@ -275,9 +298,19 @@ func valuesConfigMap(chart *helmv1.HelmChart) *core.ConfigMap {
Name: fmt.Sprintf("chart-values-%s", chart.Name),
Namespace: chart.Namespace,
},
Data: map[string]string{
"values.yaml": chart.Spec.ValuesContent,
},
Data: map[string]string{},
}
if chart.Spec.ValuesContent != "" {
configMap.Data["values-01_HelmChart.yaml"] = chart.Spec.ValuesContent
}
return configMap
}
func valuesConfigMapAddConfig(configMap *core.ConfigMap, config *helmv1.HelmChartConfig) {
if config.Spec.ValuesContent != "" {
configMap.Data["values-10_HelmChartConfig.yaml"] = config.Spec.ValuesContent
}
}
......@@ -390,10 +423,7 @@ func setProxyEnv(job *batch.Job) {
}
func contentConfigMap(chart *helmv1.HelmChart) *core.ConfigMap {
if chart.Spec.ChartContent == "" {
return nil
}
return &core.ConfigMap{
configMap := &core.ConfigMap{
TypeMeta: meta.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
......@@ -402,17 +432,19 @@ func contentConfigMap(chart *helmv1.HelmChart) *core.ConfigMap {
Name: fmt.Sprintf("chart-content-%s", chart.Name),
Namespace: chart.Namespace,
},
Data: map[string]string{
fmt.Sprintf("%s.tgz.base64", chart.Name): chart.Spec.ChartContent,
},
Data: map[string]string{},
}
if chart.Spec.ChartContent != "" {
key := fmt.Sprintf("%s.tgz.base64", chart.Name)
configMap.Data[key] = chart.Spec.ValuesContent
}
return configMap
}
func setValuesConfigMap(job *batch.Job, chart *helmv1.HelmChart) *core.ConfigMap {
configMap := valuesConfigMap(chart)
if configMap == nil {
return nil
}
job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes, []core.Volume{
{
......@@ -465,3 +497,20 @@ func setContentConfigMap(job *batch.Job, chart *helmv1.HelmChart) *core.ConfigMa
return configMap
}
func hashConfigMaps(job *batch.Job, maps ...*core.ConfigMap) {
hash := sha256.New()
for _, configMap := range maps {
for k, v := range configMap.Data {
hash.Write([]byte(k))
hash.Write([]byte(v))
}
for k, v := range configMap.BinaryData {
hash.Write([]byte(k))
hash.Write(v)
}
}
job.Spec.Template.ObjectMeta.Annotations[Annotation] = fmt.Sprintf("SHA256=%X", hash.Sum(nil))
}
......@@ -736,7 +736,7 @@ github.com/rancher/dynamiclistener/storage/memory
# github.com/rancher/go-powershell v0.0.0-20200701182037-6845e6fcfa79
github.com/rancher/go-powershell/backend
github.com/rancher/go-powershell/utils
# github.com/rancher/helm-controller v0.6.5
# github.com/rancher/helm-controller v0.7.0
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment