Skip to content

Commit 933486e

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

File tree

2 files changed

+134
-3
lines changed

2 files changed

+134
-3
lines changed

test/e2e/bundle_e2e_test.go

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ package e2e
22

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

613
. "github.com/onsi/ginkgo"
714
. "github.com/onsi/gomega"
@@ -34,19 +41,49 @@ 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 u 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 := ioutil.ReadFile("data/vpa/crd.yaml")
60+
Expect(err).ToNot(HaveOccurred(), "could not convert read vpa crd")
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, &u)
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(), &u)
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(), u.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
5188
// create catalog source
5289
source := &v1alpha1.CatalogSource{
@@ -65,8 +102,10 @@ var _ = Describe("Installing bundles with new object types", func() {
65102
},
66103
}
67104

68-
source, err := operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
69-
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())
70109

71110
// Create a Subscription for package
72111
_ = createSubscriptionForCatalog(operatorClient, source.GetNamespace(), subName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic)
@@ -116,5 +155,33 @@ var _ = Describe("Installing bundles with new object types", func() {
116155
return err
117156
}).Should(Succeed(), "expected no error finding vpa object associated with csv")
118157
})
158+
159+
AfterEach(func() {
160+
By("Deleting the VPA CRD")
161+
Eventually(func() error {
162+
err := ctx.Ctx().Client().Delete(context.TODO(), &u)
163+
return err
164+
}).Should(Succeed())
165+
})
119166
})
120167
})
168+
169+
func crdReady(status *apiextensionsv1beta1.CustomResourceDefinitionStatus) bool {
170+
if status == nil {
171+
return false
172+
}
173+
established, namesAccepted := false, false
174+
for _, cdt := range status.Conditions {
175+
switch cdt.Type {
176+
case apiextensionsv1beta1.Established:
177+
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
178+
established = true
179+
}
180+
case apiextensionsv1beta1.NamesAccepted:
181+
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
182+
namesAccepted = true
183+
}
184+
}
185+
}
186+
return established && namesAccepted
187+
}

test/e2e/data/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)