Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: support Flux V2.3 #120

Merged
merged 1 commit into from
Sep 25, 2024
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
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