Skip to content

Commit

Permalink
Update controller-runtime (v0.15) and K8s (v1.27)
Browse files Browse the repository at this point in the history
This deals with various breaking changes in controller-runtime, as
documented in the release notes:
https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.15.0

In short:

- `Watches` now use a `client.Object` instead of a `source.Kind`.
- `handler.MapFunc` signature accepts a Go context, which is used to
  log any errors, instead of silently ignoring them and/or panicking.
- Fake clients used in tests are now configured using
  `WithStatusSubresource` to enable the correct behavior for status
  updates and patches.
- Max concurrent reconciles is configured on the manager, instead of
  configuring them per reconciler instance.
- Various manager configuration options have been moved to new
  structures and/or fields.

In addition to this, all other dependencies which had updates are
updated to their latest (compatible) versions as well.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
  • Loading branch information
hiddeco committed May 24, 2023
1 parent fc0df4d commit eeef91a
Show file tree
Hide file tree
Showing 24 changed files with 559 additions and 450 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ FUZZ_TIME ?= 1m
GO_STATIC_FLAGS=-ldflags "-s -w" -tags 'netgo,osusergo,static_build$(addprefix ,,$(GO_TAGS))'

# API (doc) generation utilities
CONTROLLER_GEN_VERSION ?= v0.11.1
CONTROLLER_GEN_VERSION ?= v0.12.0
GEN_API_REF_DOCS_VERSION ?= e327d0730470cbd61b06300f81c5fcf91c23c113

# If gobin not set, create one on ./build and add to path.
Expand Down
3 changes: 1 addition & 2 deletions config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: buckets.source.toolkit.fluxcd.io
spec:
group: source.toolkit.fluxcd.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: gitrepositories.source.toolkit.fluxcd.io
spec:
group: source.toolkit.fluxcd.io
Expand Down
3 changes: 1 addition & 2 deletions config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: helmcharts.source.toolkit.fluxcd.io
spec:
group: source.toolkit.fluxcd.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: helmrepositories.source.toolkit.fluxcd.io
spec:
group: source.toolkit.fluxcd.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: ocirepositories.source.toolkit.fluxcd.io
spec:
group: source.toolkit.fluxcd.io
Expand Down
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
160 changes: 83 additions & 77 deletions go.mod

Large diffs are not rendered by default.

337 changes: 171 additions & 166 deletions go.sum

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions internal/controller/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ type BucketReconciler struct {
}

type BucketReconcilerOptions struct {
MaxConcurrentReconciles int
RateLimiter ratelimiter.RateLimiter
RateLimiter ratelimiter.RateLimiter
}

// BucketProvider is an interface for fetching objects from a storage provider
Expand Down Expand Up @@ -169,8 +168,7 @@ func (r *BucketReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts Buc
For(&bucketv1.Bucket{}).
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicates.ReconcileRequestedPredicate{})).
WithOptions(controller.Options{
MaxConcurrentReconciles: opts.MaxConcurrentReconciles,
RateLimiter: opts.RateLimiter,
RateLimiter: opts.RateLimiter,
}).
Complete(r)
}
Expand Down
65 changes: 36 additions & 29 deletions internal/controller/bucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"k8s.io/client-go/tools/record"
kstatus "sigs.k8s.io/cli-utils/pkg/kstatus/status"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -341,7 +340,10 @@ func TestBucketReconciler_reconcileStorage(t *testing.T) {
}()

r := &BucketReconciler{
Client: fakeclient.NewClientBuilder().WithScheme(testEnv.GetScheme()).Build(),
Client: fakeclient.NewClientBuilder().
WithScheme(testEnv.GetScheme()).
WithStatusSubresource(&bucketv1.Bucket{}).
Build(),
EventRecorder: record.NewFakeRecorder(32),
Storage: testStorage,
patchOptions: getPatchOptions(bucketReadyCondition.Owned, "sc"),
Expand Down Expand Up @@ -653,25 +655,26 @@ func TestBucketReconciler_reconcileSource_generic(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

builder := fakeclient.NewClientBuilder().WithScheme(testEnv.Scheme())
clientBuilder := fakeclient.NewClientBuilder().
WithScheme(testEnv.Scheme()).
WithStatusSubresource(&bucketv1.Bucket{})

if tt.secret != nil {
builder.WithObjects(tt.secret)
clientBuilder.WithObjects(tt.secret)
}

r := &BucketReconciler{
EventRecorder: record.NewFakeRecorder(32),
Client: builder.Build(),
Client: clientBuilder.Build(),
Storage: testStorage,
patchOptions: getPatchOptions(bucketReadyCondition.Owned, "sc"),
}
tmpDir := t.TempDir()

obj := &bucketv1.Bucket{
TypeMeta: metav1.TypeMeta{
Kind: bucketv1.BucketKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-bucket",
Generation: 1,
GenerateName: "test-bucket-",
Generation: 1,
},
Spec: bucketv1.BucketSpec{
Timeout: &metav1.Duration{Duration: timeout},
Expand Down Expand Up @@ -996,26 +999,27 @@ func TestBucketReconciler_reconcileSource_gcs(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

builder := fakeclient.NewClientBuilder().WithScheme(testEnv.Scheme())
clientBuilder := fakeclient.NewClientBuilder().
WithScheme(testEnv.Scheme()).
WithStatusSubresource(&bucketv1.Bucket{})

if tt.secret != nil {
builder.WithObjects(tt.secret)
clientBuilder.WithObjects(tt.secret)
}

r := &BucketReconciler{
EventRecorder: record.NewFakeRecorder(32),
Client: builder.Build(),
Client: clientBuilder.Build(),
Storage: testStorage,
patchOptions: getPatchOptions(bucketReadyCondition.Owned, "sc"),
}
tmpDir := t.TempDir()

// Test bucket object.
obj := &bucketv1.Bucket{
TypeMeta: metav1.TypeMeta{
Kind: bucketv1.BucketKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-bucket",
Generation: 1,
GenerateName: "test-bucket-",
Generation: 1,
},
Spec: bucketv1.BucketSpec{
BucketName: tt.bucketName,
Expand Down Expand Up @@ -1191,19 +1195,18 @@ func TestBucketReconciler_reconcileArtifact(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

clientBuilder := fakeclient.NewClientBuilder().
WithScheme(testEnv.GetScheme()).
WithStatusSubresource(&bucketv1.Bucket{})

r := &BucketReconciler{
Client: fakeclient.NewClientBuilder().WithScheme(testEnv.GetScheme()).Build(),
Client: clientBuilder.Build(),
EventRecorder: record.NewFakeRecorder(32),
Storage: testStorage,
patchOptions: getPatchOptions(bucketReadyCondition.Owned, "sc"),
}

tmpDir := t.TempDir()

obj := &bucketv1.Bucket{
TypeMeta: metav1.TypeMeta{
Kind: bucketv1.BucketKind,
},
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-bucket-",
Generation: 1,
Expand All @@ -1214,6 +1217,7 @@ func TestBucketReconciler_reconcileArtifact(t *testing.T) {
},
}

tmpDir := t.TempDir()
index := index.NewDigester()

if tt.beforeFunc != nil {
Expand Down Expand Up @@ -1296,17 +1300,20 @@ func TestBucketReconciler_statusConditions(t *testing.T) {

obj := &bucketv1.Bucket{
TypeMeta: metav1.TypeMeta{
APIVersion: bucketv1.GroupVersion.String(),
Kind: bucketv1.BucketKind,
APIVersion: "source.toolkit.fluxcd.io/v1beta2",
},
ObjectMeta: metav1.ObjectMeta{
Name: "bucket",
Name: "test-bucket",
Namespace: "foo",
},
}
clientBuilder := fake.NewClientBuilder()
clientBuilder.WithObjects(obj)
c := clientBuilder.Build()

c := fakeclient.NewClientBuilder().
WithScheme(testEnv.Scheme()).
WithObjects(obj).
WithStatusSubresource(&bucketv1.Bucket{}).
Build()

serialPatcher := patch.NewSerialPatcher(obj, c)

Expand Down
6 changes: 2 additions & 4 deletions internal/controller/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ type GitRepositoryReconciler struct {
}

type GitRepositoryReconcilerOptions struct {
MaxConcurrentReconciles int
DependencyRequeueInterval time.Duration
RateLimiter ratelimiter.RateLimiter
}
Expand All @@ -161,8 +160,7 @@ func (r *GitRepositoryReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, o
predicate.Or(predicate.GenerationChangedPredicate{}, predicates.ReconcileRequestedPredicate{}),
)).
WithOptions(controller.Options{
MaxConcurrentReconciles: opts.MaxConcurrentReconciles,
RateLimiter: opts.RateLimiter,
RateLimiter: opts.RateLimiter,
}).
Complete(r)
}
Expand Down Expand Up @@ -787,7 +785,7 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
obj *sourcev1.GitRepository, authOpts *git.AuthOptions, dir string,
optimized bool) (*git.Commit, error) {
// Configure checkout strategy.
cloneOpts := repository.CloneOptions{
cloneOpts := repository.CloneConfig{
RecurseSubmodules: obj.Spec.RecurseSubmodules,
ShallowClone: true,
}
Expand Down
Loading

0 comments on commit eeef91a

Please sign in to comment.