Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Make all Helm releases through the operator #1906

Merged
merged 6 commits into from
Apr 16, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chart/flux/templates/helm-operator-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ spec:
shortNames:
- hr
scope: Namespaced
subresources:
status: {}
version: v1beta1
versions:
- name: v1beta1
Expand Down
29 changes: 15 additions & 14 deletions cmd/helm-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/workqueue"

"github.com/weaveworks/flux/checkpoint"
clientset "github.com/weaveworks/flux/integrations/client/clientset/versioned"
Expand Down Expand Up @@ -136,19 +137,19 @@ func main() {

cfg, err := clientcmd.BuildConfigFromFlags(*master, *kubeconfig)
if err != nil {
mainLogger.Log("error", fmt.Sprintf("Error building kubeconfig: %v", err))
mainLogger.Log("error", fmt.Sprintf("error building kubeconfig: %v", err))
os.Exit(1)
}

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
mainLogger.Log("error", fmt.Sprintf("Error building kubernetes clientset: %v", err))
mainLogger.Log("error", fmt.Sprintf("error building kubernetes clientset: %v", err))
os.Exit(1)
}

ifClient, err := clientset.NewForConfig(cfg)
if err != nil {
mainLogger.Log("error", fmt.Sprintf("Error building integrations clientset: %v", err))
mainLogger.Log("error", fmt.Sprintf("error building integrations clientset: %v", err))
os.Exit(1)
}

Expand All @@ -169,27 +170,27 @@ func main() {
statusUpdater := status.New(ifClient, kubeClient, helmClient, *namespace)
go statusUpdater.Loop(shutdown, log.With(logger, "component", "annotator"))

// release instance is needed during the sync of Charts changes and during the sync of HelmRelease changes
nsOpt := ifinformers.WithNamespace(*namespace)
ifInformerFactory := ifinformers.NewSharedInformerFactoryWithOptions(ifClient, *chartsSyncInterval, nsOpt)
fhrInformer := ifInformerFactory.Flux().V1beta1().HelmReleases()
go ifInformerFactory.Start(shutdown)

queue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ChartRelease")

// release instance is needed during the sync of git chart changes and during the sync of HelmRelease changes
rel := release.New(log.With(logger, "component", "release"), helmClient)
chartSync := chartsync.New(
log.With(logger, "component", "chartsync"),
chartsync.Polling{Interval: *chartsSyncInterval},
chartsync.Clients{KubeClient: *kubeClient, IfClient: *ifClient},
chartsync.Clients{KubeClient: *kubeClient, IfClient: *ifClient, FhrLister: fhrInformer.Lister()},
rel,
queue,
chartsync.Config{LogDiffs: *logReleaseDiffs, UpdateDeps: *updateDependencies, GitTimeout: *gitTimeout, GitPollInterval: *gitPollInterval},
*namespace,
statusUpdater,
)
chartSync.Run(shutdown, errc, shutdownWg)

nsOpt := ifinformers.WithNamespace(*namespace)
ifInformerFactory := ifinformers.NewSharedInformerFactoryWithOptions(ifClient, 30*time.Second, nsOpt)
fhrInformer := ifInformerFactory.Flux().V1beta1().HelmReleases()

// start FluxRelease informer
opr := operator.New(log.With(logger, "component", "operator"), *logReleaseDiffs, kubeClient, fhrInformer, chartSync)
go ifInformerFactory.Start(shutdown)

opr := operator.New(log.With(logger, "component", "operator"), *logReleaseDiffs, kubeClient, fhrInformer, queue, chartSync)
checkpoint.CheckForUpdates(product, version, nil, log.With(logger, "component", "checkpoint"))

// start HTTP server
Expand Down
2 changes: 2 additions & 0 deletions deploy-helm/flux-helm-release-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ spec:
shortNames:
- hr
scope: Namespaced
subresources:
status: {}
version: v1beta1
versions:
- name: v1beta1
Expand Down
1 change: 0 additions & 1 deletion integrations/apis/flux.weave.works/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// FluxHelmRelease represents custom resource associated with a Helm Chart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ func (c *FakeHelmReleases) Update(helmRelease *v1beta1.HelmRelease) (result *v1b
return obj.(*v1beta1.HelmRelease), err
}

// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
hiddeco marked this conversation as resolved.
Show resolved Hide resolved
func (c *FakeHelmReleases) UpdateStatus(helmRelease *v1beta1.HelmRelease) (*v1beta1.HelmRelease, error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateSubresourceAction(helmreleasesResource, "status", c.ns, helmRelease), &v1beta1.HelmRelease{})

if obj == nil {
return nil, err
}
return obj.(*v1beta1.HelmRelease), err
}

// Delete takes name of the helmRelease and deletes it. Returns an error if one occurs.
func (c *FakeHelmReleases) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type HelmReleasesGetter interface {
type HelmReleaseInterface interface {
Create(*v1beta1.HelmRelease) (*v1beta1.HelmRelease, error)
Update(*v1beta1.HelmRelease) (*v1beta1.HelmRelease, error)
UpdateStatus(*v1beta1.HelmRelease) (*v1beta1.HelmRelease, error)
Delete(name string, options *v1.DeleteOptions) error
DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error
Get(name string, options v1.GetOptions) (*v1beta1.HelmRelease, error)
Expand Down Expand Up @@ -117,6 +118,22 @@ func (c *helmReleases) Update(helmRelease *v1beta1.HelmRelease) (result *v1beta1
return
}

// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
hiddeco marked this conversation as resolved.
Show resolved Hide resolved

func (c *helmReleases) UpdateStatus(helmRelease *v1beta1.HelmRelease) (result *v1beta1.HelmRelease, err error) {
result = &v1beta1.HelmRelease{}
err = c.client.Put().
Namespace(c.ns).
Resource("helmreleases").
Name(helmRelease.Name).
SubResource("status").
Body(helmRelease).
Do().
Into(result)
return
}

// Delete takes name of the helmRelease and deletes it. Returns an error if one occurs.
func (c *helmReleases) Delete(name string, options *v1.DeleteOptions) error {
return c.client.Delete().
Expand Down
Loading