Skip to content

Commit

Permalink
updating methods to comply with k8 1.30
Browse files Browse the repository at this point in the history
Signed-off-by: Adam D. Cornett <[email protected]>
  • Loading branch information
acornett21 committed Oct 17, 2024
1 parent a6ff0a6 commit 108ec1b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion internal/ansible/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -125,7 +126,7 @@ func Add(mgr manager.Manager, options Options) *controller.Controller {

u := &unstructured.Unstructured{}
u.SetGroupVersionKind(options.GVK)
err = c.Watch(source.Kind(mgr.GetCache(), u), handler.LoggingEnqueueRequestForObject{}, predicates...)
err = c.Watch(source.Kind(mgr.GetCache(), client.Object(u), handler.LoggingEnqueueRequestForObject{}, predicates...))
if err != nil {
log.Error(err, "")
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion internal/ansible/handler/logging_enqueue_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
//
// &handler.LoggingEnqueueRequestForAnnotation{}
type LoggingEnqueueRequestForAnnotation struct {
handler.EnqueueRequestForAnnotation
handler.EnqueueRequestForAnnotation[client.Object]
}

// Create implements EventHandler, and emits a log message.
Expand Down
4 changes: 2 additions & 2 deletions internal/ansible/handler/logging_enqueue_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var log = logf.Log.WithName("ansible").WithName("handler")
//
// &handler.LoggingEnqueueRequestForObject{}
type LoggingEnqueueRequestForObject struct {
handler.InstrumentedEnqueueRequestForObject
handler.InstrumentedEnqueueRequestForObject[client.Object]
}

// Create implements EventHandler, and emits a log message.
Expand All @@ -54,7 +54,7 @@ func (h LoggingEnqueueRequestForObject) Delete(ctx context.Context, e event.Dele
// Generic implements EventHandler, and emits a log message.
func (h LoggingEnqueueRequestForObject) Generic(ctx context.Context, e event.GenericEvent, q workqueue.RateLimitingInterface) {
h.logEvent("Generic", e.Object)
h.EnqueueRequestForObject.Generic(ctx, e, q)
h.InstrumentedEnqueueRequestForObject.Generic(ctx, e, q)
}

func (h LoggingEnqueueRequestForObject) logEvent(eventType string, object client.Object) {
Expand Down
11 changes: 6 additions & 5 deletions internal/ansible/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/operator-framework/ansible-operator-plugins/internal/ansible/handler"
Expand Down Expand Up @@ -238,9 +239,9 @@ func addWatchToController(owner kubeconfig.NamespacedOwnerReference, cMap *contr
owMap.Store(resource.GroupVersionKind())
log.Info("Watching child resource", "kind", resource.GroupVersionKind(),
"enqueue_kind", u.GroupVersionKind())
err := contents.Controller.Watch(source.Kind(cache, resource),
err := contents.Controller.Watch(source.Kind(cache, client.Object(resource),
handler.EnqueueRequestForOwnerWithLogging(scheme, restMapper, u),
predicate.DependentPredicate{})
predicate.DependentPredicate{}))
// Store watch in map
if err != nil {
log.Error(err, "Failed to watch child resource",
Expand All @@ -260,9 +261,9 @@ func addWatchToController(owner kubeconfig.NamespacedOwnerReference, cMap *contr
}
log.Info("Watching child resource", "kind", resource.GroupVersionKind(),
"enqueue_annotation_type", ownerGK.String())
err = contents.Controller.Watch(source.Kind(cache, resource), &handler.LoggingEnqueueRequestForAnnotation{
EnqueueRequestForAnnotation: libhandler.EnqueueRequestForAnnotation{Type: ownerGK},
}, predicate.DependentPredicate{})
err = contents.Controller.Watch(source.Kind(cache, client.Object(resource), &handler.LoggingEnqueueRequestForAnnotation{
EnqueueRequestForAnnotation: libhandler.EnqueueRequestForAnnotation[client.Object]{Type: ownerGK},
}, predicate.DependentPredicate{}))
if err != nil {
log.Error(err, "Failed to watch child resource",
"kind", resource.GroupVersionKind(), "enqueue_kind", u.GroupVersionKind())
Expand Down

0 comments on commit 108ec1b

Please sign in to comment.