Skip to content

Commit

Permalink
Handle OCP3 in e2e kustomize install tests
Browse files Browse the repository at this point in the history
* OCP3 has obsolete CRD API, which is handled in the golang binary but
  not in the kustomize install

* Adds plumbing to the kustomize install to error out gracefully if the
  CRD API is the obsolete version

* Adds env var to e2e tests to skip tests if cluster target is OCP3

* Modifies openshift github workflow to move the test-quarkus-native
  to executing as cluster-admin
  • Loading branch information
phantomjinx authored and squakez committed Jul 13, 2022
1 parent 37cba2f commit c3b9c9b
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/actions/kamel-config-cluster-ocp3/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ runs:
if: ${{ env.CLUSTER_OCP3_CONFIGURED != 'true' }}
run: |
echo "::set-output name=cluster-image-registry-pull-host::"
echo "::set-output name=cluster-image-registry-pull-host::"
echo "::set-output name=cluster-image-registry-push-host::"
echo "::set-output name=cluster-image-registry-insecure::$(echo true)"
echo "::set-output name=cluster-has-olm::$(echo false)"
echo "::set-output name=cluster-image-namespace::$(echo apache)"
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/openshift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ on:
- 'NOTICE'
workflow_dispatch:
inputs:
pre-built-kamel-image:
description: 'Kamel image url for skipping building of kamel stages. Used for debugging'
required: false
skip-problematic:
description: 'Whether tests marked as problematic should be skipped - false by default (sets CAMEL_K_TEST_SKIP_PROBLEMATIC)'
required: false
default: false
test-filters:
description: |
List of comma-separated key/value pairs to filter the tests in this test suite:
TEST_INTEGRATION_COMMON_RUN, TEST_INTEGRATION_COMMON_BUILD_RUN, TEST_INTEGRATION_COMMON_CONFIG_RUN,
TEST_INTEGRATION_COMMON_LANG_RUN, TEST_INTEGRATION_COMMON_TRAITS_RUN
TEST_SERVICE_RUN, TEST_REGISTRY_MAVEN_WAGON_RUN
eg. TEST_INTEGRATION_COMMON_RUN=TestBasic will only run tests prefixed with 'TestBasic'
required: false

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
Expand Down Expand Up @@ -92,9 +107,10 @@ jobs:
- name: Run IT 1
run: |
# Then run integration tests
export CAMEL_K_CLUSTER_OCP3=true
make test-integration
make test-builder
make test-quarkus-native
- id: change-context
name: Change the Kamel Cluster Context to Admin
Expand All @@ -105,4 +121,7 @@ jobs:
- name: Run IT 2
run: |
# Then run integration tests
export CAMEL_K_CLUSTER_OCP3=true
make test-quarkus-native
make test-install
24 changes: 22 additions & 2 deletions e2e/namespace/install/kustomize/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,28 @@ func ExecMake(t *testing.T, command *exec.Cmd) {
session.Wait()
Eventually(session).Should(gexec.Exit(0))
assert.Nil(t, err)
assert.NotContains(t, cmdErr.String(), "Error")
assert.NotContains(t, cmdErr.String(), "ERROR")
assert.NotContains(t, strings.ToUpper(cmdErr.String()), "ERROR")
}

//
// Expect a make error with an exit code of 1
//
func ExecMakeError(t *testing.T, command *exec.Cmd) {
var cmdOut strings.Builder
var cmdErr strings.Builder

defer func() {
if t.Failed() {
t.Logf("Output from make command:\n%s\n", cmdOut.String())
t.Logf("Error from make command:\n%s\n", cmdErr.String())
}
}()

session, err := gexec.Start(command, &cmdOut, &cmdErr)
session.Wait()
Eventually(session).ShouldNot(gexec.Exit(0))
assert.Nil(t, err)
assert.Contains(t, strings.ToUpper(cmdErr.String()), "ERROR")
}

// Clean up the cluster ready for the next set of tests
Expand Down
22 changes: 22 additions & 0 deletions e2e/namespace/install/kustomize/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ import (
. "github.com/onsi/gomega"
)

func TestOcp3CrdError(t *testing.T) {
if os.Getenv("CAMEL_K_CLUSTER_OCP3") != "true" {
t.Skip("INFO: Skipping test as only applicable to OCP3")
}

WithNewTestNamespace(t, func(ns string) {
ExecMakeError(t, Make("setup-cluster", fmt.Sprintf("NAMESPACE=%s", ns)))
})
}

func TestBasicOperator(t *testing.T) {
if os.Getenv("CAMEL_K_CLUSTER_OCP3") == "true" {
t.Skip("INFO: Skipping test as not supported on OCP3")
}

os.Setenv("MAKE_DIR", "../../../../install")

// Ensure no CRDs are already installed
Expand All @@ -50,6 +64,10 @@ func TestBasicOperator(t *testing.T) {
}

func TestAlternativeImageOperator(t *testing.T) {
if os.Getenv("CAMEL_K_CLUSTER_OCP3") == "true" {
t.Skip("INFO: Skipping test as not supported on OCP3")
}

os.Setenv("MAKE_DIR", "../../../../install")

// Ensure no CRDs are already installed
Expand All @@ -72,6 +90,10 @@ func TestAlternativeImageOperator(t *testing.T) {
}

func TestGlobalOperator(t *testing.T) {
if os.Getenv("CAMEL_K_CLUSTER_OCP3") == "true" {
t.Skip("INFO: Skipping test as not supported on OCP3")
}

os.Setenv("MAKE_DIR", "../../../../install")

// Ensure no CRDs are already installed
Expand Down
8 changes: 8 additions & 0 deletions e2e/namespace/install/kustomize/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (
)

func TestBasicSetup(t *testing.T) {
if os.Getenv("CAMEL_K_CLUSTER_OCP3") == "true" {
t.Skip("INFO: Skipping test as not supported on OCP3")
}

os.Setenv("MAKE_DIR", "../../../../install")

// Ensure no CRDs are already installed
Expand Down Expand Up @@ -61,6 +65,10 @@ func TestBasicSetup(t *testing.T) {
}

func TestGlobalSetup(t *testing.T) {
if os.Getenv("CAMEL_K_CLUSTER_OCP3") == "true" {
t.Skip("INFO: Skipping test as not supported on OCP3")
}

os.Setenv("MAKE_DIR", "../../../../install")

// Ensure no CRDs are already installed
Expand Down
14 changes: 12 additions & 2 deletions install/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ endif
check-admin: kubectl
@output=$$(kubectl get crd 2>&1) || (echo "****" && echo "**** ERROR: Cannot continue as user is not a Cluster-Admin ****" && echo "****"; exit 1)

crd-api-support: kubectl
ifndef CRD_SUPPORT
CRD_SUPPORT=$(shell script/check_crd_api_support.sh)
endif

check-crd-api-support: crd-api-support
ifneq ($(CRD_SUPPORT),OK)
$(error *** CRD API FAILURE: $(CRD_SUPPORT) ****)
endif

#
# Setup the cluster installation by installing crds and cluster roles.
#
Expand All @@ -168,7 +178,7 @@ check-admin: kubectl
# PLATFORM: Override the discovered platform, if required
# DRY_RUN: true - Prints the resources to be applied instead of applying them
#
setup-cluster: check-admin have-platform kustomize kubectl
setup-cluster: check-admin check-crd-api-support have-platform kustomize kubectl
# Set the namespace in the setup-cluster kustomization yaml
@$(call set-kustomize-namespace,$@)
ifeq ($(PLATFORM), openshift)
Expand Down Expand Up @@ -270,7 +280,7 @@ endif
# LOGGING_LEVEL: Set the level of logging [info|debug]
# DRY_RUN: Prints the resources to be applied instead of applying them
#
operator: check-admin have-platform kustomize kubectl .operator-port-patch .operator-log-level-patch
operator: check-admin have-platform check-crd-api-support kustomize kubectl .operator-port-patch .operator-log-level-patch
ifeq ($(MONITORING), true)
@$(MAKE) -s .operator-can-monitor
@$(call add-remove-operator-monitoring,$@,add)
Expand Down
1 change: 1 addition & 0 deletions install/script/check_crd_api_support.sh
62 changes: 62 additions & 0 deletions script/check_crd_api_support.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

is_binary_available() {

client="${1}"

# Check path first if it already exists
set +e
which "${client}" &>/dev/null
if [ $? -eq 0 ]; then
set -e
echo "OK"
return
fi

set -e

# Error, no oc found
echo "ERROR: No '${client}' binary found in path."
}

location=$(dirname $0)
rootdir=$location/../

cd $rootdir

client="oc"
hasclient=$(is_binary_available "${client}")
if [ "${hasclient}" != "OK" ]; then
client="kubectl"
hasclient=$(is_binary_available "${client}")
if [ "${hasclient}" != "OK" ]; then
echo "ERROR: No kube client installed."
exit 1
fi
fi

crd_version=$("${client}" explain customresourcedefinitions | grep VERSION | awk '{print $2}')
api="apiextensions.k8s.io"

if [ "${crd_version}" == "${api}/v1beta1" ]; then
echo "ERROR: CRD API version is too old to install camel-k in this way. Try using the client CLI app, which is able to convert the APIs."
elif [ "${crd_version}" != "${api}/v1" ]; then
echo "ERROR: CRD API version '${crd_version}' is not supported."
else
echo "OK"
fi

0 comments on commit c3b9c9b

Please sign in to comment.