Skip to content

Commit ff94842

Browse files
Merge pull request #1577 from exdx/feat/support-pdbs
feat: support priorityclass, poddisruptionbudget, and vpa objects
2 parents 53f6fa4 + 4aa2684 commit ff94842

File tree

2 files changed

+126
-8
lines changed

2 files changed

+126
-8
lines changed

pkg/controller/operators/catalog/operator.go

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

19441944
const (
1945-
PrometheusRuleKind = "PrometheusRule"
1946-
ServiceMonitorKind = "ServiceMonitor"
1945+
PrometheusRuleKind = "PrometheusRule"
1946+
ServiceMonitorKind = "ServiceMonitor"
1947+
PodDisruptionBudgetKind = "PodDisruptionBudget"
1948+
PriorityClassKind = "PriorityClass"
1949+
VerticalPodAutoscalerKind = "VerticalPodAutoscaler"
19471950
)
19481951

1952+
var supportedKinds = map[string]struct{}{
1953+
PrometheusRuleKind: {},
1954+
ServiceMonitorKind: {},
1955+
PodDisruptionBudgetKind: {},
1956+
PriorityClassKind: {},
1957+
VerticalPodAutoscalerKind: {},
1958+
}
1959+
19491960
// isSupported returns true if OLM supports this type of CustomResource.
19501961
func isSupported(kind string) bool {
1951-
switch kind {
1952-
case PrometheusRuleKind, ServiceMonitorKind:
1953-
return true
1954-
default:
1955-
return false
1956-
}
1962+
_, ok := supportedKinds[kind]
1963+
return ok
19571964
}

test/e2e/bundle_e2e_test.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
"k8s.io/client-go/dynamic"
7+
8+
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/gomega"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
12+
"github.com/operator-framework/api/pkg/operators/v1alpha1"
13+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
14+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
15+
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
16+
)
17+
18+
var _ = Describe("Installing bundles with new object types", func() {
19+
var (
20+
kubeClient operatorclient.ClientInterface
21+
operatorClient versioned.Interface
22+
dynamicClient dynamic.Interface
23+
)
24+
25+
BeforeEach(func() {
26+
kubeClient = ctx.Ctx().KubeClient()
27+
operatorClient = ctx.Ctx().OperatorClient()
28+
dynamicClient = ctx.Ctx().DynamicClient()
29+
})
30+
31+
AfterEach(func() {
32+
cleaner.NotifyTestComplete(true)
33+
})
34+
35+
When("a bundle with a pdb, priorityclass, and VPA object is installed", func() {
36+
By("including the VPA CRD in the CSV")
37+
const (
38+
packageName = "busybox"
39+
channelName = "alpha"
40+
subName = "test-subscription"
41+
)
42+
43+
BeforeEach(func() {
44+
const (
45+
sourceName = "test-catalog"
46+
imageName = "quay.io/olmtest/single-bundle-index:pdb"
47+
)
48+
// create catalog source
49+
source := &v1alpha1.CatalogSource{
50+
TypeMeta: metav1.TypeMeta{
51+
Kind: v1alpha1.CatalogSourceKind,
52+
APIVersion: v1alpha1.CatalogSourceCRDAPIVersion,
53+
},
54+
ObjectMeta: metav1.ObjectMeta{
55+
Name: sourceName,
56+
Namespace: testNamespace,
57+
Labels: map[string]string{"olm.catalogSource": sourceName},
58+
},
59+
Spec: v1alpha1.CatalogSourceSpec{
60+
SourceType: v1alpha1.SourceTypeGrpc,
61+
Image: imageName,
62+
},
63+
}
64+
65+
source, err := operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
66+
Expect(err).ToNot(HaveOccurred(), "could not create catalog source")
67+
68+
// Create a Subscription for package
69+
_ = createSubscriptionForCatalog(operatorClient, source.GetNamespace(), subName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic)
70+
71+
// Wait for the Subscription to succeed
72+
Eventually(func() error {
73+
_, err = fetchSubscription(operatorClient, testNamespace, subName, subscriptionStateAtLatestChecker)
74+
return err
75+
}).Should(BeNil())
76+
})
77+
78+
It("should create the additional bundle objects", func() {
79+
const (
80+
vpaGroup = "autoscaling.k8s.io"
81+
vpaVersion = "v1"
82+
vpaResource = "verticalpodautoscalers"
83+
pdbName = "busybox-pdb"
84+
priorityClassName = "high-priority"
85+
vpaName = "busybox-vpa"
86+
)
87+
88+
var resource = schema.GroupVersionResource{
89+
Group: vpaGroup,
90+
Version: vpaVersion,
91+
Resource: vpaResource,
92+
}
93+
94+
// confirm extra bundle objects are installed
95+
Eventually(func() error {
96+
_, err := kubeClient.KubernetesInterface().PolicyV1beta1().PodDisruptionBudgets(testNamespace).Get(context.TODO(), pdbName, metav1.GetOptions{})
97+
return err
98+
}).Should(Succeed(), "expected no error getting pdb object associated with CSV")
99+
100+
Eventually(func() error {
101+
_, err := kubeClient.KubernetesInterface().SchedulingV1().PriorityClasses().Get(context.TODO(), priorityClassName, metav1.GetOptions{})
102+
return err
103+
}).Should(Succeed(), "expected no error getting priorityclass object associated with CSV")
104+
105+
Eventually(func() error {
106+
_, err := dynamicClient.Resource(resource).Namespace(testNamespace).Get(context.TODO(), vpaName, metav1.GetOptions{})
107+
return err
108+
}).Should(Succeed(), "expected no error finding vpa object associated with csv")
109+
})
110+
})
111+
})

0 commit comments

Comments
 (0)