Skip to content

Commit

Permalink
Bump controller runtime and Kube libs
Browse files Browse the repository at this point in the history
  • Loading branch information
irajdeep committed Jan 12, 2024
1 parent 6534d40 commit fcfb744
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 563 deletions.
8 changes: 6 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
Expand Down Expand Up @@ -82,8 +83,11 @@ func main() {

// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{
Namespace: watchNamespace,
})
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{
watchNamespace: {},
},
}})
if err != nil {
log.Sugar().Fatalf("Unable to create manager: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions controllers/replica_set_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/imdario/mergo"
mdbv1 "github.com/mongodb/mongodb-kubernetes-operator/api/v1"
Expand Down Expand Up @@ -80,8 +79,8 @@ func (r *ReplicaSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(controller.Options{MaxConcurrentReconciles: 3}).
For(&mdbv1.MongoDBCommunity{}, builder.WithPredicates(predicates.OnlyOnSpecChange())).
Watches(&source.Kind{Type: &corev1.Secret{}}, r.secretWatcher).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, r.configMapWatcher).
Watches(&corev1.Secret{}, r.secretWatcher).
Watches(&corev1.ConfigMap{}, r.configMapWatcher).
Owns(&appsv1.StatefulSet{}).
Complete(r)
}
Expand Down
10 changes: 6 additions & 4 deletions controllers/watch/watch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package watch

import (
"context"

"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/contains"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -38,19 +40,19 @@ func (w ResourceWatcher) Watch(watchedName, dependentName types.NamespacedName)
w.watched[watchedName] = append(existing, dependentName)
}

func (w ResourceWatcher) Create(event event.CreateEvent, queue workqueue.RateLimitingInterface) {
func (w ResourceWatcher) Create(ctx context.Context, event event.CreateEvent, queue workqueue.RateLimitingInterface) {
w.handleEvent(event.Object, queue)
}

func (w ResourceWatcher) Update(event event.UpdateEvent, queue workqueue.RateLimitingInterface) {
func (w ResourceWatcher) Update(ctx context.Context, event event.UpdateEvent, queue workqueue.RateLimitingInterface) {
w.handleEvent(event.ObjectOld, queue)
}

func (w ResourceWatcher) Delete(event event.DeleteEvent, queue workqueue.RateLimitingInterface) {
func (w ResourceWatcher) Delete(ctx context.Context, event event.DeleteEvent, queue workqueue.RateLimitingInterface) {
w.handleEvent(event.Object, queue)
}

func (w ResourceWatcher) Generic(event event.GenericEvent, queue workqueue.RateLimitingInterface) {
func (w ResourceWatcher) Generic(ctx context.Context, event event.GenericEvent, queue workqueue.RateLimitingInterface) {
w.handleEvent(event.Object, queue)
}

Expand Down
25 changes: 13 additions & 12 deletions controllers/watch/watch_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package watch

import (
"context"
"testing"

"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -43,9 +44,9 @@ func TestWatcher(t *testing.T) {

t.Run("Non-watched object", func(t *testing.T) {
watcher := New()
queue := controllertest.Queue{Interface: workqueue.New()}
queue := &controllertest.Queue{Interface: workqueue.New()}

watcher.Create(event.CreateEvent{
watcher.Create(context.Background(), event.CreateEvent{
Object: obj,
}, queue)

Expand All @@ -55,11 +56,11 @@ func TestWatcher(t *testing.T) {

t.Run("Multiple objects to reconcile", func(t *testing.T) {
watcher := New()
queue := controllertest.Queue{Interface: workqueue.New()}
queue := &controllertest.Queue{Interface: workqueue.New()}
watcher.Watch(objNsName, mdb1.NamespacedName())
watcher.Watch(objNsName, mdb2.NamespacedName())

watcher.Create(event.CreateEvent{
watcher.Create(context.Background(), event.CreateEvent{
Object: obj,
}, queue)

Expand All @@ -69,10 +70,10 @@ func TestWatcher(t *testing.T) {

t.Run("Create event", func(t *testing.T) {
watcher := New()
queue := controllertest.Queue{Interface: workqueue.New()}
queue := &controllertest.Queue{Interface: workqueue.New()}
watcher.Watch(objNsName, mdb1.NamespacedName())

watcher.Create(event.CreateEvent{
watcher.Create(context.Background(), event.CreateEvent{
Object: obj,
}, queue)

Expand All @@ -81,10 +82,10 @@ func TestWatcher(t *testing.T) {

t.Run("Update event", func(t *testing.T) {
watcher := New()
queue := controllertest.Queue{Interface: workqueue.New()}
queue := &controllertest.Queue{Interface: workqueue.New()}
watcher.Watch(objNsName, mdb1.NamespacedName())

watcher.Update(event.UpdateEvent{
watcher.Update(context.Background(), event.UpdateEvent{
ObjectOld: obj,
ObjectNew: obj,
}, queue)
Expand All @@ -94,10 +95,10 @@ func TestWatcher(t *testing.T) {

t.Run("Delete event", func(t *testing.T) {
watcher := New()
queue := controllertest.Queue{Interface: workqueue.New()}
queue := &controllertest.Queue{Interface: workqueue.New()}
watcher.Watch(objNsName, mdb1.NamespacedName())

watcher.Delete(event.DeleteEvent{
watcher.Delete(context.Background(), event.DeleteEvent{
Object: obj,
}, queue)

Expand All @@ -106,10 +107,10 @@ func TestWatcher(t *testing.T) {

t.Run("Generic event", func(t *testing.T) {
watcher := New()
queue := controllertest.Queue{Interface: workqueue.New()}
queue := &controllertest.Queue{Interface: workqueue.New()}
watcher.Watch(objNsName, mdb1.NamespacedName())

watcher.Generic(event.GenericEvent{
watcher.Generic(context.Background(), event.GenericEvent{
Object: obj,
}, queue)

Expand Down
61 changes: 31 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,75 @@ require (
go.mongodb.org/mongo-driver v1.13.1
go.uber.org/zap v1.26.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
k8s.io/api v0.26.10
k8s.io/apimachinery v0.26.10
k8s.io/client-go v0.26.10
sigs.k8s.io/controller-runtime v0.14.7
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/yaml v1.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // 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/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // 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/spf13/pflag v1.0.5 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.15.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
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.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.26.10 // indirect
k8s.io/component-base v0.26.10 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // 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/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Loading

0 comments on commit fcfb744

Please sign in to comment.