Skip to content

Commit 994fa1d

Browse files
committed
add e2e test
1 parent 8eae15a commit 994fa1d

File tree

4 files changed

+220
-11
lines changed

4 files changed

+220
-11
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: operators.coreos.com/v1
2+
kind: OLMConfig
3+
metadata:
4+
name: cluster
5+
spec:
6+
features:
7+
disableCopiedCSVs: false

pkg/controller/operators/openshift/suite_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
. "github.com/onsi/gomega"
1111
configv1 "github.com/openshift/api/config/v1"
1212
"github.com/operator-framework/api/crds"
13+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/client-go/rest"
1516
ctrl "sigs.k8s.io/controller-runtime"
@@ -54,8 +55,8 @@ var _ = BeforeSuite(func() {
5455
base := filepath.Join("..", "..", "..", "..", "vendor", "github.com", "openshift", "api", "config", "v1")
5556
testEnv = &envtest.Environment{
5657
ErrorIfCRDPathMissing: true,
57-
CRDs: []client.Object{
58-
crds.ClusterServiceVersion(),
58+
CRDs: []apiextensionsv1.CustomResourceDefinition{
59+
*crds.ClusterServiceVersion(),
5960
},
6061
CRDDirectoryPaths: []string{
6162
filepath.Join(base, "0000_00_cluster-version-operator_01_clusteroperator.crd.yaml"),

pkg/controller/operators/suite_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ var _ = BeforeSuite(func() {
8888
useExisting := false
8989
testEnv = &envtest.Environment{
9090
UseExistingCluster: &useExisting,
91-
CRDs: []client.Object{
92-
crds.CatalogSource(),
93-
crds.ClusterServiceVersion(),
94-
crds.InstallPlan(),
95-
crds.Subscription(),
96-
crds.OperatorGroup(),
97-
crds.Operator(),
98-
crds.OperatorCondition(),
91+
CRDs: []apiextensionsv1.CustomResourceDefinition{
92+
*crds.CatalogSource(),
93+
*crds.ClusterServiceVersion(),
94+
*crds.InstallPlan(),
95+
*crds.Subscription(),
96+
*crds.OperatorGroup(),
97+
*crds.Operator(),
98+
*crds.OperatorCondition(),
99+
*crds.OLMConfig(),
99100
},
100101
}
101102

test/e2e/csv_e2e_test.go

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ import (
1717
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
1818
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1919
k8serrors "k8s.io/apimachinery/pkg/api/errors"
20+
"k8s.io/apimachinery/pkg/api/meta"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/labels"
2123
k8slabels "k8s.io/apimachinery/pkg/labels"
2224
"k8s.io/apimachinery/pkg/runtime"
25+
"k8s.io/apimachinery/pkg/selection"
26+
apitypes "k8s.io/apimachinery/pkg/types"
2327
"k8s.io/apimachinery/pkg/util/intstr"
2428
"k8s.io/apimachinery/pkg/util/wait"
2529
"k8s.io/apimachinery/pkg/watch"
@@ -36,7 +40,7 @@ import (
3640
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
3741
)
3842

39-
var _ = Describe("ClusterServiceVersion", func() {
43+
var _ = FDescribe("ClusterServiceVersion", func() {
4044
HavePhase := func(goal operatorsv1alpha1.ClusterServiceVersionPhase) types.GomegaMatcher {
4145
return WithTransform(func(csv *operatorsv1alpha1.ClusterServiceVersion) operatorsv1alpha1.ClusterServiceVersionPhase {
4246
return csv.Status.Phase
@@ -4168,6 +4172,202 @@ var _ = Describe("ClusterServiceVersion", func() {
41684172

41694173
Expect(apiService2.Spec.CABundle).Should(Equal(apiService1.Spec.CABundle))
41704174
})
4175+
4176+
It("Disabling copied csvs", func() {
4177+
ns := &corev1.Namespace{
4178+
ObjectMeta: metav1.ObjectMeta{
4179+
Name: genName("csv-toggle-test-"),
4180+
},
4181+
}
4182+
4183+
// Create a new operator group for the new namespace
4184+
operatorGroup := v1.OperatorGroup{
4185+
ObjectMeta: metav1.ObjectMeta{
4186+
Name: genName("csv-toggle-test-"),
4187+
Namespace: ns.GetName(),
4188+
},
4189+
}
4190+
4191+
csv := v1alpha1.ClusterServiceVersion{
4192+
ObjectMeta: metav1.ObjectMeta{
4193+
Name: genName("csv-toggle-test-"),
4194+
Namespace: ns.GetName(),
4195+
},
4196+
Spec: v1alpha1.ClusterServiceVersionSpec{
4197+
InstallStrategy: newNginxInstallStrategy(genName("csv-toggle-test-"), nil, nil),
4198+
InstallModes: []v1alpha1.InstallMode{
4199+
{
4200+
Type: v1alpha1.InstallModeTypeAllNamespaces,
4201+
Supported: true,
4202+
},
4203+
},
4204+
},
4205+
}
4206+
Context("When an operator is installed in all namespace mode", func() {
4207+
Eventually(func() error {
4208+
if err := ctx.Ctx().Client().Create(context.TODO(), ns); err != nil && !k8serrors.IsAlreadyExists(err) {
4209+
ctx.Ctx().Logf("Unable to create ns: %v", err)
4210+
return err
4211+
}
4212+
4213+
if err := ctx.Ctx().Client().Create(context.TODO(), &operatorGroup); err != nil && !k8serrors.IsAlreadyExists(err) {
4214+
ctx.Ctx().Logf("Unable to create og: %v", err)
4215+
return err
4216+
}
4217+
4218+
if err := ctx.Ctx().Client().Create(context.TODO(), &csv); err != nil && !k8serrors.IsAlreadyExists(err) {
4219+
ctx.Ctx().Logf("Unable to create csv: %v", err)
4220+
return err
4221+
}
4222+
4223+
return nil
4224+
}).Should(Succeed())
4225+
})
4226+
4227+
Context("Copied CSVs should be generated in all other namespaces", func() {
4228+
Eventually(func() error {
4229+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})
4230+
if err != nil {
4231+
return err
4232+
}
4233+
4234+
var copiedCSVs v1alpha1.ClusterServiceVersionList
4235+
err = ctx.Ctx().Client().List(context.TODO(), &copiedCSVs, &client.ListOptions{
4236+
LabelSelector: labels.NewSelector().Add(*requirement),
4237+
})
4238+
if err != nil {
4239+
return err
4240+
}
4241+
4242+
var namespaces corev1.NamespaceList
4243+
if err := ctx.Ctx().Client().List(context.TODO(), &namespaces, &client.ListOptions{}); err != nil {
4244+
return err
4245+
}
4246+
4247+
if len(namespaces.Items) != len(copiedCSVs.Items)+1 {
4248+
return fmt.Errorf("CSVs are not copied to every namespace %v vs %v", len(namespaces.Items), (copiedCSVs.Items))
4249+
}
4250+
4251+
return nil
4252+
}).Should(Succeed())
4253+
})
4254+
4255+
When("Copied CSVs should be generated in all other namespaces", func() {
4256+
Eventually(func() error {
4257+
var olmConfig v1.OLMConfig
4258+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4259+
ctx.Ctx().Logf("Error getting olmConfig %v", err)
4260+
return err
4261+
}
4262+
4263+
olmConfig.Spec.Features.DisableCopiedCSVs = true
4264+
4265+
if err := ctx.Ctx().Client().Update(context.TODO(), &olmConfig); err != nil {
4266+
ctx.Ctx().Logf("Error setting olmConfig %v", err)
4267+
return err
4268+
}
4269+
4270+
return nil
4271+
}).Should(Succeed())
4272+
})
4273+
Context("Should delete existing copied csvs", func() {
4274+
Eventually(func() error {
4275+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})
4276+
if err != nil {
4277+
return err
4278+
}
4279+
4280+
var copiedCSVs v1alpha1.ClusterServiceVersionList
4281+
err = ctx.Ctx().Client().List(context.TODO(), &copiedCSVs, &client.ListOptions{
4282+
LabelSelector: labels.NewSelector().Add(*requirement),
4283+
})
4284+
if err != nil {
4285+
return err
4286+
}
4287+
4288+
if len(copiedCSVs.Items) != 0 {
4289+
return fmt.Errorf("Number of copied csvs should be 0")
4290+
}
4291+
return nil
4292+
}).Should(Succeed())
4293+
})
4294+
4295+
Context("Should updated the olmConfig status to reflect that the cluster is in the expected state", func() {
4296+
Eventually(func() error {
4297+
var olmConfig v1.OLMConfig
4298+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4299+
return err
4300+
}
4301+
4302+
if !meta.IsStatusConditionPresentAndEqual(olmConfig.Status.Conditions, "ready", metav1.ConditionTrue) {
4303+
return fmt.Errorf("Copied CSVs not ready not ready")
4304+
}
4305+
4306+
return nil
4307+
}).Should(Succeed())
4308+
})
4309+
When("Copied CSVs are toggled back on", func() {
4310+
Eventually(func() error {
4311+
4312+
var olmConfig v1.OLMConfig
4313+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4314+
return err
4315+
}
4316+
4317+
olmConfig.Spec.Features.DisableCopiedCSVs = false
4318+
4319+
if err := ctx.Ctx().Client().Update(context.TODO(), &olmConfig); err != nil {
4320+
return err
4321+
}
4322+
4323+
return nil
4324+
}).Should(Succeed())
4325+
})
4326+
4327+
Context("OLM should recreate existing copied csvs", func() {
4328+
Eventually(func() error {
4329+
// find copied csvs...
4330+
requirement, err := labels.NewRequirement(v1alpha1.CopiedLabelKey, selection.Equals, []string{csv.GetNamespace()})
4331+
if err != nil {
4332+
return err
4333+
}
4334+
4335+
var copiedCSVs v1alpha1.ClusterServiceVersionList
4336+
err = ctx.Ctx().Client().List(context.TODO(), &copiedCSVs, &client.ListOptions{
4337+
LabelSelector: labels.NewSelector().Add(*requirement),
4338+
})
4339+
if err != nil {
4340+
return err
4341+
}
4342+
4343+
var namespaces corev1.NamespaceList
4344+
if err := ctx.Ctx().Client().List(context.TODO(), &namespaces, &client.ListOptions{}); err != nil {
4345+
return err
4346+
}
4347+
4348+
if len(namespaces.Items) != len(copiedCSVs.Items)+1 {
4349+
return fmt.Errorf("CSVs are not copied to every namespace")
4350+
}
4351+
4352+
return nil
4353+
}).Should(Succeed())
4354+
})
4355+
4356+
Context("Should updated the olmConfig status to reflect that the cluster is in the expected state", func() {
4357+
Eventually(func() error {
4358+
var olmConfig v1.OLMConfig
4359+
if err := ctx.Ctx().Client().Get(context.TODO(), apitypes.NamespacedName{Name: "cluster"}, &olmConfig); err != nil {
4360+
return err
4361+
}
4362+
4363+
if !meta.IsStatusConditionPresentAndEqual(olmConfig.Status.Conditions, "ready", metav1.ConditionTrue) {
4364+
return fmt.Errorf("Copied CSVs not ready not ready")
4365+
}
4366+
4367+
return nil
4368+
}).Should(Succeed())
4369+
})
4370+
})
41714371
})
41724372

41734373
var singleInstance = int32(1)

0 commit comments

Comments
 (0)