mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-22 19:59:26 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66eca59f67 |
@@ -43,7 +43,7 @@ jobs:
|
||||
run: |
|
||||
set +x
|
||||
# create cluster
|
||||
az group create --location eastus2 --name ${{ env.NAMESPACE }}
|
||||
az group create --location eastus --name ${{ env.NAMESPACE }}
|
||||
az aks create --name ${{ env.NAMESPACE }} --resource-group ${{ env.NAMESPACE }} --enable-private-cluster --generate-ssh-keys
|
||||
az aks get-credentials --resource-group ${{ env.NAMESPACE }} --name ${{ env.NAMESPACE }}
|
||||
|
||||
@@ -63,7 +63,6 @@ jobs:
|
||||
images: nginx:1.14.2
|
||||
manifests: |
|
||||
test/integration/manifests/test.yml
|
||||
test/integration/manifests/test2.yml
|
||||
action: deploy
|
||||
private-cluster: true
|
||||
resource-group: ${{ env.NAMESPACE }}
|
||||
@@ -74,9 +73,6 @@ jobs:
|
||||
python test/integration/k8s-deploy-test.py private=${{ env.NAMESPACE }} namespace=${{ env.NAMESPACE }} kind=Deployment name=nginx-deployment containerName=nginx:1.14.2 labels=app:nginx,workflow:actions.github.com-k8s-deploy,workflowFriendlyName:Cluster_Integration_Tests_-_private_cluster selectorLabels=app:nginx
|
||||
python test/integration/k8s-deploy-test.py private=${{ env.NAMESPACE }} namespace=${{ env.NAMESPACE }} kind=Service name=nginx-service labels=workflow:actions.github.com-k8s-deploy,workflowFriendlyName:Cluster_Integration_Tests_-_private_cluster selectorLabels=app:nginx
|
||||
|
||||
python test/integration/k8s-deploy-test.py private=${{ env.NAMESPACE }} namespace=${{ env.NAMESPACE }} kind=Deployment name=nginx-deployment2 containerName=nginx:1.14.2 labels=app:nginx2,workflow:actions.github.com-k8s-deploy,workflowFriendlyName:Cluster_Integration_Tests_-_private_cluster selectorLabels=app:nginx2
|
||||
python test/integration/k8s-deploy-test.py private=${{ env.NAMESPACE }} namespace=${{ env.NAMESPACE }} kind=Service name=nginx-service2 labels=workflow:actions.github.com-k8s-deploy,workflowFriendlyName:Cluster_Integration_Tests_-_private_cluster selectorLabels=app:nginx2
|
||||
|
||||
- name: Clean up AKS cluster
|
||||
if: ${{ always() }}
|
||||
run: |
|
||||
|
||||
Generated
+6770
-2955
File diff suppressed because it is too large
Load Diff
+5
-6
@@ -19,17 +19,16 @@
|
||||
"@octokit/core": "^3.5.1",
|
||||
"@octokit/plugin-retry": "^3.0.9",
|
||||
"@types/minipass": "^3.1.2",
|
||||
"js-yaml": "3.13.1",
|
||||
"minimist": "^1.2.8"
|
||||
"js-yaml": "3.13.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/js-yaml": "^3.12.7",
|
||||
"@types/node": "^12.20.41",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-jest": "^29.2.3",
|
||||
"typescript": "5.5.4"
|
||||
"jest": "^26.0.0",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "3.9.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,17 @@ const testNamespace = 'testNamespace'
|
||||
const defaultNamespace = 'default'
|
||||
const otherNamespace = 'otherns'
|
||||
describe('Kubectl class', () => {
|
||||
describe('default namespace behavior', () => {
|
||||
const kubectl = new Kubectl(kubectlPath, defaultNamespace)
|
||||
const execReturn = {exitCode: 0, stdout: 'Output', stderr: ''}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return execReturn
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a success exec return in testNamespace', () => {
|
||||
const kubectl = new Kubectl(kubectlPath, testNamespace)
|
||||
const execReturn = {exitCode: 0, stdout: 'Output', stderr: ''}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
PrivateKubectl,
|
||||
extractFileNames,
|
||||
replaceFileNamesWithBaseNames
|
||||
} from './privatekubectl'
|
||||
import { PrivateKubectl, extractFileNames, replaceFileNamesWithBaseNames } from './privatekubectl'
|
||||
import * as exec from '@actions/exec'
|
||||
|
||||
describe('Private kubectl', () => {
|
||||
@@ -16,13 +12,9 @@ describe('Private kubectl', () => {
|
||||
)
|
||||
|
||||
it('should extract filenames correctly', () => {
|
||||
expect(extractFileNames(testString)).toEqual([
|
||||
'testdir/test.yml',
|
||||
'test2.yml',
|
||||
'testdir/subdir/test3.yml',
|
||||
'test4.yml',
|
||||
'test5.yml'
|
||||
])
|
||||
expect(extractFileNames(testString)).toEqual(
|
||||
['testdir/test.yml', 'test2.yml', 'testdir/subdir/test3.yml', 'test4.yml', 'test5.yml']
|
||||
)
|
||||
})
|
||||
|
||||
it('should replace filenames with basenames correctly', () => {
|
||||
@@ -34,7 +26,7 @@ describe('Private kubectl', () => {
|
||||
test('Should throw well defined Error on error from Azure', async () => {
|
||||
const errorMsg = 'An error message'
|
||||
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return {exitCode: 1, stdout: '', stderr: errorMsg}
|
||||
return { exitCode: 1, stdout: '', stderr: errorMsg }
|
||||
})
|
||||
|
||||
await expect(mockKube.executeCommand('az', 'test')).rejects.toThrow(
|
||||
|
||||
+18
-25
@@ -1,6 +1,6 @@
|
||||
import {Kubectl} from './kubectl'
|
||||
import { Kubectl } from './kubectl'
|
||||
import * as minimist from 'minimist'
|
||||
import {ExecOptions, ExecOutput, getExecOutput} from '@actions/exec'
|
||||
import { ExecOptions, ExecOutput, getExecOutput } from '@actions/exec'
|
||||
import * as core from '@actions/core'
|
||||
import * as os from 'os'
|
||||
import * as fs from 'fs'
|
||||
@@ -54,9 +54,7 @@ export class PrivateKubectl extends Kubectl {
|
||||
try {
|
||||
this.moveFileToTempManifestDir(filename)
|
||||
} catch (e) {
|
||||
core.debug(
|
||||
`Error moving file ${filename} to temp directory: ${e}`
|
||||
)
|
||||
core.debug(`Error moving file ${filename} to temp directory: ${e}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +78,7 @@ export class PrivateKubectl extends Kubectl {
|
||||
)
|
||||
}
|
||||
|
||||
const runObj: {logs: string; exitCode: number} = JSON.parse(
|
||||
const runObj: { logs: string; exitCode: number } = JSON.parse(
|
||||
runOutput.stdout
|
||||
)
|
||||
if (!silent) core.info(runObj.logs)
|
||||
@@ -95,6 +93,7 @@ export class PrivateKubectl extends Kubectl {
|
||||
} as ExecOutput
|
||||
}
|
||||
|
||||
|
||||
private containsFilenames(str: string) {
|
||||
return str.includes('-f ') || str.includes('filename ')
|
||||
}
|
||||
@@ -102,7 +101,7 @@ export class PrivateKubectl extends Kubectl {
|
||||
private createTempManifestsDirectory() {
|
||||
const manifestsDir = '/tmp/manifests'
|
||||
if (!fs.existsSync('/tmp/manifests')) {
|
||||
fs.mkdirSync('/tmp/manifests', {recursive: true})
|
||||
fs.mkdirSync('/tmp/manifests', { recursive: true })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +110,8 @@ export class PrivateKubectl extends Kubectl {
|
||||
if (!fs.existsSync('/tmp/' + file)) {
|
||||
core.debug(
|
||||
'/tmp/' +
|
||||
file +
|
||||
' does not exist, and therefore cannot be moved to the manifest directory'
|
||||
file +
|
||||
' does not exist, and therefore cannot be moved to the manifest directory'
|
||||
)
|
||||
}
|
||||
|
||||
@@ -120,20 +119,20 @@ export class PrivateKubectl extends Kubectl {
|
||||
if (err) {
|
||||
core.debug(
|
||||
'Could not rename ' +
|
||||
'/tmp/' +
|
||||
file +
|
||||
' to ' +
|
||||
'/tmp/manifests/' +
|
||||
file +
|
||||
' ERROR: ' +
|
||||
err
|
||||
'/tmp/' +
|
||||
file +
|
||||
' to ' +
|
||||
'/tmp/manifests/' +
|
||||
file +
|
||||
' ERROR: ' +
|
||||
err
|
||||
)
|
||||
return
|
||||
}
|
||||
core.debug(
|
||||
"Successfully moved file '" +
|
||||
file +
|
||||
"' from /tmp to /tmp/manifest directory"
|
||||
file +
|
||||
"' from /tmp to /tmp/manifest directory"
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -145,13 +144,7 @@ export function replaceFileNamesWithBaseNames(kubectlCmd: string) {
|
||||
|
||||
let result = kubectlCmd
|
||||
if (filenames.length != basenames.length) {
|
||||
throw Error(
|
||||
'replacing filenames with basenames, ' +
|
||||
filenames.length +
|
||||
' filenames != ' +
|
||||
basenames.length +
|
||||
'basenames'
|
||||
)
|
||||
throw Error('replacing filenames with basenames, ' + filenames.length + ' filenames != ' + basenames.length + 'basenames')
|
||||
}
|
||||
for (let index = 0; index < filenames.length; index++) {
|
||||
result = result.replace(filenames[index], basenames[index])
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-deployment2
|
||||
labels:
|
||||
app: nginx2
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx2
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: nginx-service2
|
||||
spec:
|
||||
selector:
|
||||
app: nginx2
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 80
|
||||
Reference in New Issue
Block a user