Skip to content
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

Move operator condition e2e to one namespace per spec #2719

Merged
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
58 changes: 34 additions & 24 deletions test/e2e/operator_condition_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"

"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
meta "k8s.io/apimachinery/pkg/api/meta"
Expand All @@ -18,8 +19,17 @@ import (
)

var _ = Describe("Operator Condition", func() {

var (
generatedNamespace corev1.Namespace
)

BeforeEach(func() {
generatedNamespace = SetupGeneratedTestNamespace(genName("operator-conditions-e2e-"))
})

AfterEach(func() {
TearDown(testNamespace)
TeardownNamespace(generatedNamespace.GetName())
})

It("OperatorCondition Upgradeable type and overrides", func() {
Expand All @@ -44,9 +54,9 @@ var _ = Describe("Operator Condition", func() {
strategyB := newNginxInstallStrategy(pkgBStable, nil, nil)
strategyD := newNginxInstallStrategy(pkgDStable, nil, nil)
crd := newCRD(genName(pkgA))
csvA := newCSV(pkgAStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, &strategyA)
csvB := newCSV(pkgBStable, testNamespace, pkgAStable, semver.MustParse("0.2.0"), []apiextensions.CustomResourceDefinition{crd}, nil, &strategyB)
csvD := newCSV(pkgDStable, testNamespace, pkgBStable, semver.MustParse("0.3.0"), []apiextensions.CustomResourceDefinition{crd}, nil, &strategyD)
csvA := newCSV(pkgAStable, generatedNamespace.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, &strategyA)
csvB := newCSV(pkgBStable, generatedNamespace.GetName(), pkgAStable, semver.MustParse("0.2.0"), []apiextensions.CustomResourceDefinition{crd}, nil, &strategyB)
csvD := newCSV(pkgDStable, generatedNamespace.GetName(), pkgBStable, semver.MustParse("0.3.0"), []apiextensions.CustomResourceDefinition{crd}, nil, &strategyD)

// Create the initial catalogsources
manifests := []registry.PackageManifest{
Expand All @@ -60,15 +70,15 @@ var _ = Describe("Operator Condition", func() {
}

catalog := genName("catalog-")
_, cleanupCatalogSource := createInternalCatalogSource(c, crc, catalog, testNamespace, manifests, []apiextensions.CustomResourceDefinition{crd}, []operatorsv1alpha1.ClusterServiceVersion{csvA})
_, cleanupCatalogSource := createInternalCatalogSource(c, crc, catalog, generatedNamespace.GetName(), manifests, []apiextensions.CustomResourceDefinition{crd}, []operatorsv1alpha1.ClusterServiceVersion{csvA})
defer cleanupCatalogSource()
_, err := fetchCatalogSourceOnStatus(crc, catalog, testNamespace, catalogSourceRegistryPodSynced)
_, err := fetchCatalogSourceOnStatus(crc, catalog, generatedNamespace.GetName(), catalogSourceRegistryPodSynced)
subName := genName("sub-")
cleanupSub := createSubscriptionForCatalog(crc, testNamespace, subName, catalog, pkgA, stableChannel, pkgAStable, operatorsv1alpha1.ApprovalAutomatic)
cleanupSub := createSubscriptionForCatalog(crc, generatedNamespace.GetName(), subName, catalog, pkgA, stableChannel, pkgAStable, operatorsv1alpha1.ApprovalAutomatic)
defer cleanupSub()

// Await csvA's success
_, err = awaitCSV(crc, testNamespace, csvA.GetName(), csvSucceededChecker)
_, err = awaitCSV(crc, generatedNamespace.GetName(), csvA.GetName(), csvSucceededChecker)
require.NoError(GinkgoT(), err)

// Get the OperatorCondition for csvA and report that it is not upgradeable
Expand All @@ -83,14 +93,14 @@ var _ = Describe("Operator Condition", func() {

var currentGen int64
Eventually(func() error {
cond, err := crc.OperatorsV2().OperatorConditions(testNamespace).Get(context.TODO(), csvA.GetName(), metav1.GetOptions{})
cond, err := crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).Get(context.TODO(), csvA.GetName(), metav1.GetOptions{})
if err != nil {
return err
}
currentGen = cond.ObjectMeta.GetGeneration()
upgradeableFalseCondition.ObservedGeneration = currentGen
meta.SetStatusCondition(&cond.Spec.Conditions, upgradeableFalseCondition)
_, err = crc.OperatorsV2().OperatorConditions(testNamespace).Update(context.TODO(), cond, metav1.UpdateOptions{})
_, err = crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).Update(context.TODO(), cond, metav1.UpdateOptions{})
return err
}, pollInterval, pollDuration).Should(Succeed())

Expand All @@ -104,14 +114,14 @@ var _ = Describe("Operator Condition", func() {
DefaultChannelName: stableChannel,
},
}
updateInternalCatalog(GinkgoT(), c, crc, catalog, testNamespace, []apiextensions.CustomResourceDefinition{crd}, []operatorsv1alpha1.ClusterServiceVersion{csvA, csvB}, manifests)
updateInternalCatalog(GinkgoT(), c, crc, catalog, generatedNamespace.GetName(), []apiextensions.CustomResourceDefinition{crd}, []operatorsv1alpha1.ClusterServiceVersion{csvA, csvB}, manifests)

// Attempt to get the catalog source before creating install plan(s)
_, err = fetchCatalogSourceOnStatus(crc, catalog, testNamespace, catalogSourceRegistryPodSynced)
_, err = fetchCatalogSourceOnStatus(crc, catalog, generatedNamespace.GetName(), catalogSourceRegistryPodSynced)
require.NoError(GinkgoT(), err)

// csvB will be in Pending phase due to csvA reports Upgradeable=False condition
fetchedCSV, err := fetchCSV(crc, csvB.GetName(), testNamespace, buildCSVReasonChecker(operatorsv1alpha1.CSVReasonOperatorConditionNotUpgradeable))
fetchedCSV, err := fetchCSV(crc, csvB.GetName(), generatedNamespace.GetName(), buildCSVReasonChecker(operatorsv1alpha1.CSVReasonOperatorConditionNotUpgradeable))
require.NoError(GinkgoT(), err)
require.Equal(GinkgoT(), fetchedCSV.Status.Phase, operatorsv1alpha1.CSVPhasePending)

Expand All @@ -124,32 +134,32 @@ var _ = Describe("Operator Condition", func() {
LastTransitionTime: metav1.Now(),
}
Eventually(func() error {
cond, err = crc.OperatorsV2().OperatorConditions(testNamespace).Get(context.TODO(), csvA.GetName(), metav1.GetOptions{})
cond, err = crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).Get(context.TODO(), csvA.GetName(), metav1.GetOptions{})
if err != nil || currentGen == cond.ObjectMeta.GetGeneration() {
return err
}
currentGen = cond.ObjectMeta.GetGeneration()
upgradeableTrueCondition.ObservedGeneration = cond.ObjectMeta.GetGeneration()
meta.SetStatusCondition(&cond.Spec.Conditions, upgradeableTrueCondition)
_, err = crc.OperatorsV2().OperatorConditions(testNamespace).Update(context.TODO(), cond, metav1.UpdateOptions{})
_, err = crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).Update(context.TODO(), cond, metav1.UpdateOptions{})
return err
}, pollInterval, pollDuration).Should(Succeed())

// Await csvB's success
_, err = awaitCSV(crc, testNamespace, csvB.GetName(), csvSucceededChecker)
_, err = awaitCSV(crc, generatedNamespace.GetName(), csvB.GetName(), csvSucceededChecker)
require.NoError(GinkgoT(), err)

// Get the OperatorCondition for csvB and purposedly change ObservedGeneration
// to cause mismatch generation situation
Eventually(func() error {
cond, err = crc.OperatorsV2().OperatorConditions(testNamespace).Get(context.TODO(), csvB.GetName(), metav1.GetOptions{})
cond, err = crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).Get(context.TODO(), csvB.GetName(), metav1.GetOptions{})
if err != nil || currentGen == cond.ObjectMeta.GetGeneration() {
return err
}
currentGen = cond.ObjectMeta.GetGeneration()
upgradeableTrueCondition.ObservedGeneration = currentGen + 1
meta.SetStatusCondition(&cond.Status.Conditions, upgradeableTrueCondition)
_, err = crc.OperatorsV2().OperatorConditions(testNamespace).UpdateStatus(context.TODO(), cond, metav1.UpdateOptions{})
_, err = crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).UpdateStatus(context.TODO(), cond, metav1.UpdateOptions{})
return err
}, pollInterval, pollDuration).Should(Succeed())

Expand All @@ -164,31 +174,31 @@ var _ = Describe("Operator Condition", func() {
},
}

updateInternalCatalog(GinkgoT(), c, crc, catalog, testNamespace, []apiextensions.CustomResourceDefinition{crd}, []operatorsv1alpha1.ClusterServiceVersion{csvA, csvB, csvD}, manifests)
updateInternalCatalog(GinkgoT(), c, crc, catalog, generatedNamespace.GetName(), []apiextensions.CustomResourceDefinition{crd}, []operatorsv1alpha1.ClusterServiceVersion{csvA, csvB, csvD}, manifests)
// Attempt to get the catalog source before creating install plan(s)
_, err = fetchCatalogSourceOnStatus(crc, catalog, testNamespace, catalogSourceRegistryPodSynced)
_, err = fetchCatalogSourceOnStatus(crc, catalog, generatedNamespace.GetName(), catalogSourceRegistryPodSynced)
require.NoError(GinkgoT(), err)

// CSVD will be in Pending status due to overrides in csvB's condition
fetchedCSV, err = fetchCSV(crc, csvD.GetName(), testNamespace, buildCSVReasonChecker(operatorsv1alpha1.CSVReasonOperatorConditionNotUpgradeable))
fetchedCSV, err = fetchCSV(crc, csvD.GetName(), generatedNamespace.GetName(), buildCSVReasonChecker(operatorsv1alpha1.CSVReasonOperatorConditionNotUpgradeable))
require.NoError(GinkgoT(), err)
require.Equal(GinkgoT(), fetchedCSV.Status.Phase, operatorsv1alpha1.CSVPhasePending)

// Get the OperatorCondition for csvB and override the upgradeable false condition
Eventually(func() error {
cond, err = crc.OperatorsV2().OperatorConditions(testNamespace).Get(context.TODO(), csvB.GetName(), metav1.GetOptions{})
cond, err = crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).Get(context.TODO(), csvB.GetName(), metav1.GetOptions{})
if err != nil {
return err
}
meta.SetStatusCondition(&cond.Spec.Overrides, upgradeableTrueCondition)
// Update the condition
_, err = crc.OperatorsV2().OperatorConditions(testNamespace).Update(context.TODO(), cond, metav1.UpdateOptions{})
_, err = crc.OperatorsV2().OperatorConditions(generatedNamespace.GetName()).Update(context.TODO(), cond, metav1.UpdateOptions{})
return err
}, pollInterval, pollDuration).Should(Succeed())
require.NoError(GinkgoT(), err)

require.NoError(GinkgoT(), err)
_, err = awaitCSV(crc, testNamespace, csvD.GetName(), csvSucceededChecker)
_, err = awaitCSV(crc, generatedNamespace.GetName(), csvD.GetName(), csvSucceededChecker)
require.NoError(GinkgoT(), err)
})
})