diff --git a/cypress/utils/utils.ts b/cypress/utils/utils.ts index 9b55d87c3..d944c82ed 100644 --- a/cypress/utils/utils.ts +++ b/cypress/utils/utils.ts @@ -1680,24 +1680,38 @@ export function isRwxEnabled(): boolean { return Cypress.env("rwx_enabled"); } +export function getUrl(): string { + return window.location.href; +} + +export function getNamespace(): string { + // This is regexp pattern to search between first `-` and first `.` + const namespacePattern = /-(.*?)\./; + // First match, means `-` + const match = getUrl().match(namespacePattern); + if (match && match[1]) { + return match[1].toString(); + } else { + return "konveyor-tackle"; + } +} + // This method is patching export function configureRWX(isEnabled = true): void { // Patching CR to set value - let value: string; + let value = ""; if (isEnabled) { value = "true"; } else { value = "false"; } let command = ""; - let tackleCr = "tackle=$(oc get tackle --all-namespaces|grep -iv name|awk '{print $2}'); "; - let namespace = - 'namespace=$(oc get tackle --all-namespaces|egrep "tackle|mta"|cut -d " " -f 1); '; + let namespace = getNamespace(); + let tackleCr = `tackle=$(oc get tackle -n${namespace}|grep -iv name|awk '{print $1}'); `; command += tackleCr; - command += namespace; command += "oc patch tackle "; command += "$tackle "; - command += "-n$namespace "; + command += `-n${namespace} `; command += "--type merge "; command += `--patch '{"spec":{"rwx_supported": ${value}}}'`; cy.log(command);