Skip to content

fix: install VPA CRD directly on clusterfor bundle e2e test #1637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 74 additions & 5 deletions test/e2e/bundle_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package e2e

import (
"context"
"encoding/json"

"github.com/ghodss/yaml"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -14,6 +20,7 @@ import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/testdata/vpa"
)

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

When("a bundle with a pdb, priorityclass, and VPA object is installed", func() {
By("including the VPA CRD in the CSV")
const (
packageName = "busybox"
channelName = "alpha"
subName = "test-subscription"
)
var vpaCRD unstructured.Unstructured

BeforeEach(func() {
By("first installing the VPA CRD on cluster")
const (
sourceName = "test-catalog"
imageName = "quay.io/olmtest/single-bundle-index:pdb"
)

// create VPA CRD on cluster
y, err := vpa.Asset("test/e2e/testdata/vpa/crd.yaml")
Expect(err).ToNot(HaveOccurred(), "could not read vpa bindata")

data, err := yaml.YAMLToJSON(y)
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to json")

err = json.Unmarshal(data, &vpaCRD)
Expect(err).ToNot(HaveOccurred(), "could not convert vpa crd to unstructured")

Eventually(func() error {
err := ctx.Ctx().Client().Create(context.TODO(), &vpaCRD)
if err != nil {
if !k8serrors.IsAlreadyExists(err) {
return err
}
}
return nil
}).Should(Succeed())

// ensure vpa crd is established and accepted on the cluster before continuing
Eventually(func() (bool, error) {
crd, err := kubeClient.ApiextensionsInterface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.TODO(), vpaCRD.GetName(), metav1.GetOptions{})
if err != nil {
return false, err
}
return crdReady(&crd.Status), nil
}).Should(BeTrue())

var installPlanRef string
// create catalog source
source := &v1alpha1.CatalogSource{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.CatalogSourceKind,
Expand All @@ -65,8 +101,10 @@ var _ = Describe("Installing bundles with new object types", func() {
},
}

source, err := operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred(), "could not create catalog source")
Eventually(func() error {
source, err = operatorClient.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{})
return err
}).Should(Succeed())

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

Expand All @@ -116,5 +154,36 @@ var _ = Describe("Installing bundles with new object types", func() {
return err
}).Should(Succeed(), "expected no error finding vpa object associated with csv")
})

AfterEach(func() {
By("Deleting the VPA CRD")
Eventually(func() error {
err := ctx.Ctx().Client().Delete(context.TODO(), &vpaCRD)
if k8serrors.IsNotFound(err) {
return nil
}
return err
}).Should(Succeed())
})
})
})

func crdReady(status *apiextensionsv1beta1.CustomResourceDefinitionStatus) bool {
if status == nil {
return false
}
established, namesAccepted := false, false
for _, cdt := range status.Conditions {
switch cdt.Type {
case apiextensionsv1beta1.Established:
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
established = true
}
case apiextensionsv1beta1.NamesAccepted:
if cdt.Status == apiextensionsv1beta1.ConditionTrue {
namesAccepted = true
}
}
}
return established && namesAccepted
}
64 changes: 64 additions & 0 deletions test/e2e/testdata/vpa/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: apiextensions.k8s.io/v1beta1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we'll want to add a make rule to x.mk to regenerate this.

kind: CustomResourceDefinition
metadata:
name: verticalpodautoscalers.autoscaling.k8s.io
annotations:
"api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/63797"
spec:
group: autoscaling.k8s.io
scope: Namespaced
names:
plural: verticalpodautoscalers
singular: verticalpodautoscaler
kind: VerticalPodAutoscaler
shortNames:
- vpa
version: v1beta1
versions:
- name: v1beta1
served: false
storage: false
- name: v1beta2
served: true
storage: true
- name: v1
served: true
storage: false
validation:
# openAPIV3Schema is the schema for validating custom objects.
openAPIV3Schema:
type: object
properties:
spec:
type: object
required: []
properties:
targetRef:
type: object
updatePolicy:
type: object
properties:
updateMode:
type: string
resourcePolicy:
type: object
properties:
containerPolicies:
type: array
items:
type: object
properties:
containerName:
type: string
mode:
type: string
enum: ["Auto", "Off"]
minAllowed:
type: object
maxAllowed:
type: object
controlledResources:
type: array
items:
type: string
enum: ["cpu", "memory"]
Loading