Skip to content

Commit 2c9b993

Browse files
committed
fix: install VPA CRD directly on clusterfor bundle e2e test.
1 parent 5dc2e63 commit 2c9b993

File tree

3 files changed

+391
-5
lines changed

3 files changed

+391
-5
lines changed

test/e2e/bundle_e2e_test.go

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ package e2e
22

33
import (
44
"context"
5+
"encoding/json"
6+
7+
"github.com/ghodss/yaml"
8+
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
9+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
10+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
511

612
. "github.com/onsi/ginkgo"
713
. "github.com/onsi/gomega"
@@ -14,6 +20,7 @@ import (
1420
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
1521
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
1622
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
23+
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/testdata/vpa"
1724
)
1825

1926
var _ = Describe("Installing bundles with new object types", func() {
@@ -34,21 +41,50 @@ var _ = Describe("Installing bundles with new object types", func() {
3441
})
3542

3643
When("a bundle with a pdb, priorityclass, and VPA object is installed", func() {
37-
By("including the VPA CRD in the CSV")
3844
const (
3945
packageName = "busybox"
4046
channelName = "alpha"
4147
subName = "test-subscription"
4248
)
49+
var vpaCRD unstructured.Unstructured
4350

4451
BeforeEach(func() {
52+
By("first installing the VPA CRD on cluster")
4553
const (
4654
sourceName = "test-catalog"
4755
imageName = "quay.io/olmtest/single-bundle-index:pdb"
4856
)
4957

58+
// create VPA CRD on cluster
59+
y, err := vpa.Asset("test/e2e/testdata/vpa/crd.yaml")
60+
Expect(err).ToNot(HaveOccurred(), "could not read vpa bindata")
61+
62+
data, err := yaml.YAMLToJSON(y)
63+
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to json")
64+
65+
err = json.Unmarshal(data, &vpaCRD)
66+
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to unstructured")
67+
68+
Eventually(func() error {
69+
err := ctx.Ctx().Client().Create(context.TODO(), &vpaCRD)
70+
if err != nil {
71+
if !k8serrors.IsAlreadyExists(err) {
72+
return err
73+
}
74+
}
75+
return nil
76+
}).Should(Succeed())
77+
78+
// ensure vpa crd is established and accepted on the cluster before continuing
79+
Eventually(func() (bool, error) {
80+
crd, err := kubeClient.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), vpaCRD.GetName(), metav1.GetOptions{})
81+
if err != nil {
82+
return false, err
83+
}
84+
return crdReady(&crd.Status), nil
85+
}).Should(BeTrue())
86+
5087
var installPlanRef string
51-
// create catalog source
5288
source := &v1alpha1.CatalogSource{
5389
TypeMeta: metav1.TypeMeta{
5490
Kind: v1alpha1.CatalogSourceKind,
@@ -65,8 +101,10 @@ var _ = Describe("Installing bundles with new object types", func() {
65101
},
66102
}
67103

68-
source, err := operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
69-
Expect(err).ToNot(HaveOccurred(), "could not create catalog source")
104+
Eventually(func() error {
105+
source, err = operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
106+
return err
107+
}).Should(Succeed())
70108

71109
// Create a Subscription for package
72110
_ = createSubscriptionForCatalog(operatorClient, source.GetNamespace(), subName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic)
@@ -90,7 +128,7 @@ var _ = Describe("Installing bundles with new object types", func() {
90128
vpaVersion = "v1"
91129
vpaResource = "verticalpodautoscalers"
92130
pdbName = "busybox-pdb"
93-
priorityClassName = "high-priority"
131+
priorityClassName = "super-priority"
94132
vpaName = "busybox-vpa"
95133
)
96134

@@ -116,5 +154,36 @@ var _ = Describe("Installing bundles with new object types", func() {
116154
return err
117155
}).Should(Succeed(), "expected no error finding vpa object associated with csv")
118156
})
157+
158+
AfterEach(func() {
159+
By("Deleting the VPA CRD")
160+
Eventually(func() error {
161+
err := ctx.Ctx().Client().Delete(context.TODO(), &vpaCRD)
162+
if k8serrors.IsNotFound(err) {
163+
return nil
164+
}
165+
return err
166+
}).Should(Succeed())
167+
})
119168
})
120169
})
170+
171+
func crdReady(status *apiextensionsv1beta1.CustomResourceDefinitionStatus) bool {
172+
if status == nil {
173+
return false
174+
}
175+
established, namesAccepted := false, false
176+
for _, cdt := range status.Conditions {
177+
switch cdt.Type {
178+
case apiextensionsv1beta1.Established:
179+
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
180+
established = true
181+
}
182+
case apiextensionsv1beta1.NamesAccepted:
183+
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
184+
namesAccepted = true
185+
}
186+
}
187+
}
188+
return established && namesAccepted
189+
}

test/e2e/testdata/vpa/crd.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: verticalpodautoscalers.autoscaling.k8s.io
5+
annotations:
6+
"api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/63797"
7+
spec:
8+
group: autoscaling.k8s.io
9+
scope: Namespaced
10+
names:
11+
plural: verticalpodautoscalers
12+
singular: verticalpodautoscaler
13+
kind: VerticalPodAutoscaler
14+
shortNames:
15+
- vpa
16+
version: v1beta1
17+
versions:
18+
- name: v1beta1
19+
served: false
20+
storage: false
21+
- name: v1beta2
22+
served: true
23+
storage: true
24+
- name: v1
25+
served: true
26+
storage: false
27+
validation:
28+
# openAPIV3Schema is the schema for validating custom objects.
29+
openAPIV3Schema:
30+
type: object
31+
properties:
32+
spec:
33+
type: object
34+
required: []
35+
properties:
36+
targetRef:
37+
type: object
38+
updatePolicy:
39+
type: object
40+
properties:
41+
updateMode:
42+
type: string
43+
resourcePolicy:
44+
type: object
45+
properties:
46+
containerPolicies:
47+
type: array
48+
items:
49+
type: object
50+
properties:
51+
containerName:
52+
type: string
53+
mode:
54+
type: string
55+
enum: ["Auto", "Off"]
56+
minAllowed:
57+
type: object
58+
maxAllowed:
59+
type: object
60+
controlledResources:
61+
type: array
62+
items:
63+
type: string
64+
enum: ["cpu", "memory"]

0 commit comments

Comments
 (0)