Skip to content

Commit 6ac2961

Browse files
authored
Merge pull request #385 from containeroo/refactor
refactor controllers
2 parents cd3d9a6 + b6889fa commit 6ac2961

17 files changed

+640
-654
lines changed

.golangci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
---
12
run:
2-
deadline: 5m
3+
timeout: 5m
34
allow-parallel-runners: true
45

56
issues:
@@ -19,9 +20,10 @@ issues:
1920
linters:
2021
disable-all: true
2122
enable:
23+
- copyloopvar
2224
- dupl
2325
- errcheck
24-
- exportloopref
26+
- ginkgolinter
2527
- goconst
2628
- gocyclo
2729
- gofmt
@@ -33,8 +35,14 @@ linters:
3335
- misspell
3436
- nakedret
3537
- prealloc
38+
- revive
3639
- staticcheck
3740
- typecheck
3841
- unconvert
3942
- unparam
4043
- unused
44+
45+
linters-settings:
46+
revive:
47+
rules:
48+
- name: comment-spacings

api/v1/account_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ type Account struct {
6262
Status AccountStatus `json:"status,omitempty"`
6363
}
6464

65+
// GetConditions returns the status conditions of the object.
66+
func (in *Account) GetConditions() []metav1.Condition {
67+
return in.Status.Conditions
68+
}
69+
70+
// SetConditions sets the status conditions on the object.
71+
func (in *Account) SetConditions(conditions []metav1.Condition) {
72+
in.Status.Conditions = conditions
73+
}
74+
6575
// +kubebuilder:object:root=true
6676

6777
// AccountList contains a list of Account

api/v1/condition_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2025 containeroo
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
const (
20+
// ConditionTypeReady represents the fact that the object is ready.
21+
ConditionTypeReady string = "Ready"
22+
23+
// ConditionReasonReady represents the fact that the object is ready.
24+
ConditionReasonReady string = "Ready"
25+
26+
// ConditionReasonNotReady represents the fact that the object is not ready.
27+
ConditionReasonNotReady string = "NotReady"
28+
29+
// ConditionReasonFailed represents the fact that the object has failed.
30+
ConditionReasonFailed string = "Failed"
31+
)

api/v1/dnsrecord_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ type DNSRecordStatus struct {
7676
RecordID string `json:"recordID,omitempty"`
7777
}
7878

79+
const (
80+
IPRefIndexKey string = ".spec.ipRef.name"
81+
OwnerRefUIDIndexKey string = ".metadata.ownerReferences.uid"
82+
)
83+
7984
// +kubebuilder:object:root=true
8085
// +kubebuilder:subresource:status
8186

@@ -94,6 +99,16 @@ type DNSRecord struct {
9499
Status DNSRecordStatus `json:"status,omitempty"`
95100
}
96101

102+
// GetConditions returns the status conditions of the object.
103+
func (in *DNSRecord) GetConditions() []metav1.Condition {
104+
return in.Status.Conditions
105+
}
106+
107+
// SetConditions sets the status conditions on the object.
108+
func (in *DNSRecord) SetConditions(conditions []metav1.Condition) {
109+
in.Status.Conditions = conditions
110+
}
111+
97112
// +kubebuilder:object:root=true
98113

99114
// DNSRecordList contains a list of DNSRecord

api/v1/ip_types.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ type IPStatus struct {
7373
// Conditions contains the different condition statuses for the IP object.
7474
// +optional
7575
Conditions []metav1.Condition `json:"conditions"`
76-
// LastObservedIP contains the IP address observed at the last interval (used to determine whether the IP has changed)
77-
// +optional
78-
LastObservedIP string `json:"lastObservedIP,omitempty"`
7976
}
8077

8178
// +kubebuilder:object:root=true
@@ -94,6 +91,16 @@ type IP struct {
9491
Status IPStatus `json:"status,omitempty"`
9592
}
9693

94+
// GetConditions returns the status conditions of the object.
95+
func (in *IP) GetConditions() []metav1.Condition {
96+
return in.Status.Conditions
97+
}
98+
99+
// SetConditions sets the status conditions on the object.
100+
func (in *IP) SetConditions(conditions []metav1.Condition) {
101+
in.Status.Conditions = conditions
102+
}
103+
97104
// +kubebuilder:object:root=true
98105

99106
// IPList contains a list of IP

api/v1/zone_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type ZoneStatus struct {
4444
Conditions []metav1.Condition `json:"conditions"`
4545
}
4646

47+
const (
48+
ZoneNameIndexKey string = ".spec.name"
49+
)
50+
4751
// +kubebuilder:object:root=true
4852
// +kubebuilder:subresource:status
4953
// +kubebuilder:resource:scope=Cluster
@@ -60,6 +64,16 @@ type Zone struct {
6064
Status ZoneStatus `json:"status,omitempty"`
6165
}
6266

67+
// GetConditions returns the status conditions of the object.
68+
func (in *Zone) GetConditions() []metav1.Condition {
69+
return in.Status.Conditions
70+
}
71+
72+
// SetConditions sets the status conditions on the object.
73+
func (in *Zone) SetConditions(conditions []metav1.Condition) {
74+
in.Status.Conditions = conditions
75+
}
76+
6377
// +kubebuilder:object:root=true
6478

6579
// ZoneList contains a list of Zone

cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func main() {
130130
Client: mgr.GetClient(),
131131
Scheme: mgr.GetScheme(),
132132
Cf: &cf,
133-
}).SetupWithManager(mgr); err != nil {
133+
}).SetupWithManager(ctx, mgr); err != nil {
134134
setupLog.Error(err, "unable to create controller", "controller", "Zone")
135135
os.Exit(1)
136136
}
@@ -144,15 +144,15 @@ func main() {
144144
if err = (&controller.IngressReconciler{
145145
Client: mgr.GetClient(),
146146
Scheme: mgr.GetScheme(),
147-
}).SetupWithManager(ctx, mgr); err != nil {
147+
}).SetupWithManager(mgr); err != nil {
148148
setupLog.Error(err, "unable to create controller", "controller", "Ingress")
149149
os.Exit(1)
150150
}
151151
if err = (&controller.DNSRecordReconciler{
152152
Client: mgr.GetClient(),
153153
Scheme: mgr.GetScheme(),
154154
Cf: &cf,
155-
}).SetupWithManager(mgr); err != nil {
155+
}).SetupWithManager(ctx, mgr); err != nil {
156156
setupLog.Error(err, "unable to create controller", "controller", "DNSRecord")
157157
os.Exit(1)
158158
}

config/crd/bases/cloudflare-operator.io_ips.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ spec:
176176
- type
177177
type: object
178178
type: array
179-
lastObservedIP:
180-
description: LastObservedIP contains the IP address observed at the
181-
last interval (used to determine whether the IP has changed)
182-
type: string
183179
type: object
184180
type: object
185181
served: true

go.mod

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23.0
44

55
require (
66
github.com/cloudflare/cloudflare-go v0.115.0
7-
github.com/go-logr/logr v1.4.2
7+
github.com/fluxcd/pkg/runtime v0.53.1
88
github.com/itchyny/gojq v0.12.17
99
github.com/prometheus/client_golang v1.20.5
1010
golang.org/x/net v0.35.0
@@ -19,56 +19,58 @@ require (
1919
github.com/beorn7/perks v1.0.1 // indirect
2020
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2121
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
22-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
23-
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
24-
github.com/fsnotify/fsnotify v1.7.0 // indirect
22+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
23+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
24+
github.com/fluxcd/pkg/apis/meta v1.10.0 // indirect
25+
github.com/fsnotify/fsnotify v1.8.0 // indirect
2526
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
27+
github.com/go-logr/logr v1.4.2 // indirect
2628
github.com/go-logr/zapr v1.3.0 // indirect
2729
github.com/go-openapi/jsonpointer v0.21.0 // indirect
28-
github.com/go-openapi/jsonreference v0.20.2 // indirect
30+
github.com/go-openapi/jsonreference v0.21.0 // indirect
2931
github.com/go-openapi/swag v0.23.0 // indirect
3032
github.com/goccy/go-json v0.10.5 // indirect
3133
github.com/gogo/protobuf v1.3.2 // indirect
3234
github.com/golang/protobuf v1.5.4 // indirect
3335
github.com/google/btree v1.1.3 // indirect
34-
github.com/google/gnostic-models v0.6.8 // indirect
36+
github.com/google/gnostic-models v0.6.9 // indirect
3537
github.com/google/go-cmp v0.6.0 // indirect
3638
github.com/google/go-querystring v1.1.0 // indirect
3739
github.com/google/gofuzz v1.2.0 // indirect
3840
github.com/google/uuid v1.6.0 // indirect
3941
github.com/itchyny/timefmt-go v0.1.6 // indirect
4042
github.com/josharian/intern v1.0.0 // indirect
4143
github.com/json-iterator/go v1.1.12 // indirect
42-
github.com/klauspost/compress v1.17.9 // indirect
43-
github.com/mailru/easyjson v0.7.7 // indirect
44+
github.com/klauspost/compress v1.17.11 // indirect
45+
github.com/mailru/easyjson v0.9.0 // indirect
4446
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4547
github.com/modern-go/reflect2 v1.0.2 // indirect
4648
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4749
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
4850
github.com/onsi/gomega v1.36.2 // indirect
4951
github.com/pkg/errors v0.9.1 // indirect
5052
github.com/prometheus/client_model v0.6.1 // indirect
51-
github.com/prometheus/common v0.55.0 // indirect
53+
github.com/prometheus/common v0.62.0 // indirect
5254
github.com/prometheus/procfs v0.15.1 // indirect
53-
github.com/spf13/pflag v1.0.5 // indirect
55+
github.com/spf13/pflag v1.0.6 // indirect
5456
github.com/x448/float16 v0.8.4 // indirect
5557
go.uber.org/multierr v1.11.0 // indirect
5658
go.uber.org/zap v1.27.0 // indirect
57-
golang.org/x/oauth2 v0.23.0 // indirect
59+
golang.org/x/oauth2 v0.25.0 // indirect
5860
golang.org/x/sync v0.11.0 // indirect
5961
golang.org/x/sys v0.30.0 // indirect
6062
golang.org/x/term v0.29.0 // indirect
6163
golang.org/x/text v0.22.0 // indirect
6264
golang.org/x/time v0.9.0 // indirect
6365
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
64-
google.golang.org/protobuf v1.36.1 // indirect
66+
google.golang.org/protobuf v1.36.4 // indirect
6567
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
6668
gopkg.in/inf.v0 v0.9.1 // indirect
6769
gopkg.in/yaml.v3 v3.0.1 // indirect
6870
k8s.io/klog/v2 v2.130.1 // indirect
69-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
70-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
71-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
72-
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
71+
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
72+
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect
73+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
74+
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
7375
sigs.k8s.io/yaml v1.4.0 // indirect
7476
)

0 commit comments

Comments
 (0)