Skip to content

Commit

Permalink
Feat: support Flux V3 (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamB78 authored Sep 25, 2024
1 parent d8c8bc9 commit 99631f0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
16 changes: 15 additions & 1 deletion pkg/controllers/helmChartController.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"context"
"encoding/json"

"github.com/gimlet-io/capacitor/pkg/flux"
Expand All @@ -13,6 +14,12 @@ import (
)

var helmChartResource = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1",
Resource: "helmcharts",
}

var helmChartResourceV1beta2 = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "helmcharts",
Expand All @@ -23,10 +30,17 @@ func HelmChartController(
dynamicClient *dynamic.DynamicClient,
clientHub *streaming.ClientHub,
) (*Controller, error) {
resource := helmChartResource
// check if v1 is supported
_, err := dynamicClient.Resource(resource).Namespace("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
// try and possibly fail (helm-controller is not mandatory) with v1beta2
resource = helmChartResourceV1beta2
}
return NewDynamicController(
"helmcharts.source.toolkit.fluxcd.io",
dynamicClient,
helmChartResource,
resource,
func(informerEvent Event, objectMeta metav1.ObjectMeta, obj interface{}) error {
switch informerEvent.eventType {
case "create":
Expand Down
16 changes: 15 additions & 1 deletion pkg/controllers/helmRepositoryController.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
"context"
"encoding/json"

"github.com/gimlet-io/capacitor/pkg/flux"
Expand All @@ -13,6 +14,12 @@ import (
)

var helmRepositoryResource = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1",
Resource: "helmrepositories",
}

var helmRepositoryResourceV1beta2 = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "helmrepositories",
Expand All @@ -23,10 +30,17 @@ func HelmRepositoryController(
dynamicClient *dynamic.DynamicClient,
clientHub *streaming.ClientHub,
) (*Controller, error) {
resource := helmRepositoryResource
// check if v1 is supported
_, err := dynamicClient.Resource(resource).Namespace("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
// try and possibly fail (helm-controller is not mandatory) with v1beta2
resource = helmRepositoryResourceV1beta2
}
return NewDynamicController(
"helmrepositories.source.toolkit.fluxcd.io",
dynamicClient,
helmRepositoryResource,
resource,
func(informerEvent Event, objectMeta metav1.ObjectMeta, obj interface{}) error {
switch informerEvent.eventType {
case "create":
Expand Down
14 changes: 13 additions & 1 deletion pkg/controllers/helmreleaseController.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
)

var helmReleaseResource = schema.GroupVersionResource{
Group: "helm.toolkit.fluxcd.io",
Version: "v2",
Resource: "helmreleases",
}

var helmReleaseResourceV2beta2 = schema.GroupVersionResource{
Group: "helm.toolkit.fluxcd.io",
Version: "v2beta2",
Resource: "helmreleases",
Expand All @@ -31,8 +37,14 @@ func HelmReleaseController(
clientHub *streaming.ClientHub,
) (*Controller, error) {
resource := helmReleaseResource
// check if v2beta2 is supported
// check if v2 is supported
_, err := dynamicClient.Resource(resource).Namespace("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
// try and possibly fail (helm-controller is not mandatory) with v2beta2
resource = helmReleaseResourceV2beta2
}

_, err = dynamicClient.Resource(resource).Namespace("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
// try and possibly fail (helm-controller is not mandatory) with v2beta1
resource = helmReleaseResourceV2beta1
Expand Down

0 comments on commit 99631f0

Please sign in to comment.