Skip to content

Commit

Permalink
Merge branch 'master' into move_ci_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoaresd authored Nov 14, 2024
2 parents d82b92d + 5af42ca commit 05850d1
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
9 changes: 8 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ NOTE: you can disable SSL/TLS certificate verification in tests setting the `DIS

NOTE: you can specify a regular expression to selectively run particular test cases by setting the `TESTS_RUN_FILTER_REGEXP` variable. eg.: `make test-e2e TESTS_RUN_FILTER_REGEXP="TestSetupMigration"`. For more information see the https://pkg.go.dev/cmd/go#hdr-Testing_flags[go test -run documentation].

NOTE: you should not override `SECOND_MEMBER_MODE` in test-e2e, since the e2e tests require a second member operator.

=== Running/Debugging e2e tests from your IDE

In order to run/debug tests from your IDE you'll need to export some required env variables, those will be used by the test framework to interact with the operator namespaces and the other toolchain resources in you cluster.
Following snippet of code should be TEMPORARILY added at the top of the test you want to run/debug from your IDE:

```
os.Setenv("MEMBER_NS","toolchain-member-18161051")
// `SECOND_MEMBER_MODE` should be set to true, since the e2e tests require a second member operator.
os.Setenv("SECOND_MEMBER_MODE","true")
os.Setenv("MEMBER_NS_2","toolchain-member2-18161051")
os.Setenv("HOST_NS","toolchain-host-18161051")
os.Setenv("REGISTRATION_SERVICE_NS","toolchain-host-18161051")
Expand All @@ -95,6 +99,7 @@ import (

func TestCreateSpaceRequest(t *testing.T) {
os.Setenv("MEMBER_NS","toolchain-member-18161051")
os.Setenv("SECOND_MEMBER_MODE","true")
os.Setenv("MEMBER_NS_2","toolchain-member2-18161051")
os.Setenv("HOST_NS","toolchain-host-18161051")
os.Setenv("REGISTRATION_SERVICE_NS","toolchain-host-18161051")
Expand Down Expand Up @@ -148,10 +153,12 @@ All e2e resources (host operator, member operator, registration-service, CRDs, e
* `make dev-deploy-e2e` - deploys the same resources as `make test-e2e` but doesn't run tests.
By default these targets deploy resources to `toolchain-host-operator` and `toolchain-member-operator` namespaces.
NOTE: By default these targets deploy resources to `toolchain-host-operator` and `toolchain-member-operator` namespaces.
NOTE: If running in CodeReady Containers `eval $(crc oc-env)` is required.
NOTE: By default, `SECOND_MEMBER_MODE` is set to false.
== How to Test Mailgun/Twilio Notifications in a Dev Environment
* Get a cluster and setup the following env vars
** `export QUAY_NAMESPACE=<your-quay-namespace>`
Expand Down
3 changes: 2 additions & 1 deletion deploy/host-operator/e2e-tests/toolchainconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ spec:
segmentWriteKey: 'test devspaces segment write key'
segmentWriteKey: 'test sandbox segment write key'
environment: 'e2e-tests'
replicas: 2
# same number that is set in https://github.com/codeready-toolchain/host-operator/blob/master/deploy/registration-service/registration-service.yaml#L272-L273
replicas: 3
verification:
enabled: true
excludedEmailDomains: 'redhat.com,acme.com'
Expand Down
2 changes: 1 addition & 1 deletion make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ execute-tests:
@echo "Status of ToolchainStatus"
-oc get ToolchainStatus -n ${HOST_NS} -o yaml
@echo "Starting test $(shell date)"
MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} HOST_NS=${HOST_NS} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -v -timeout=90m -failfast || \
MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} HOST_NS=${HOST_NS} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} SECOND_MEMBER_MODE=${SECOND_MEMBER_MODE} go test ${TESTS_TO_EXECUTE} -run ${TESTS_RUN_FILTER_REGEXP} -p 1 -v -timeout=90m -failfast || \
($(MAKE) print-logs HOST_NS=${HOST_NS} MEMBER_NS=${MEMBER_NS} MEMBER_NS_2=${MEMBER_NS_2} REGISTRATION_SERVICE_NS=${REGISTRATION_SERVICE_NS} && exit 1)

.PHONY: print-logs
Expand Down
34 changes: 34 additions & 0 deletions test/e2e/parallel/toolchainconfig_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package parallel

import (
"context"
"testing"

testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"
"github.com/codeready-toolchain/toolchain-e2e/testsupport"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
)

func TestToolchainConfig(t *testing.T) {
awaitilities := testsupport.WaitForDeployments(t)
hostAwait := awaitilities.Host()

t.Run("update replica count for registration-service", func(t *testing.T) {
// get current replica count in registration-service
registrationServiceName := "registration-service"
rs := &appsv1.Deployment{}
err := hostAwait.Client.Get(context.TODO(), types.NamespacedName{Namespace: hostAwait.Namespace, Name: registrationServiceName}, rs)
require.NoError(t, err)
currentNrReplicas := *rs.Spec.Replicas

// update replica count in registration-service
newNrReplicas := currentNrReplicas + 1
hostAwait.UpdateToolchainConfig(t, testconfig.RegistrationService().Replicas(newNrReplicas))
hostAwait.WaitForDeploymentToGetReady(t, registrationServiceName, int(newNrReplicas))

// no need to revert to original replica count
// UpdateToolchainConfig returns the resource back to the original value/state at the end of the test
})
}
36 changes: 27 additions & 9 deletions testsupport/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func waitForOperators(t *testing.T) {
registrationServiceNs := os.Getenv(wait.RegistrationServiceVar)
t.Logf("Host Operator namespace: %s", hostNs)
t.Logf("Member1 Operator namespace: %s", memberNs)
t.Logf("Member2 Operator namespace: %s", memberNs2)
if IsSecondMemberMode(t) {
t.Logf("Member2 Operator namespace: %s", memberNs2)
}
t.Logf("Registration Service namespace: %s", registrationServiceNs)

apiConfig, err := clientcmd.NewDefaultClientConfigLoadingRules().Load()
Expand All @@ -82,7 +84,7 @@ func waitForOperators(t *testing.T) {
initHostAwait.WaitForDeploymentToGetReady(t, "host-operator-controller-manager", 1)

// wait for registration service to be ready
initHostAwait.WaitForDeploymentToGetReady(t, "registration-service", 2)
initHostAwait.WaitForDeploymentToGetReady(t, "registration-service", 3)

// set registration service values
registrationServiceRoute, err := initHostAwait.WaitForRouteToBeAvailable(t, registrationServiceNs, "registration-service", "/")
Expand All @@ -97,14 +99,15 @@ func waitForOperators(t *testing.T) {
// wait for member operators to be ready
initMemberAwait = getMemberAwaitility(t, initHostAwait, kubeconfig, memberNs)

initMember2Await = getMemberAwaitility(t, initHostAwait, kubeconfig, memberNs2)

_, err = initMemberAwait.WaitForToolchainClusterWithCondition(t, initHostAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)

_, err = initMember2Await.WaitForToolchainClusterWithCondition(t, initHostAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
if IsSecondMemberMode(t) {
initMember2Await = getMemberAwaitility(t, initHostAwait, kubeconfig, memberNs2)

_, err = initMember2Await.WaitForToolchainClusterWithCondition(t, initHostAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
}
t.Log("all operators are ready and in running state")
}

Expand Down Expand Up @@ -209,13 +212,17 @@ func WaitForDeployments(t *testing.T) wait.Awaitilities {
// Also verify the autoscaling buffer in both members
webhookImage := initMemberAwait.GetContainerEnv(t, "MEMBER_OPERATOR_WEBHOOK_IMAGE")
require.NotEmpty(t, webhookImage, "The value of the env var MEMBER_OPERATOR_WEBHOOK_IMAGE wasn't found in the deployment of the member operator.")
err = initMember2Await.WaitUntilWebhookDeleted(t) // webhook on member2 should be deleted
require.NoError(t, err)
if IsSecondMemberMode(t) {
err = initMember2Await.WaitUntilWebhookDeleted(t) // webhook on member2 should be deleted
require.NoError(t, err)
}
initMemberAwait.WaitForMemberWebhooks(t, webhookImage)

// wait for autoscaler buffer apps
initMemberAwait.WaitForAutoscalingBufferApp(t)
initMember2Await.WaitForAutoscalingBufferApp(t)
if IsSecondMemberMode(t) {
initMember2Await.WaitForAutoscalingBufferApp(t)
}

// check that the tier exists, and all its namespace other cluster-scoped resource revisions
// are different from `000000a` which is the value specified in the initial manifest (used for base tier)
Expand All @@ -228,6 +235,10 @@ func WaitForDeployments(t *testing.T) wait.Awaitilities {
require.NoError(t, err)
})

if !IsSecondMemberMode(t) {
return wait.NewAwaitilities(initHostAwait, initMemberAwait)
}

return wait.NewAwaitilities(initHostAwait, initMemberAwait, initMember2Await)
}

Expand Down Expand Up @@ -263,3 +274,10 @@ func schemeWithAllAPIs(t *testing.T) *runtime.Scheme {
require.NoError(t, builder.AddToScheme(s))
return s
}

func IsSecondMemberMode(t *testing.T) bool {
secondMemberMode := os.Getenv(wait.SecondMemberModeVar)
require.NotEmpty(t, secondMemberMode)

return secondMemberMode == "true"
}
1 change: 1 addition & 0 deletions testsupport/wait/awaitility.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
DefaultTimeout = time.Second * 120
MemberNsVar = "MEMBER_NS"
MemberNsVar2 = "MEMBER_NS_2"
SecondMemberModeVar = "SECOND_MEMBER_MODE"
HostNsVar = "HOST_NS"
RegistrationServiceVar = "REGISTRATION_SERVICE_NS"
ToolchainClusterConditionTimeout = 180 * time.Second
Expand Down

0 comments on commit 05850d1

Please sign in to comment.