Skip to content

Commit

Permalink
Fix: remove v1beta2 Bucket deprecated log (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamB78 authored Oct 15, 2024
1 parent 7f2b8ae commit bd74d3c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pkg/controllers/bucketController.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 bucketResource = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1",
Resource: "buckets",
}

var bucketResourceV1beta2 = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "buckets",
Expand All @@ -23,6 +30,13 @@ func BucketController(
dynamicClient *dynamic.DynamicClient,
clientHub *streaming.ClientHub,
) (*Controller, error) {
// check if v1 is supported
_, err := dynamicClient.Resource(bucketResource).Namespace("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
// try and possibly fail (bucket-controller is not mandatory) with v1beta2
bucketResource = bucketResourceV1beta2
}

return NewDynamicController(
"buckets.source.toolkit.fluxcd.io",
dynamicClient,
Expand Down
20 changes: 19 additions & 1 deletion pkg/flux/flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ var (
}

bucketGVR = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1",
Resource: "buckets",
}

bucketGVR1beta2 = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "buckets",
Expand Down Expand Up @@ -453,9 +459,21 @@ func State(c *kubernetes.Clientset, dc *dynamic.DynamicClient) (*FluxState, erro
buckets, err := dc.Resource(bucketGVR).
Namespace("").
List(context.TODO(), metav1.ListOptions{})

if err != nil {
return nil, err
if strings.Contains(err.Error(), "the server could not find the requested resource") {
// let's try the deprecated v1beta2
buckets, err = dc.Resource(bucketGVR1beta2).
Namespace("").
List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, err
}
} else {
return nil, err
}
}

for _, repo := range buckets.Items {
unstructured := repo.UnstructuredContent()
var bucket sourcev1beta2.Bucket
Expand Down

0 comments on commit bd74d3c

Please sign in to comment.