Skip to content

Commit 964ca16

Browse files
Merge pull request #1637 from exdx/fix/vpa-crd-e2e
fix: install VPA CRD directly on clusterfor bundle e2e test
2 parents c3bcd2e + 2c9b993 commit 964ca16

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
// FIXME: Reintegrate this test
@@ -35,21 +42,50 @@ var _ = PDescribe("Installing bundles with new object types", func() {
3542
})
3643

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

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

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

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

72110
// Create a Subscription for package
73111
_ = createSubscriptionForCatalog(operatorClient, source.GetNamespace(), subName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic)
@@ -91,7 +129,7 @@ var _ = PDescribe("Installing bundles with new object types", func() {
91129
vpaVersion = "v1"
92130
vpaResource = "verticalpodautoscalers"
93131
pdbName = "busybox-pdb"
94-
priorityClassName = "high-priority"
132+
priorityClassName = "super-priority"
95133
vpaName = "busybox-vpa"
96134
)
97135

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

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)