Skip to content

Commit

Permalink
fix: problem of the binary set for kubectl
Browse files Browse the repository at this point in the history
  • Loading branch information
TsuyoshiUshio committed Jul 13, 2018
1 parent 8e14d03 commit 08ebf48
Show file tree
Hide file tree
Showing 7 changed files with 487 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Tests/test-apply.ts
Expand Up @@ -12,6 +12,7 @@ tr.setInput('kubectlBinary', './Tests/kubectl');
tr.setInput('k8sService', 'k8sendpoint');
tr.setInput('system.debug', 'true');

process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = '/opt/vsts/work/r1/a'
process.env['ENDPOINT_AUTH_PARAMETER_K8SENDPOINT_KUBECONFIG'] = `
---
Expand Down Expand Up @@ -56,7 +57,11 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"./Tests/kubectl apply -f ./Tests/my-nginx.yml --kubeconfig ./kubeconfig": {
"code": 0,
"stdout": "deployment \"nginx-deployment\" created"
}
},
"mkdir -p /opt/vsts/work/r1/a/.vstsbin": {
"code": 0,
"stdiout": ""
},
}
}
tr.setAnswers(a);
Expand Down
7 changes: 6 additions & 1 deletion Tests/test-general-doubleminus.ts
Expand Up @@ -12,6 +12,7 @@ tr.setInput('k8sService', 'k8sendpoint');
tr.setInput('subCommand', 'exec');
tr.setInput('arguments', 'mongo-2180634381-zx0d3 --namespace mrp -- mongo ordering /tmp/MongoRecords.js');

process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = '/opt/vsts/work/r1/a'
process.env['ENDPOINT_AUTH_PARAMETER_K8SENDPOINT_KUBECONFIG'] = `
---
Expand Down Expand Up @@ -52,7 +53,11 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"./Tests/kubectl exec mongo-2180634381-zx0d3 --namespace mrp --kubeconfig ./kubeconfig -- mongo ordering /tmp/MongoRecords.js": {
"code": 0,
"stdout": "OK"
}
},
"mkdir -p /opt/vsts/work/r1/a/.vstsbin": {
"code": 0,
"stdiout": ""
},
}
}
tr.setAnswers(a);
Expand Down
8 changes: 6 additions & 2 deletions Tests/test-general-expose.ts
Expand Up @@ -12,7 +12,7 @@ tr.setInput('k8sService', 'k8sendpoint');
tr.setInput('subCommand', 'expose');
tr.setInput('arguments', 'deployment echoheaders\n--port=80\n--target-port=8080\n--name=echoheaders-x');


process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = '/opt/vsts/work/r1/a'
process.env['ENDPOINT_AUTH_PARAMETER_K8SENDPOINT_KUBECONFIG'] = `
---
Expand Down Expand Up @@ -53,7 +53,11 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"./Tests/kubectl expose deployment echoheaders --port=80 --target-port=8080 --name=echoheaders-x --kubeconfig ./config": {
"code": 0,
"stdout": "echoheader exposed."
}
},
"mkdir -p /opt/vsts/work/r1/a/.vstsbin": {
"code": 0,
"stdiout": ""
},
}
}
tr.setAnswers(a);
Expand Down
7 changes: 6 additions & 1 deletion Tests/test-general.ts
Expand Up @@ -12,6 +12,7 @@ tr.setInput('k8sService', 'k8sendpoint');
tr.setInput('subCommand', 'get');
tr.setInput('arguments', 'nodes');

process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = '/opt/vsts/work/r1/a'
process.env['ENDPOINT_AUTH_PARAMETER_K8SENDPOINT_KUBECONFIG'] = `
---
Expand Down Expand Up @@ -53,7 +54,11 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers> {
"./Tests/kubectl get nodes --kubeconfig ./kubeconfig": {
"code": 0,
"stdout": "NAME STATUS AGE\nk8s-agent-559ac24b-0 Ready 28d\nk8s-master-559ac24b-0 Ready,SchedulingDisabled 28d"
}
},
"mkdir -p /opt/vsts/work/r1/a/.vstsbin": {
"code": 0,
"stdiout": ""
},
}
}
tr.setAnswers(a);
Expand Down
11 changes: 11 additions & 0 deletions kubectl.ts
Expand Up @@ -69,10 +69,21 @@ export class KubectlCommand {

if (this.kubectlbinary === tl.cwd()) {
this.kubectlbinary = await this.downloadKubectl(this.downloadVersion);
} else {
await this.createBinaryDirWithPath();
}
this.kubectl = tl.tool(this.kubectlbinary);
}

async createBinaryDirWithPath() {
let binaryDir = process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] + '/.vstsbin';
tl.debug("create the .vstsbin directory for the binaries");
let mkdir: ToolRunner = tl.tool("mkdir");
mkdir.arg("-p").arg(binaryDir);
await mkdir.exec();
tl.setVariable("PATH", binaryDir + ':' + tl.getVariable("PATH"));
}

async downloadKubectl(downloadVersion: string) : Q.Promise<string> {
try {
if (!downloadVersion) {
Expand Down

0 comments on commit 08ebf48

Please sign in to comment.