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

fix(e2e): Fix OLM upgrade e2e test #2281

Merged
merged 4 commits into from
May 11, 2021
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
12 changes: 5 additions & 7 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@ jobs:
# replace image
$(cd config/manifests && kustomize edit set image "docker.io/apache/camel-k=${{ env.LOCAL_IMAGE }}")


# CSV the patch to force OLM upgrade
export RELEASE_VERSION=$(make get-version | grep -Po "\d.\d.\d")
# Patch CSV with the 'replaces' field to define the upgrade graph
cat <<EOF > config/manifests/patch.yml
apiVersion: operators.coreos.com/v1alpha1
kind: ClusterServiceVersion
metadata:
namespace: placeholder
name: camel-k.v$(make get-last-released-version)
annotations:
olm.skipRange: ">=1.0.0 <${RELEASE_VERSION}"
name: camel-k.v$(make get-version | grep -Po "\d.\d.\d")
spec:
replaces: camel-k-operator.v$(make get-last-released-version)
EOF

echo "Patching CSV with"
Expand All @@ -142,7 +140,7 @@ jobs:
run: |
export LOCAL_IIB=$KIND_REGISTRY/apache/camel-k-iib:$(make get-version)
echo "LOCAL_IIB=${LOCAL_IIB}" >> $GITHUB_ENV
opm index add --bundles ${{ env.LOCAL_IMAGE_BUNDLE }} -u docker --from-index quay.io/operatorhubio/catalog:latest --tag ${LOCAL_IIB} --skip-tls
opm index add --bundles ${{ env.LOCAL_IMAGE_BUNDLE }} -c docker --from-index quay.io/operatorhubio/catalog:latest --tag ${LOCAL_IIB} --skip-tls
docker push ${LOCAL_IIB}
- name: Run IT
run: |
Expand Down
61 changes: 0 additions & 61 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ import (
"encoding/json"
"errors"
"fmt"
v1alpha12 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"io"
"io/ioutil"
"os"
"os/exec"
"strings"
"testing"
"time"
"unsafe"

"github.com/google/uuid"
"github.com/onsi/gomega"
Expand Down Expand Up @@ -673,65 +671,6 @@ func KnativeService(ns string, name string) func() *servingv1.Service {
}
}

func CKClusterServiceVersion(conditions func(v1alpha12.ClusterServiceVersion) bool ,ns string) func() *v1alpha12.ClusterServiceVersion {
return func() *v1alpha12.ClusterServiceVersion {
lst := v1alpha12.ClusterServiceVersionList{}
if err := TestClient().List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil {
panic(err)
}
for _, s := range lst.Items {
if strings.Contains(s.Name, "camel-k") && conditions(s){
return &s
}
}
return nil
}
}

func CKClusterServiceVersionPhase(conditions func(v1alpha12.ClusterServiceVersion) bool, ns string) func() v1alpha12.ClusterServiceVersionPhase {
return func() v1alpha12.ClusterServiceVersionPhase {
if csv := CKClusterServiceVersion(conditions, ns)(); csv != nil && unsafe.Sizeof(csv.Status) > 0 {
return csv.Status.Phase
}
return ""
}
}

func CatalogSource(name string, ns string) func() *v1alpha12.CatalogSource {
return func() *v1alpha12.CatalogSource {
answer := v1alpha12.CatalogSource{
TypeMeta: metav1.TypeMeta{
Kind: "CatalogSource",
APIVersion: v1alpha1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
},
}
key := ctrl.ObjectKey{
Namespace: ns,
Name: name,
}
if err := TestClient().Get(TestContext, key, &answer); err != nil && k8serrors.IsNotFound(err) {
return nil
} else if err != nil {
log.Errorf(err, "Error while retrieving CatalogSource %s", name)
return nil
}
return &answer
}
}

func CatalogSourcePhase(name string, ns string) func() string {
return func() string {
if source := CatalogSource(name, ns)(); source != nil && source.Status.GRPCConnectionState != nil {
return CatalogSource(name, ns)().Status.GRPCConnectionState.LastObservedState
}
return ""
}
}

func Deployment(ns string, name string) func() *appsv1.Deployment {
return func() *appsv1.Deployment {
answer := appsv1.Deployment{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ import (

. "github.com/onsi/gomega"

v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"

. "github.com/apache/camel-k/e2e/support"
camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util/defaults"
)

func TestOperatorUpgrade(t *testing.T) {
// Clean all cluster-wide resources that could corrupt the test run
Expect(Kamel("uninstall", "--all", "--olm=false").Execute()).To(Succeed())

WithNewTestNamespace(t, func(ns string) {
version, ok := os.LookupEnv("KAMEL_K_TEST_RELEASE_VERSION")
Expect(ok).To(BeTrue())
Expand All @@ -49,14 +46,14 @@ func TestOperatorUpgrade(t *testing.T) {
kamel, ok := os.LookupEnv("RELEASED_KAMEL_BIN")
Expect(ok).To(BeTrue())

//set KAMEL_BIN only for this test - don't override the ENV variable for all tests
// Set KAMEL_BIN only for this test - don't override the ENV variable for all tests
Expect(os.Setenv("KAMEL_BIN", kamel)).To(Succeed())

Expect(Kamel("install", "--olm=false", "--cluster-setup", "--force").Execute()).To(Succeed())
Expect(Kamel("install", "--olm=false", "-n", ns).Execute()).To(Succeed())

// Check the operator pod is running
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning))

// Refresh the test client to account for the newly installed CRDs
SyncClient()
Expand All @@ -67,11 +64,11 @@ func TestOperatorUpgrade(t *testing.T) {
// Run the Integration
name := "yaml"
Expect(Kamel("run", "-n", ns, "files/yaml.yaml").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
// Check the Integration version
Eventually(IntegrationVersion(ns, "yaml")).Should(Equal(version))
kit := IntegrationKit(ns, "yaml")()
Eventually(IntegrationVersion(ns, name)).Should(Equal(version))
kit := IntegrationKit(ns, name)()

// Clear the KAMEL_BIN environment variable so that the current version is used from now on
Expect(os.Setenv("KAMEL_BIN", "")).To(Succeed())
Expand All @@ -84,27 +81,27 @@ func TestOperatorUpgrade(t *testing.T) {
// Check the operator image is the current built one
Eventually(OperatorImage(ns)).Should(Equal(image))
// Check the operator pod is running
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
// Check the IntegrationPlatform has been reconciled
Eventually(PlatformVersion(ns), TestTimeoutMedium).Should(Equal(defaults.Version))

// Check the Integration hasn't been upgraded
Consistently(IntegrationVersion(ns, "yaml"), 3*time.Second).Should(Equal(version))
Consistently(IntegrationVersion(ns, name), 3*time.Second).Should(Equal(version))

// Force the Integration upgrade
Expect(Kamel("rebuild", "yaml", "-n", ns).Execute()).To(Succeed())
Expect(Kamel("rebuild", name, "-n", ns).Execute()).To(Succeed())

// Check the Integration version change
Eventually(IntegrationVersion(ns, "yaml")).Should(Equal(defaults.Version))
Eventually(IntegrationVersion(ns, name)).Should(Equal(defaults.Version))
// Check the previous kit is not garbage collected
Eventually(KitsWithVersion(ns, version)).Should(Equal(1))
// Check a new kit is created with the current version
Eventually(KitsWithVersion(ns, defaults.Version)).Should(Equal(1))
// Check the Integration uses the new kit
Eventually(IntegrationKit(ns, "yaml"), TestTimeoutMedium).ShouldNot(Equal(kit))
Eventually(IntegrationKit(ns, name), TestTimeoutMedium).ShouldNot(Equal(kit))
// Check the Integration runs correctly
Eventually(IntegrationPodPhase(ns, "yaml"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, name, camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))

// Clean up
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
Expand Down
Loading