Skip to content

Commit f7ed5b1

Browse files
olm: apparently there's a whole other controller framework
That also starts LIST + WATCH calls and needs labelling ... sigh. Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent b683c28 commit f7ed5b1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

cmd/olm/manager.go

+34
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ package main
33
import (
44
"context"
55

6+
appsv1 "k8s.io/api/apps/v1"
67
corev1 "k8s.io/api/core/v1"
8+
rbacv1 "k8s.io/api/rbac/v1"
9+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
710
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
811
"k8s.io/apimachinery/pkg/labels"
912
"k8s.io/apimachinery/pkg/runtime"
1013
"k8s.io/apimachinery/pkg/selection"
14+
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
1115
ctrl "sigs.k8s.io/controller-runtime"
1216
"sigs.k8s.io/controller-runtime/pkg/cache"
1317
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -53,6 +57,36 @@ func Manager(ctx context.Context, debug bool) (ctrl.Manager, error) {
5357
MetricsBindAddress: "0", // TODO(njhale): Enable metrics on non-conflicting port (not 8080)
5458
Cache: cache.Options{
5559
ByObject: map[client.Object]cache.ByObject{
60+
&appsv1.Deployment{}: {
61+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
62+
},
63+
&corev1.Service{}: {
64+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
65+
},
66+
&apiextensionsv1.CustomResourceDefinition{}: {
67+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
68+
},
69+
&apiregistrationv1.APIService{}: {
70+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
71+
},
72+
&corev1.ConfigMap{}: {
73+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
74+
},
75+
&corev1.ServiceAccount{}: {
76+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
77+
},
78+
&rbacv1.Role{}: {
79+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
80+
},
81+
&rbacv1.RoleBinding{}: {
82+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
83+
},
84+
&rbacv1.ClusterRole{}: {
85+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
86+
},
87+
&rbacv1.ClusterRoleBinding{}: {
88+
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
89+
},
5690
&corev1.Secret{}: {
5791
Label: labels.SelectorFromValidatedSet(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue}),
5892
},

pkg/controller/operators/adoption_controller_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
. "github.com/onsi/ginkgo/v2"
88
. "github.com/onsi/gomega"
9+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
910
appsv1 "k8s.io/api/apps/v1"
1011
corev1 "k8s.io/api/core/v1"
1112
rbacv1 "k8s.io/api/rbac/v1"
@@ -350,6 +351,12 @@ var _ = Describe("Adoption Controller", func() {
350351
),
351352
}
352353
for _, component := range components {
354+
labels := component.GetLabels()
355+
if labels == nil {
356+
labels = map[string]string{}
357+
}
358+
labels[install.OLMManagedLabelKey] = install.OLMManagedLabelValue
359+
component.SetLabels(labels)
353360
Eventually(func() error {
354361
return k8sClient.Create(ctx, component)
355362
}, timeout, interval).Should(Succeed())

0 commit comments

Comments
 (0)