Skip to content

Commit 6b42d67

Browse files
committed
Adapt to metricsbindaddress/default cache namespace API changes
Signed-off-by: Alex Kalenyuk <[email protected]>
1 parent 5489144 commit 6b42d67

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

examples/sample-operator/cmd/manager/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import (
2121
v1 "k8s.io/api/core/v1"
2222
"k8s.io/apimachinery/pkg/util/intstr"
2323
"k8s.io/client-go/rest"
24+
"sigs.k8s.io/controller-runtime/pkg/cache"
2425
"sigs.k8s.io/controller-runtime/pkg/client/config"
2526
logf "sigs.k8s.io/controller-runtime/pkg/log"
2627
"sigs.k8s.io/controller-runtime/pkg/manager"
2728
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
29+
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
2830

2931
"kubevirt.io/controller-lifecycle-operator-sdk/examples/sample-operator/pkg/apis"
3032
"kubevirt.io/controller-lifecycle-operator-sdk/examples/sample-operator/pkg/controller"
@@ -92,8 +94,14 @@ func main() {
9294

9395
// Create a new Cmd to provide shared dependencies and start components
9496
mgr, err := manager.New(cfg, manager.Options{
95-
Namespace: namespace,
96-
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
97+
Cache: cache.Options{
98+
DefaultNamespaces: map[string]cache.Config{
99+
namespace: {},
100+
},
101+
},
102+
Metrics: server.Options{
103+
BindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
104+
},
97105
})
98106
if err != nil {
99107
log.Error(err, "")

pkg/sdk/reconciler/reconciler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"reflect"
7+
"strings"
78
"sync"
89
"time"
910

@@ -566,7 +567,7 @@ func (r *Reconciler) WatchResourceTypes(resources ...client.Object) error {
566567
predicates := []predicate.Predicate{sdk.NewIgnoreLeaderElectionPredicate()}
567568

568569
if err := r.controller.Watch(source.Kind(r.getCache(), resource), eventHandler, predicates...); err != nil {
569-
if meta.IsNoMatchError(err) {
570+
if meta.IsNoMatchError(err) || strings.Contains(err.Error(), "failed to find API group") {
570571
r.log.Info("No match for type, NOT WATCHING", "type", t)
571572
continue
572573
}

0 commit comments

Comments
 (0)