mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-27 23:39:27 +08:00
Make namespace input optional (#420)
Signed-off-by: Tatsat Mishra <tamishra@microsoft.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tatsinnit <tamishra@microsoft.com>
This commit is contained in:
+1
-1
@@ -35,7 +35,7 @@ export async function run() {
|
||||
const fullManifestFilePaths =
|
||||
await getFilesFromDirectoriesAndURLs(manifestFilePaths)
|
||||
const kubectlPath = await getKubectlPath()
|
||||
const namespace = core.getInput('namespace') || 'default'
|
||||
const namespace = core.getInput('namespace') || '' // Sets namespace to an empty string if not provided, allowing the manifest-defined namespace to take precedence instead of "default".
|
||||
const isPrivateCluster =
|
||||
core.getInput('private-cluster').toLowerCase() === 'true'
|
||||
const resourceGroup = core.getInput('resource-group') || ''
|
||||
|
||||
@@ -196,7 +196,7 @@ async function annotateResources(
|
||||
deploymentConfig: DeploymentConfig
|
||||
) {
|
||||
const annotateResults: ExecOutput[] = []
|
||||
const namespace = core.getInput('namespace') || 'default'
|
||||
const namespace = core.getInput('namespace') || '' // Sets namespace to an empty string if not provided, allowing the manifest-defined namespace to take precedence instead of "default".
|
||||
const lastSuccessSha = await getLastSuccessfulRunSha(
|
||||
kubectl,
|
||||
namespace,
|
||||
@@ -227,8 +227,10 @@ async function annotateResources(
|
||||
)}`
|
||||
|
||||
const annotateNamespace = !(
|
||||
namespace === '' ||
|
||||
core.getInput('annotate-namespace').toLowerCase() === 'false'
|
||||
)
|
||||
) // If namespace is empty, we don't annotate it. If the input is false, we also don't annotate it.
|
||||
|
||||
if (annotateNamespace) {
|
||||
annotateResults.push(
|
||||
await kubectl.annotate(
|
||||
|
||||
@@ -535,3 +535,54 @@ describe('Kubectl class', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Kubectl namespace handling', () => {
|
||||
const kubectlPath = 'kubectlPath'
|
||||
const testNamespace = 'testNamespace'
|
||||
const configPaths = 'configPaths'
|
||||
const execReturn = {exitCode: 0, stdout: 'Output', stderr: ''}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(exec, 'getExecOutput').mockResolvedValue(execReturn)
|
||||
})
|
||||
|
||||
const runApply = async (namespace?: string) => {
|
||||
const kubectl = new Kubectl(kubectlPath, namespace)
|
||||
return kubectl.apply(configPaths)
|
||||
}
|
||||
|
||||
it.each([
|
||||
{
|
||||
namespace: undefined,
|
||||
expectedArgs: ['apply', '-f', configPaths],
|
||||
description: 'namespace omitted'
|
||||
},
|
||||
{
|
||||
namespace: '',
|
||||
expectedArgs: ['apply', '-f', configPaths],
|
||||
description: 'namespace is an empty string (default namespace)'
|
||||
},
|
||||
{
|
||||
namespace: testNamespace,
|
||||
expectedArgs: [
|
||||
'apply',
|
||||
'-f',
|
||||
configPaths,
|
||||
'--namespace',
|
||||
testNamespace
|
||||
],
|
||||
description: 'namespace provided'
|
||||
}
|
||||
])(
|
||||
'handles namespace when $description',
|
||||
async ({namespace, expectedArgs}) => {
|
||||
const result = await runApply(namespace)
|
||||
expect(result).toBe(execReturn)
|
||||
expect(exec.getExecOutput).toHaveBeenCalledWith(
|
||||
kubectlPath,
|
||||
expectedArgs,
|
||||
{silent: false}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user