Skip to content

Commit

Permalink
feat(controllers): implement ObjectReconciler
Browse files Browse the repository at this point in the history
With controller-runtime 0.17.0, reconcilers can be generic over
client.Object objects, which can be used to reduce the boilerplate of
returning requests into typed objects in the standard reconciler case
over Kubernetes objects.

This changeset implements both origin-ca-issuer reconcilers as
ObjectReconcilers, and upgrades controller-runtime to 0.17.0 to use the
new feature.
  • Loading branch information
terinjokes committed Jan 30, 2024
1 parent 3954a9e commit 000367f
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 135 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ concurrency:
jobs:
unit:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ 'stable', 'oldstable' ]
name: 'Go ${{ matrix.go }} Test'
name: "Go ${{ matrix.go }} Test"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
go-version: stable
- run: make test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 'stable'
go-version: "stable"
- uses: dominikh/staticcheck-action@v1
with:
build-tags: suite
Expand All @@ -38,7 +35,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 'stable'
go-version: "stable"
- run: |
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
source <(setup-envtest use -p env)
Expand Down
9 changes: 5 additions & 4 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

func main() {
Expand Down Expand Up @@ -87,13 +88,13 @@ func main() {
err = builder.
ControllerManagedBy(mgr).
For(&v1.OriginIssuer{}).
Complete(&controllers.OriginIssuerController{
Complete(reconcile.AsReconciler(mgr.GetClient(), &controllers.OriginIssuerController{
Client: mgr.GetClient(),
Clock: clock.RealClock{},
Factory: f,
Log: log.WithName("controllers").WithName("OriginIssuer"),
Collection: collection,
})
}))

if err != nil {
log.Error(err, "could not create origin issuer controller")
Expand All @@ -103,14 +104,14 @@ func main() {
err = builder.
ControllerManagedBy(mgr).
For(&certmanager.CertificateRequest{}).
Complete(&controllers.CertificateRequestController{
Complete(reconcile.AsReconciler(mgr.GetClient(), &controllers.CertificateRequestController{
Client: mgr.GetClient(),
Log: log.WithName("controllers").WithName("CertificateRequest"),
Collection: collection,

Clock: clock.RealClock{},
CheckApprovedCondition: !o.DisableApprovedCheck,
})
}))

if err != nil {
log.Error(err, "could not create certificaterequest controller")
Expand Down
62 changes: 32 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
module github.com/cloudflare/origin-ca-issuer

go 1.20
go 1.21

toolchain go1.21.5

require (
github.com/cert-manager/cert-manager v1.9.2
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.4.1
github.com/go-logr/zerologr v1.2.1
github.com/google/go-cmp v0.5.9
github.com/google/go-cmp v0.6.0
github.com/rs/zerolog v1.25.0
github.com/spf13/pflag v1.0.5
gotest.tools/v3 v3.0.3
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
sigs.k8s.io/controller-runtime v0.16.3
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.17.0
sigs.k8s.io/controller-tools v0.13.0
)

Expand All @@ -26,9 +28,9 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.1 // indirect
github.com/go-ldap/ldap/v3 v3.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
Expand All @@ -48,39 +50,39 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
golang.org/x/tools v0.16.1 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-aggregator v0.24.2 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
sigs.k8s.io/gateway-api v0.4.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 000367f

Please sign in to comment.