Skip to content

Commit bd74d3c

Browse files
authored
Fix: remove v1beta2 Bucket deprecated log (#131)
1 parent 7f2b8ae commit bd74d3c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pkg/controllers/bucketController.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package controllers
22

33
import (
4+
"context"
45
"encoding/json"
56

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

1516
var bucketResource = schema.GroupVersionResource{
17+
Group: "source.toolkit.fluxcd.io",
18+
Version: "v1",
19+
Resource: "buckets",
20+
}
21+
22+
var bucketResourceV1beta2 = schema.GroupVersionResource{
1623
Group: "source.toolkit.fluxcd.io",
1724
Version: "v1beta2",
1825
Resource: "buckets",
@@ -23,6 +30,13 @@ func BucketController(
2330
dynamicClient *dynamic.DynamicClient,
2431
clientHub *streaming.ClientHub,
2532
) (*Controller, error) {
33+
// check if v1 is supported
34+
_, err := dynamicClient.Resource(bucketResource).Namespace("").List(context.TODO(), metav1.ListOptions{})
35+
if err != nil {
36+
// try and possibly fail (bucket-controller is not mandatory) with v1beta2
37+
bucketResource = bucketResourceV1beta2
38+
}
39+
2640
return NewDynamicController(
2741
"buckets.source.toolkit.fluxcd.io",
2842
dynamicClient,

pkg/flux/flux.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ var (
5757
}
5858

5959
bucketGVR = schema.GroupVersionResource{
60+
Group: "source.toolkit.fluxcd.io",
61+
Version: "v1",
62+
Resource: "buckets",
63+
}
64+
65+
bucketGVR1beta2 = schema.GroupVersionResource{
6066
Group: "source.toolkit.fluxcd.io",
6167
Version: "v1beta2",
6268
Resource: "buckets",
@@ -453,9 +459,21 @@ func State(c *kubernetes.Clientset, dc *dynamic.DynamicClient) (*FluxState, erro
453459
buckets, err := dc.Resource(bucketGVR).
454460
Namespace("").
455461
List(context.TODO(), metav1.ListOptions{})
462+
456463
if err != nil {
457-
return nil, err
464+
if strings.Contains(err.Error(), "the server could not find the requested resource") {
465+
// let's try the deprecated v1beta2
466+
buckets, err = dc.Resource(bucketGVR1beta2).
467+
Namespace("").
468+
List(context.TODO(), metav1.ListOptions{})
469+
if err != nil {
470+
return nil, err
471+
}
472+
} else {
473+
return nil, err
474+
}
458475
}
476+
459477
for _, repo := range buckets.Items {
460478
unstructured := repo.UnstructuredContent()
461479
var bucket sourcev1beta2.Bucket

0 commit comments

Comments
 (0)