Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add server-side option based on force option #312

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ Following are the key capabilities of this action:
<td>force </br></br>(Optional)</td>
<td>Deploy when a previous deployment already exists. If true then '--force' argument is added to the apply command. Using '--force' argument is not recommended in production.</td>
</tr>
<tr>
<td>server-side </br></br>(Optional)</td>
<td>The apply command runs in the server instead of the client. If true then '--server-side' argument is added to the apply command.</td>
</tr>
<tr>
<td>annotate-resources</br></br>(Optional)</td>
<td>Acceptable values: true/false</br>Default value: true</br>Switch whether to annotate the resources or not. If set to false all annotations are skipped completely.</td>
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ inputs:
description: 'Deploy when a previous deployment already exists. If true then --force argument is added to the apply command'
required: false
default: false
server-side:
description: 'The apply command runs in the server instead of the client. If true then --server-side argument is added to the apply command.'
required: false
default: false
token:
description: 'Github token'
default: ${{ github.token }}
Expand Down
3 changes: 2 additions & 1 deletion src/strategyHelpers/canary/podCanaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ export async function deployPodCanary(
core.debug('New objects list: ' + JSON.stringify(newObjectsList))
const manifestFiles = fileHelper.writeObjectsToFile(newObjectsList)
const forceDeployment = core.getInput('force').toLowerCase() === 'true'
const serverSideDeployment = core.getInput('server-side').toLowerCase() === 'true'

const execResult = await kubectl.apply(manifestFiles, forceDeployment)
const execResult = await kubectl.apply(manifestFiles, forceDeployment, serverSideDeployment)
return {execResult, manifestFiles}
}

Expand Down
9 changes: 6 additions & 3 deletions src/strategyHelpers/canary/smiCanaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export async function deploySMICanary(
)
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList)
const forceDeployment = core.getInput('force').toLowerCase() === 'true'
const result = await kubectl.apply(newFilePaths, forceDeployment)
const serverSideDeployment = core.getInput('server-side').toLowerCase() === 'true'
const result = await kubectl.apply(newFilePaths, forceDeployment, serverSideDeployment)
const svcDeploymentFiles = await createCanaryService(kubectl, filePaths)
newFilePaths.push(...svcDeploymentFiles)
return {execResult: result, manifestFiles: newFilePaths}
Expand Down Expand Up @@ -192,8 +193,9 @@ async function createCanaryService(
const manifestFiles = fileHelper.writeObjectsToFile(newObjectsList)
manifestFiles.push(...trafficObjectsList)
const forceDeployment = core.getInput('force').toLowerCase() === 'true'
const serverSideDeployment = core.getInput('server-side').toLowerCase() === 'true'

const result = await kubectl.apply(manifestFiles, forceDeployment)
const result = await kubectl.apply(manifestFiles, forceDeployment, server-side)
checkForErrors([result])
return manifestFiles
}
Expand Down Expand Up @@ -249,7 +251,8 @@ async function adjustTraffic(
}

const forceDeployment = core.getInput('force').toLowerCase() === 'true'
const result = await kubectl.apply(trafficSplitManifests, forceDeployment)
const serverSideDeployment = core.getInput('server-side').toLowerCase() === 'true'
const result = await kubectl.apply(trafficSplitManifests, forceDeployment, serverSideDeployment)
checkForErrors([result])
return trafficSplitManifests
}
Expand Down
6 changes: 4 additions & 2 deletions src/strategyHelpers/deploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,18 @@ export async function deployManifests(
)

const forceDeployment = core.getInput('force').toLowerCase() === 'true'
const serverSideDeployment = core.getInput('server-side').toLowerCase() === 'true'
if (trafficSplitMethod === TrafficSplitMethod.SMI) {
const updatedManifests = appendStableVersionLabelToResource(files)

const result = await kubectl.apply(
updatedManifests,
forceDeployment
forceDeployment,
serverSideDeployment
)
checkForErrors([result])
} else {
const result = await kubectl.apply(files, forceDeployment)
const result = await kubectl.apply(files, forceDeployment, serverSideDeployment)
checkForErrors([result])
}

Expand Down
20 changes: 19 additions & 1 deletion src/types/kubectl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Kubectl class', () => {

it('applies a configuration with force when specified', async () => {
const configPaths = ['configPath1', 'configPath2', 'configPath3']
const result = await kubectl.apply(configPaths, true)
const result = await kubectl.apply(configPaths, true, false)
expect(result).toBe(execReturn)
expect(exec.getExecOutput).toBeCalledWith(
kubectlPath,
Expand All @@ -106,6 +106,24 @@ describe('Kubectl class', () => {
)
})

it('applies a configuration with server-side when specified', async () => {
const configPaths = ['configPath1', 'configPath2', 'configPath3']
const result = await kubectl.apply(configPaths, false, true)
expect(result).toBe(execReturn)
expect(exec.getExecOutput).toBeCalledWith(
kubectlPath,
[
'apply',
'-f',
configPaths[0] + ',' + configPaths[1] + ',' + configPaths[2],
'--server-side',
'--namespace',
testNamespace
],
{silent: false}
)
})

it('describes a resource', async () => {
const resourceType = 'type'
const resourceName = 'name'
Expand Down
4 changes: 3 additions & 1 deletion src/types/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class Kubectl {

public async apply(
configurationPaths: string | string[],
force: boolean = false
force: boolean = false,
serverSide: boolean = false,
): Promise<ExecOutput> {
try {
if (!configurationPaths || configurationPaths?.length === 0)
Expand All @@ -46,6 +47,7 @@ export class Kubectl {
createInlineArray(configurationPaths)
]
if (force) applyArgs.push('--force')
if (serverSide) applyArgs.push('--server-side')

return await this.execute(applyArgs.concat(this.getFlags()))
} catch (err) {
Expand Down