Skip to content

Commit fb1b110

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

File tree

1 file changed

+117
-2
lines changed

1 file changed

+117
-2
lines changed

test/e2e/bundle_e2e_test.go

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

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

610
. "github.com/onsi/ginkgo"
711
. "github.com/onsi/gomega"
@@ -16,6 +20,73 @@ import (
1620
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
1721
)
1822

23+
const vpaCRDManifest = `
24+
apiVersion: apiextensions.k8s.io/v1beta1
25+
kind: CustomResourceDefinition
26+
metadata:
27+
name: verticalpodautoscalers.autoscaling.k8s.io
28+
annotations:
29+
"api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/63797"
30+
spec:
31+
group: autoscaling.k8s.io
32+
scope: Namespaced
33+
names:
34+
plural: verticalpodautoscalers
35+
singular: verticalpodautoscaler
36+
kind: VerticalPodAutoscaler
37+
shortNames:
38+
- vpa
39+
version: v1beta1
40+
versions:
41+
- name: v1beta1
42+
served: false
43+
storage: false
44+
- name: v1beta2
45+
served: true
46+
storage: true
47+
- name: v1
48+
served: true
49+
storage: false
50+
validation:
51+
# openAPIV3Schema is the schema for validating custom objects.
52+
openAPIV3Schema:
53+
type: object
54+
properties:
55+
spec:
56+
type: object
57+
required: []
58+
properties:
59+
targetRef:
60+
type: object
61+
updatePolicy:
62+
type: object
63+
properties:
64+
updateMode:
65+
type: string
66+
resourcePolicy:
67+
type: object
68+
properties:
69+
containerPolicies:
70+
type: array
71+
items:
72+
type: object
73+
properties:
74+
containerName:
75+
type: string
76+
mode:
77+
type: string
78+
enum: ["Auto", "Off"]
79+
minAllowed:
80+
type: object
81+
maxAllowed:
82+
type: object
83+
controlledResources:
84+
type: array
85+
items:
86+
type: string
87+
enum: ["cpu", "memory"]
88+
`
89+
1990
var _ = Describe("Installing bundles with new object types", func() {
2091
var (
2192
kubeClient operatorclient.ClientInterface
@@ -34,7 +105,7 @@ var _ = Describe("Installing bundles with new object types", func() {
34105
})
35106

36107
When("a bundle with a pdb, priorityclass, and VPA object is installed", func() {
37-
By("including the VPA CRD in the CSV")
108+
By("first installing the VPA CRD on cluster")
38109
const (
39110
packageName = "busybox"
40111
channelName = "alpha"
@@ -47,6 +118,30 @@ var _ = Describe("Installing bundles with new object types", func() {
47118
imageName = "quay.io/olmtest/single-bundle-index:pdb"
48119
)
49120

121+
// create VPA CRD on cluster
122+
data, err := yaml.YAMLToJSON([]byte(vpaCRDManifest))
123+
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to json")
124+
125+
crd := &apiextensionsv1beta1.CustomResourceDefinition{}
126+
err = json.Unmarshal(data, crd)
127+
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to unstructured")
128+
129+
_, err = kubeClient.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Create(context.TODO(), crd, metav1.CreateOptions{})
130+
if err != nil {
131+
if !k8serrors.IsAlreadyExists(err) {
132+
Expect(err).ToNot(HaveOccurred(), "could not create vpa crd to on cluster")
133+
}
134+
}
135+
136+
// ensure vpa crd is established and accepted on the cluster before continuing
137+
Eventually(func () bool {
138+
crd, err := kubeClient.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), crd.GetName(), metav1.GetOptions{})
139+
if err != nil {
140+
return false
141+
}
142+
return crdReady(&crd.Status)
143+
}).Should(BeTrue())
144+
50145
var installPlanRef string
51146
// create catalog source
52147
source := &v1alpha1.CatalogSource{
@@ -65,7 +160,7 @@ var _ = Describe("Installing bundles with new object types", func() {
65160
},
66161
}
67162

68-
source, err := operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
163+
source, err = operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
69164
Expect(err).ToNot(HaveOccurred(), "could not create catalog source")
70165

71166
// Create a Subscription for package
@@ -118,3 +213,23 @@ var _ = Describe("Installing bundles with new object types", func() {
118213
})
119214
})
120215
})
216+
217+
func crdReady(status *apiextensionsv1beta1.CustomResourceDefinitionStatus) bool {
218+
if status == nil {
219+
return false
220+
}
221+
established, namesAccepted := false, false
222+
for _, cdt := range status.Conditions{
223+
switch cdt.Type {
224+
case apiextensionsv1beta1.Established:
225+
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
226+
established = true
227+
}
228+
case apiextensionsv1beta1.NamesAccepted:
229+
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
230+
namesAccepted = true
231+
}
232+
}
233+
}
234+
return established && namesAccepted
235+
}

0 commit comments

Comments
 (0)