Skip to content

Commit 63ff4ff

Browse files
committed
feat: support new bundle object types
1 parent bed57b1 commit 63ff4ff

File tree

8 files changed

+482
-23
lines changed

8 files changed

+482
-23
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,16 +1906,23 @@ func (o *Operator) apiresourceFromGVK(gvk schema.GroupVersionKind) (metav1.APIRe
19061906
}
19071907

19081908
const (
1909-
PrometheusRuleKind = "PrometheusRule"
1910-
ServiceMonitorKind = "ServiceMonitor"
1909+
PrometheusRuleKind = "PrometheusRule"
1910+
ServiceMonitorKind = "ServiceMonitor"
1911+
PodDisruptionBudgetKind = "PodDisruptionBudget"
1912+
PriorityClassKind = "PriorityClass"
1913+
VerticalPodAutoscalerKind = "VerticalPodAutoscaler"
19111914
)
19121915

1916+
var supportedKinds = map[string]struct{}{
1917+
PrometheusRuleKind: {},
1918+
ServiceMonitorKind: {},
1919+
PodDisruptionBudgetKind: {},
1920+
PriorityClassKind: {},
1921+
VerticalPodAutoscalerKind: {},
1922+
}
1923+
19131924
// isSupported returns true if OLM supports this type of CustomResource.
19141925
func isSupported(kind string) bool {
1915-
switch kind {
1916-
case PrometheusRuleKind, ServiceMonitorKind:
1917-
return true
1918-
default:
1919-
return false
1920-
}
1926+
_, ok := supportedKinds[kind]
1927+
return ok
19211928
}

pkg/controller/operators/olm/operator.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
schedulingv1 "k8s.io/api/scheduling/v1"
78
"strings"
89
"time"
910

@@ -395,6 +396,21 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
395396
return nil, err
396397
}
397398

399+
priorityClassInformer := k8sInformerFactory.Scheduling().V1().PriorityClasses()
400+
op.lister.SchedulingV1().RegisterPriorityClassLister(priorityClassInformer.Lister())
401+
priorityClassQueueInformer, err := queueinformer.NewQueueInformer(
402+
ctx,
403+
queueinformer.WithLogger(op.logger),
404+
queueinformer.WithInformer(priorityClassInformer.Informer()),
405+
queueinformer.WithSyncer(k8sSyncer),
406+
)
407+
if err != nil {
408+
return nil, err
409+
}
410+
if err := op.RegisterQueueInformer(priorityClassQueueInformer); err != nil {
411+
return nil, err
412+
}
413+
398414
// register namespace queueinformer
399415
namespaceInformer := k8sInformerFactory.Core().V1().Namespaces()
400416
op.lister.CoreV1().RegisterNamespaceLister(namespaceInformer.Lister())
@@ -702,7 +718,7 @@ func (a *Operator) syncObject(obj interface{}) (syncError error) {
702718
a.requeueOwnerCSVs(metaObj)
703719
} else {
704720
switch metaObj.(type) {
705-
case *rbacv1.ClusterRole, *rbacv1.ClusterRoleBinding, *admissionregistrationv1.MutatingWebhookConfiguration, *admissionregistrationv1.ValidatingWebhookConfiguration:
721+
case *rbacv1.ClusterRole, *rbacv1.ClusterRoleBinding, *admissionregistrationv1.MutatingWebhookConfiguration, *admissionregistrationv1.ValidatingWebhookConfiguration, *schedulingv1.PriorityClass:
706722
resourceEvent := kubestate.NewResourceEvent(
707723
kubestate.ResourceUpdated,
708724
metaObj,
@@ -990,6 +1006,17 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
9901006
logger.WithError(err).Warnf("failed to requeue gc event: %v", webhook)
9911007
}
9921008
}
1009+
1010+
priorityClasses, err := a.opClient.KubernetesInterface().SchedulingV1().PriorityClasses().List(context.TODO(), metav1.ListOptions{LabelSelector: webhookSelector})
1011+
if err != nil {
1012+
logger.WithError(err).Warn("cannot list priority classes")
1013+
}
1014+
for _, priorityClass := range priorityClasses.Items {
1015+
pc := priorityClass
1016+
if err := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, &pc)); err != nil {
1017+
logger.WithError(err).Warnf("failed to requeue gc event: %v", priorityClass)
1018+
}
1019+
}
9931020
}
9941021

9951022
func (a *Operator) removeDanglingChildCSVs(csv *v1alpha1.ClusterServiceVersion) error {

pkg/lib/operatorlister/lister.go

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
appsv1 "k8s.io/client-go/listers/apps/v1"
66
corev1 "k8s.io/client-go/listers/core/v1"
77
rbacv1 "k8s.io/client-go/listers/rbac/v1"
8+
scheduling "k8s.io/client-go/listers/scheduling/v1"
89
aregv1 "k8s.io/kube-aggregator/pkg/client/listers/apiregistration/v1"
910

1011
v1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1"
@@ -19,6 +20,7 @@ type OperatorLister interface {
1920
RbacV1() RbacV1Lister
2021
APIRegistrationV1() APIRegistrationV1Lister
2122
APIExtensionsV1() APIExtensionsV1Lister
23+
SchedulingV1() SchedulingV1Lister
2224

2325
OperatorsV1alpha1() OperatorsV1alpha1Lister
2426
OperatorsV1() OperatorsV1Lister
@@ -74,6 +76,12 @@ type APIExtensionsV1Lister interface {
7476
CustomResourceDefinitionLister() aextv1.CustomResourceDefinitionLister
7577
}
7678

79+
//go:generate counterfeiter . SchedulingV1Lister
80+
type SchedulingV1Lister interface {
81+
RegisterPriorityClassLister(lister scheduling.PriorityClassLister)
82+
PriorityClassLister() scheduling.PriorityClassLister
83+
}
84+
7785
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . OperatorsV1alpha1Lister
7886
type OperatorsV1alpha1Lister interface {
7987
RegisterClusterServiceVersionLister(namespace string, lister v1alpha1.ClusterServiceVersionLister)
@@ -160,6 +168,16 @@ func newAPIExtensionsV1Lister() *apiExtensionsV1Lister {
160168
}
161169
}
162170

171+
type schedulingV1Lister struct {
172+
priorityClassLister *UnionPriorityClassLister
173+
}
174+
175+
func newSchedulingV1Lister() *schedulingV1Lister {
176+
return &schedulingV1Lister{
177+
priorityClassLister: &UnionPriorityClassLister{},
178+
}
179+
}
180+
163181
type operatorsV1alpha1Lister struct {
164182
clusterServiceVersionLister *UnionClusterServiceVersionLister
165183
catalogSourceLister *UnionCatalogSourceLister
@@ -190,13 +208,14 @@ func newOperatorsV1Lister() *operatorsV1Lister {
190208
var _ OperatorLister = &lister{}
191209

192210
type lister struct {
193-
appsV1Lister *appsV1Lister
194-
coreV1Lister *coreV1Lister
195-
rbacV1Lister *rbacV1Lister
196-
apiRegistrationV1Lister *apiRegistrationV1Lister
197-
apiExtensionsV1Lister *apiExtensionsV1Lister
198-
operatorsV1alpha1Lister *operatorsV1alpha1Lister
199-
operatorsV1Lister *operatorsV1Lister
211+
appsV1Lister *appsV1Lister
212+
coreV1Lister *coreV1Lister
213+
rbacV1Lister *rbacV1Lister
214+
apiRegistrationV1Lister *apiRegistrationV1Lister
215+
apiExtensionsV1Lister *apiExtensionsV1Lister
216+
schedulingV1Lister *schedulingV1Lister
217+
operatorsV1alpha1Lister *operatorsV1alpha1Lister
218+
operatorsV1Lister *operatorsV1Lister
200219
}
201220

202221
func (l *lister) AppsV1() AppsV1Lister {
@@ -219,6 +238,10 @@ func (l *lister) APIExtensionsV1() APIExtensionsV1Lister {
219238
return l.apiExtensionsV1Lister
220239
}
221240

241+
func (l *lister) SchedulingV1() SchedulingV1Lister {
242+
return l.schedulingV1Lister
243+
}
244+
222245
func (l *lister) OperatorsV1alpha1() OperatorsV1alpha1Lister {
223246
return l.operatorsV1alpha1Lister
224247
}
@@ -230,12 +253,13 @@ func (l *lister) OperatorsV1() OperatorsV1Lister {
230253
func NewLister() OperatorLister {
231254
// TODO: better initialization
232255
return &lister{
233-
appsV1Lister: newAppsV1Lister(),
234-
coreV1Lister: newCoreV1Lister(),
235-
rbacV1Lister: newRbacV1Lister(),
236-
apiRegistrationV1Lister: newAPIRegistrationV1Lister(),
237-
apiExtensionsV1Lister: newAPIExtensionsV1Lister(),
238-
operatorsV1alpha1Lister: newOperatorsV1alpha1Lister(),
239-
operatorsV1Lister: newOperatorsV1Lister(),
256+
appsV1Lister: newAppsV1Lister(),
257+
coreV1Lister: newCoreV1Lister(),
258+
rbacV1Lister: newRbacV1Lister(),
259+
apiRegistrationV1Lister: newAPIRegistrationV1Lister(),
260+
apiExtensionsV1Lister: newAPIExtensionsV1Lister(),
261+
schedulingV1Lister: newSchedulingV1Lister(),
262+
operatorsV1alpha1Lister: newOperatorsV1alpha1Lister(),
263+
operatorsV1Lister: newOperatorsV1Lister(),
240264
}
241265
}

pkg/lib/operatorlister/operatorlisterfakes/fake_operator_lister.go

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)