Skip to content

Commit

Permalink
chore(e2e): rhidp-4049 change app-config at e2e test runtime (#1850)
Browse files Browse the repository at this point in the history
* RHIDP-4049 change app-config at e2e test runtime

* Refactor namespace in config-map test

Changed the namespace from "showcase" to "showcase-runtime" in the configuration test to align with the new environment setup. This ensures the tests run against the correct namespace.

Signed-off-by: Gustavo Lira <[email protected]>

* Add logging for ConfigMap updates and deployment restarts

Enhanced the e2e test to include logging for key actions like updating ConfigMaps and restarting deployments. Modified the k8sHelper utility to log deployment status checks and errors for better traceability and debugging.

Signed-off-by: Gustavo Lira <[email protected]>

* Simplify logging and improve readability in deployment scripts

Updated various sections to utilize `console.log` and `console.error` for better clarity and simplicity in logging outputs. Indentation was corrected to improve readability, and unnecessary log statements were removed to streamline the code.

Signed-off-by: Gustavo Lira <[email protected]>

* Improve deployment debugging with detailed logs

Added detailed logging of deployment conditions and events to aid in debugging. This includes logging deployment status conditions and capturing events associated with the deployment during restarts.

Signed-off-by: Gustavo Lira <[email protected]>

* Increase deployment readiness timeout and enhance logging

Extended the deployment readiness timeout to 5 minutes and added logging for pod conditions to provide detailed insights during deployment checks. Refined condition checks to include both 'Progressing' and 'Available' states for completeness.

Signed-off-by: Gustavo Lira <[email protected]>

* Refactor k8sHelper.ts for improved logging and stability

Centralized the Kubernetes label selector and streamlined the logging of pod conditions by consolidating duplicate label selectors. Removed unnecessary deployment status checks for better performance and added error handling when retrieving pod conditions.

Signed-off-by: Gustavo Lira <[email protected]>

* Refactor deployment status check and logging

Added inline comments to clarify deployment status checking and logging enhancements. Specifically, log pod conditions using a label selector and verify replica count for readiness.

Signed-off-by: Gustavo Lira <[email protected]>

* Add optional labelSelector to logPodConditions method

Refactored the logPodConditions method to accept an optional labelSelector parameter. This allows more flexibility in logging pod conditions by using different label selectors if provided. Updated references within the method to use the new parameter accordingly.

Signed-off-by: Gustavo Lira <[email protected]>

* Reorganize runtime test deployment to periodic jobs

Moved deployment and testing of `showcase-runtime` from regular job flow to periodic job flow. This change ensures that runtime configuration changes and TLS config tests are only performed during nightly jobs, improving efficiency in the regular CI pipeline.

Signed-off-by: Gustavo Lira <[email protected]>

---------

Signed-off-by: Gustavo Lira <[email protected]>
  • Loading branch information
gustavolira authored Nov 26, 2024
1 parent 1a4a1d5 commit 058a609
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 20 deletions.
1 change: 1 addition & 0 deletions .ibm/pipelines/env_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RELEASE_NAME=rhdh
RELEASE_NAME_RBAC=rhdh-rbac
NAME_SPACE="${NAME_SPACE:-showcase}"
NAME_SPACE_RBAC="${NAME_SPACE_RBAC:-showcase-rbac}"
NAME_SPACE_RUNTIME="${NAME_SPACE_RUNTIME:-showcase-runtime}"
NAME_SPACE_POSTGRES_DB="${NAME_SPACE_POSTGRES_DB:-postgress-external-db}"
NAME_SPACE_RDS="showcase-rds-nightly"
CHART_VERSION="2.15.2"
Expand Down
12 changes: 10 additions & 2 deletions .ibm/pipelines/openshift-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ apply_yaml_files() {
oc apply -f "$dir/auth/secrets-rhdh-secrets.yaml" --namespace="${project}"

#sleep 20 # wait for Pipeline Operator/Tekton pipelines to be ready
# Renable when namespace termination issue is solved
# oc apply -f "$dir/resources/pipeline-run/hello-world-pipeline.yaml"
# oc apply -f "$dir/resources/pipeline-run/hello-world-pipeline-run.yaml"
}
Expand Down Expand Up @@ -473,7 +474,6 @@ main() {
ENCODED_API_SERVER_URL=$(echo "${API_SERVER_URL}" | base64)
ENCODED_CLUSTER_NAME=$(echo "my-cluster" | base64)


if [[ "$JOB_NAME" == *aks* ]]; then
initiate_aks_deployment
check_and_test "${RELEASE_NAME}" "${NAME_SPACE_K8S}"
Expand All @@ -492,10 +492,18 @@ main() {
initiate_deployments
check_and_test "${RELEASE_NAME}" "${NAME_SPACE}"
check_and_test "${RELEASE_NAME_RBAC}" "${NAME_SPACE_RBAC}"
# Only test TLS config with RDS in nightly jobs
# Only test TLS config with RDS and Change configuration at runtime in nightly jobs
if [[ "$JOB_NAME" == *periodic* ]]; then
initiate_rds_deployment "${RELEASE_NAME}" "${NAME_SPACE_RDS}"
check_and_test "${RELEASE_NAME}" "${NAME_SPACE_RDS}"

# Deploy `showcase-runtime` to run tests that require configuration changes at runtime
configure_namespace "${NAME_SPACE_RUNTIME}"
uninstall_helmchart "${NAME_SPACE_RUNTIME}" "${RELEASE_NAME}"
oc apply -f "$DIR/resources/redis-cache/redis-deployment.yaml" --namespace="${NAME_SPACE_RUNTIME}"
apply_yaml_files "${DIR}" "${NAME_SPACE_RUNTIME}"
helm upgrade -i "${RELEASE_NAME}" -n "${NAME_SPACE_RUNTIME}" "${HELM_REPO_NAME}/${HELM_IMAGE_NAME}" --version "${CHART_VERSION}" -f "${DIR}/value_files/${HELM_CHART_VALUE_FILE_NAME}" --set global.clusterRouterBase="${K8S_CLUSTER_ROUTER_BASE}" --set upstream.backstage.image.repository="${QUAY_REPO}" --set upstream.backstage.image.tag="${TAG_NAME}"
check_and_test "${RELEASE_NAME}" "${NAME_SPACE_RUNTIME}"
fi
fi

Expand Down
2 changes: 2 additions & 0 deletions e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"showcase-k8s-ci-nightly": "playwright test --project=showcase-k8s",
"showcase-rbac-k8s-ci-nightly": "playwright test --project=showcase-rbac-k8s",
"showcase-rds-nightly": "playwright test --project=postgres-health-check",
"showcase-runtime": "playwright test --project=showcase-runtime",
"lint:check": "eslint . --ext .js,.ts",
"lint:fix": "eslint . --ext .js,.ts --fix",
"postinstall": "playwright install",
Expand All @@ -41,6 +42,7 @@
"@kubernetes/client-node": "0.21.0",
"@microsoft/microsoft-graph-client": "3.0.7",
"isomorphic-fetch": "3.0.0",
"js-yaml": "^4.1.0",
"node-fetch": "3.3.2",
"octokit": "4.0.2",
"winston": "3.14.2"
Expand Down
8 changes: 7 additions & 1 deletion e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: 1,
workers: 3,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
["html"],
Expand Down Expand Up @@ -56,6 +56,7 @@ export default defineConfig({
"**/playwright/e2e/authProviders/**/*.spec.ts",
"**/playwright/e2e/plugins/bulk-import.spec.ts",
"**/playwright/e2e/verify-tls-config-health-check.spec.ts",
"**/playwright/e2e/configuration-test/config-map.spec.ts",
],
},
{
Expand Down Expand Up @@ -124,6 +125,11 @@ export default defineConfig({
...useCommonDeviceAndViewportConfig,
testMatch: ["**/playwright/e2e/verify-tls-config-health-check.spec.ts"],
},
{
name: "showcase-runtime",
...useCommonDeviceAndViewportConfig,
testMatch: ["**/playwright/e2e/configuration-test/config-map.spec.ts"],
},

// {
// name: 'firefox',
Expand Down
48 changes: 48 additions & 0 deletions e2e-tests/playwright/e2e/configuration-test/config-map.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test, expect } from "@playwright/test";
import { Common } from "../../utils/Common";
import { kubeCLient } from "../../utils/k8sHelper";
import { logger } from "../../utils/Logger";

test.describe("Change app-config at e2e test runtime", () => {
test("Verify title change after ConfigMap modification", async ({ page }) => {
test.setTimeout(300000); // Increasing to 5 minutes

const configMapName = "app-config-rhdh";
const namespace = "showcase-runtime";
const deploymentName = "rhdh-backstage";

const kubeUtils = new kubeCLient();
const dynamicTitle = generateDynamicTitle();

try {
logger.info(`Updating ConfigMap '${configMapName}' with new title.`);
await kubeUtils.updateConfigMapTitle(
configMapName,
namespace,
dynamicTitle,
);

logger.info(
`Restarting deployment '${deploymentName}' to apply ConfigMap changes.`,
);
await kubeUtils.restartDeployment(deploymentName, namespace);

const common = new Common(page);
await common.loginAsGuest();
logger.info("Verifying new title in the UI...");
expect(await page.title()).toContain(dynamicTitle);
logger.info("Title successfully verified in the UI.");
} catch (error) {
logger.error(
`Test failed during ConfigMap update or deployment restart:`,
error,
);
throw error;
}
});
});

function generateDynamicTitle() {
const timestamp = new Date().toISOString().replace(/[-:.]/g, "");
return `New Title - ${timestamp}`;
}
12 changes: 6 additions & 6 deletions e2e-tests/playwright/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function upgradeHelmChartWithWait(
dump: upgradeOutput,
});

const configmap = await k8sClient.getCongifmap(
const configmap = await k8sClient.getConfigMap(
`${RELEASE}-backstage-app-config`,
NAMESPACE,
);
Expand Down Expand Up @@ -153,7 +153,7 @@ export async function replaceInRBACPolicyFileConfigMap(
},
},
];
await k8sClient.updateCongifmap(configMap, namespace, patch);
await k8sClient.updateConfigMap(configMap, namespace, patch);
}

export async function ensureNewPolicyConfigMapExists(
Expand All @@ -164,7 +164,7 @@ export async function ensureNewPolicyConfigMapExists(
logger.info(
`Ensuring configmap ${configMap} exisists in namespace ${namespace}`,
);
await k8sClient.getCongifmap(configMap, namespace);
await k8sClient.getConfigMap(configMap, namespace);
const patch = [
{
op: "replace",
Expand All @@ -174,12 +174,12 @@ export async function ensureNewPolicyConfigMapExists(
},
},
];
await k8sClient.updateCongifmap(configMap, namespace, patch);
return await k8sClient.getCongifmap(configMap, namespace);
await k8sClient.updateConfigMap(configMap, namespace, patch);
return await k8sClient.getConfigMap(configMap, namespace);
} catch (e) {
if (e.response.statusCode == 404) {
logger.info(
`Configmap ${configMap} did not exsist in namespace ${namespace}. Creating it..`,
`Configmap ${configMap} did not exist in namespace ${namespace}. Creating it..`,
);
const cmBody: V1ConfigMap = {
metadata: {
Expand Down
Loading

0 comments on commit 058a609

Please sign in to comment.