Skip to content

Commit babff11

Browse files
authored
Merge pull request #533 from containeroo/renovate/github.com-cloudflare-cloudflare-go-7.x
2 parents e85f77e + 13ae6a3 commit babff11

20 files changed

Lines changed: 496 additions & 274 deletions

api/v1/groupversion_info.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,30 @@ limitations under the License.
2020
package v1
2121

2222
import (
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/runtime"
2325
"k8s.io/apimachinery/pkg/runtime/schema"
24-
"sigs.k8s.io/controller-runtime/pkg/scheme"
2526
)
2627

28+
type schemeBuilder struct {
29+
GroupVersion schema.GroupVersion
30+
runtime.SchemeBuilder
31+
}
32+
33+
func (b *schemeBuilder) Register(objects ...runtime.Object) {
34+
b.SchemeBuilder.Register(func(s *runtime.Scheme) error {
35+
s.AddKnownTypes(b.GroupVersion, objects...)
36+
metav1.AddToGroupVersion(s, b.GroupVersion)
37+
return nil
38+
})
39+
}
40+
2741
var (
2842
// GroupVersion is group version used to register these objects
2943
GroupVersion = schema.GroupVersion{Group: "cloudflare-operator.io", Version: "v1"}
3044

3145
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32-
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
46+
SchemeBuilder = &schemeBuilder{GroupVersion: GroupVersion}
3347

3448
// AddToScheme adds the types in this group-version to the given scheme.
3549
AddToScheme = SchemeBuilder.AddToScheme

api/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/containeroo/cloudflare-operator
33
go 1.26.0
44

55
require (
6-
github.com/cloudflare/cloudflare-go v0.117.0
6+
github.com/cloudflare/cloudflare-go/v7 v7.4.0
77
github.com/fluxcd/pkg/runtime v0.108.0
88
github.com/itchyny/gojq v0.12.19
99
github.com/onsi/ginkgo/v2 v2.29.0
@@ -33,10 +33,8 @@ require (
3333
github.com/go-openapi/jsonreference v0.21.0 // indirect
3434
github.com/go-openapi/swag v0.23.1 // indirect
3535
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
36-
github.com/goccy/go-json v0.10.5 // indirect
3736
github.com/google/gnostic-models v0.7.0 // indirect
3837
github.com/google/go-cmp v0.7.0 // indirect
39-
github.com/google/go-querystring v1.1.0 // indirect
4038
github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect
4139
github.com/google/uuid v1.6.0 // indirect
4240
github.com/itchyny/timefmt-go v0.1.8 // indirect
@@ -52,6 +50,10 @@ require (
5250
github.com/prometheus/common v0.67.5 // indirect
5351
github.com/prometheus/procfs v0.19.2 // indirect
5452
github.com/spf13/pflag v1.0.10 // indirect
53+
github.com/tidwall/gjson v1.18.0 // indirect
54+
github.com/tidwall/match v1.1.1 // indirect
55+
github.com/tidwall/pretty v1.2.1 // indirect
56+
github.com/tidwall/sjson v1.2.5 // indirect
5557
github.com/x448/float16 v0.8.4 // indirect
5658
go.uber.org/multierr v1.11.0 // indirect
5759
go.uber.org/zap v1.27.1 // indirect

go.sum

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
66
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
77
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
88
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
9-
github.com/cloudflare/cloudflare-go v0.117.0 h1:y00E0XCvxuZGplL+gkoMRIhWpfNqIgyBFS6UUWC4s0c=
10-
github.com/cloudflare/cloudflare-go v0.117.0/go.mod h1:Ds6urDwn/TF2uIU24mu7H91xkKP8gSAHxQ44DSZgVmU=
9+
github.com/cloudflare/cloudflare-go/v7 v7.4.0 h1:JdTxzeXcAhtJ9rUkNISK4ABA55pZP8HLxx6XsPSA7dU=
10+
github.com/cloudflare/cloudflare-go/v7 v7.4.0/go.mod h1:9zcoIAtu6cmcoPszCNISvqYMXs8wObtVGXE1qGFMrNU=
1111
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1212
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1313
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@@ -44,17 +44,12 @@ github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZ
4444
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
4545
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
4646
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
47-
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
48-
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
4947
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
5048
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
5149
github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo=
5250
github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ=
53-
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5451
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
5552
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
56-
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
57-
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
5853
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
5954
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
6055
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -121,10 +116,12 @@ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/
121116
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
122117
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
123118
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
119+
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
124120
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
125121
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
126122
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
127123
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
124+
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
128125
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
129126
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
130127
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
@@ -159,7 +156,6 @@ golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
159156
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
160157
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
161158
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
162-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
163159
gomodules.xyz/jsonpatch/v2 v2.5.0 h1:JELs8RLM12qJGXU4u/TO3V25KW8GreMKl9pdkk14RM0=
164160
gomodules.xyz/jsonpatch/v2 v2.5.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
165161
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af h1:+5/Sw3GsDNlEmu7TfklWKPdQ0Ykja5VEmq2i817+jbI=

internal/controller/account_controller.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"errors"
2222
"time"
2323

24-
"github.com/cloudflare/cloudflare-go"
2524
"sigs.k8s.io/controller-runtime/pkg/builder"
2625
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2726
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -123,10 +122,7 @@ func (r *AccountReconciler) reconcileAccount(ctx context.Context, account *cloud
123122
return ctrl.Result{RequeueAfter: r.RetryInterval}, nil
124123
}
125124

126-
if _, err := cloudflare.NewWithAPIToken(cloudflareAPIToken); err != nil {
127-
intconditions.MarkFalse(account, err)
128-
return ctrl.Result{}, err
129-
}
125+
_ = newCloudflareClient(cloudflareAPIToken)
130126

131127
intconditions.MarkTrue(account, "Account is ready")
132128

internal/controller/account_controller_test.go

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434

35-
"github.com/cloudflare/cloudflare-go"
35+
cloudflare "github.com/cloudflare/cloudflare-go/v7"
3636
cloudflareoperatoriov1 "github.com/containeroo/cloudflare-operator/api/v1"
3737
networkingv1 "k8s.io/api/networking/v1"
3838
)
@@ -46,28 +46,40 @@ func NewTestScheme() *runtime.Scheme {
4646
return s
4747
}
4848

49-
var cloudflareAPI cloudflare.API
49+
var (
50+
cloudflareAPI *cloudflare.Client
51+
cloudflareAPIToken string
52+
)
53+
54+
const (
55+
testAccountName = "account"
56+
testContentAnnotation = "cloudflare-operator.io/content"
57+
testDefaultNamespace = "default"
58+
testDNSRecordHost = "dnstest.containeroo-test.org"
59+
testIPv4Address = "1.1.1.1"
60+
testAlternateIPv4Address = "2.2.2.2"
61+
testRecordTypeTXT = "TXT"
62+
testSecretName = "secret"
63+
testWildcardDNSRecordName = "wildcard-containeroo-test-org"
64+
testWildcardHost = "*.containeroo-test.org"
65+
)
5066

5167
func initTestCloudflareAPI(t *testing.T) {
5268
t.Helper()
5369

54-
if cloudflareAPI.APIToken == os.Getenv("CF_API_TOKEN") && cloudflareAPI.APIToken != "" {
70+
if cloudflareAPI != nil && cloudflareAPIToken == os.Getenv("CF_API_TOKEN") {
5571
return
5672
}
5773

58-
api, err := cloudflare.NewWithAPIToken(os.Getenv("CF_API_TOKEN"))
59-
if err != nil {
60-
t.Fatalf("failed to initialize test Cloudflare API: %v", err)
61-
}
62-
63-
cloudflareAPI = *api
74+
cloudflareAPIToken = os.Getenv("CF_API_TOKEN")
75+
cloudflareAPI = newCloudflareClient(cloudflareAPIToken)
6476
}
6577

6678
func NewTestAccountObjects() (*corev1.Secret, *cloudflareoperatoriov1.Account) {
6779
secret := &corev1.Secret{
6880
ObjectMeta: metav1.ObjectMeta{
69-
Name: "secret",
70-
Namespace: "default",
81+
Name: testSecretName,
82+
Namespace: testDefaultNamespace,
7183
},
7284
Data: map[string][]byte{
7385
"apiToken": []byte(os.Getenv("CF_API_TOKEN")),
@@ -76,7 +88,7 @@ func NewTestAccountObjects() (*corev1.Secret, *cloudflareoperatoriov1.Account) {
7688

7789
account := &cloudflareoperatoriov1.Account{
7890
ObjectMeta: metav1.ObjectMeta{
79-
Name: "account",
91+
Name: testAccountName,
8092
},
8193
Spec: cloudflareoperatoriov1.AccountSpec{
8294
ApiToken: cloudflareoperatoriov1.AccountSpecApiToken{
@@ -118,13 +130,13 @@ func TestAccountReconciler_reconcileAccount(t *testing.T) {
118130

119131
account := &cloudflareoperatoriov1.Account{
120132
ObjectMeta: metav1.ObjectMeta{
121-
Name: "account",
133+
Name: testAccountName,
122134
},
123135
Spec: cloudflareoperatoriov1.AccountSpec{
124136
ApiToken: cloudflareoperatoriov1.AccountSpecApiToken{
125137
SecretRef: corev1.SecretReference{
126-
Name: "secret",
127-
Namespace: "default",
138+
Name: testSecretName,
139+
Namespace: testDefaultNamespace,
128140
},
129141
},
130142
},
@@ -150,8 +162,8 @@ func TestAccountReconciler_reconcileAccount(t *testing.T) {
150162

151163
secret := &corev1.Secret{
152164
ObjectMeta: metav1.ObjectMeta{
153-
Name: "secret",
154-
Namespace: "default",
165+
Name: testSecretName,
166+
Namespace: testDefaultNamespace,
155167
},
156168
Data: map[string][]byte{
157169
"invalid": []byte("invalid"),
@@ -160,13 +172,13 @@ func TestAccountReconciler_reconcileAccount(t *testing.T) {
160172

161173
account := &cloudflareoperatoriov1.Account{
162174
ObjectMeta: metav1.ObjectMeta{
163-
Name: "account",
175+
Name: testAccountName,
164176
},
165177
Spec: cloudflareoperatoriov1.AccountSpec{
166178
ApiToken: cloudflareoperatoriov1.AccountSpecApiToken{
167179
SecretRef: corev1.SecretReference{
168-
Name: "secret",
169-
Namespace: "default",
180+
Name: testSecretName,
181+
Namespace: testDefaultNamespace,
170182
},
171183
},
172184
},
@@ -229,6 +241,6 @@ func TestCloudflareAPIForAccountName(t *testing.T) {
229241

230242
api, err := cloudflareAPIForAccountName(context.TODO(), kubeClient, otherAccount.Name)
231243
g.Expect(err).ToNot(HaveOccurred())
232-
g.Expect(api.APIToken).To(Equal(string(otherSecret.Data["apiToken"])))
244+
g.Expect(api).ToNot(BeNil())
233245
})
234246
}

internal/controller/cloudflare_api.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ import (
2121
"errors"
2222
"fmt"
2323

24-
"github.com/cloudflare/cloudflare-go"
24+
cloudflare "github.com/cloudflare/cloudflare-go/v7"
2525
corev1 "k8s.io/api/core/v1"
2626
apierrors "k8s.io/apimachinery/pkg/api/errors"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828

2929
cloudflareoperatoriov1 "github.com/containeroo/cloudflare-operator/api/v1"
3030
)
3131

32-
func cloudflareAPIFromZone(ctx context.Context, kubeClient client.Client, zone *cloudflareoperatoriov1.Zone) (*cloudflare.API, error) {
32+
func cloudflareAPIFromZone(ctx context.Context, kubeClient client.Client, zone *cloudflareoperatoriov1.Zone) (*cloudflare.Client, error) {
3333
return cloudflareAPIForAccountName(ctx, kubeClient, zone.Spec.AccountRef.Name)
3434
}
3535

36-
func cloudflareAPIFromDNSRecord(ctx context.Context, kubeClient client.Client, dnsRecord *cloudflareoperatoriov1.DNSRecord, zone *cloudflareoperatoriov1.Zone) (*cloudflare.API, error) {
36+
func cloudflareAPIFromDNSRecord(ctx context.Context, kubeClient client.Client, dnsRecord *cloudflareoperatoriov1.DNSRecord, zone *cloudflareoperatoriov1.Zone) (*cloudflare.Client, error) {
3737
accountName := dnsRecord.Spec.AccountRef.Name
3838
if zone != nil && zone.Spec.AccountRef.Name != "" {
3939
if accountName != "" && accountName != zone.Spec.AccountRef.Name {
@@ -45,7 +45,7 @@ func cloudflareAPIFromDNSRecord(ctx context.Context, kubeClient client.Client, d
4545
return cloudflareAPIForAccountName(ctx, kubeClient, accountName)
4646
}
4747

48-
func cloudflareAPIForAccountName(ctx context.Context, kubeClient client.Client, accountName string) (*cloudflare.API, error) {
48+
func cloudflareAPIForAccountName(ctx context.Context, kubeClient client.Client, accountName string) (*cloudflare.Client, error) {
4949
account, err := accountForName(ctx, kubeClient, accountName)
5050
if err != nil {
5151
return nil, err
@@ -56,12 +56,7 @@ func cloudflareAPIForAccountName(ctx context.Context, kubeClient client.Client,
5656
return nil, err
5757
}
5858

59-
cloudflareAPI, err := cloudflare.NewWithAPIToken(token)
60-
if err != nil {
61-
return nil, fmt.Errorf("failed to create Cloudflare API client for account %q: %w", account.Name, err)
62-
}
63-
64-
return cloudflareAPI, nil
59+
return newCloudflareClient(token), nil
6560
}
6661

6762
func accountForName(ctx context.Context, kubeClient client.Client, accountName string) (*cloudflareoperatoriov1.Account, error) {

0 commit comments

Comments
 (0)