-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9945 from Microsoft/users/ansheno/kubectlToolInst…
…aller Added Kubectl tool installer task
- Loading branch information
Showing
12 changed files
with
1,294 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Tasks/KubectlInstallerV0/Strings/resources.resjson/en-US/resources.resjson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"loc.friendlyName": "Kubectl tool installer", | ||
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=851275)", | ||
"loc.description": "Install Kubectl on agent machine.", | ||
"loc.instanceNameFormat": "Install Kubectl $(kubectlVersion)", | ||
"loc.input.label.kubectlVersion": "Kubectl Version Spec", | ||
"loc.input.help.kubectlVersion": "Specify the version of Kubectl to install", | ||
"loc.messages.NotAValidSemverVersion": "Version not specified in correct format. E.g: 1.8.2, v1.8.2, 2.8.2, v2.8.2.", | ||
"loc.messages.VerifyKubectlInstallation": "Verifying kubectl installation..." | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"common": [{ | ||
"module": "../Common/utility-common", | ||
"type": "node", | ||
"dest" : "./", | ||
"compile" : true | ||
}], | ||
"rm": [ | ||
{ | ||
"items": [ | ||
"node_modules/utility-common/node_modules/vsts-task-lib" | ||
], | ||
"options": "-Rf" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"azure-pipelines-task-lib": "2.7.7", | ||
"azure-pipelines-tool-lib": "0.11.0", | ||
"utility-common": "file:../../_build/Tasks/Common/utility-common-1.0.2.tgz" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
|
||
import tl = require('azure-pipelines-task-lib/task'); | ||
import path = require('path'); | ||
import * as toolLib from 'azure-pipelines-tool-lib/tool'; | ||
import utils = require("./utils"); | ||
|
||
tl.setResourcePath(path.join(__dirname, '..', 'task.json')); | ||
|
||
async function configureKubectl() { | ||
var version = await utils.getKuberctlVersion(); | ||
var kubectlPath = await utils.downloadKubectl(version); | ||
|
||
// prepend the tools path. instructs the agent to prepend for future tasks | ||
if (!process.env['PATH'].startsWith(path.dirname(kubectlPath))) { | ||
toolLib.prependPath(path.dirname(kubectlPath)); | ||
} | ||
} | ||
|
||
async function verifyKubectl() { | ||
console.log(tl.loc("VerifyKubectlInstallation")); | ||
var kubectlToolPath = tl.which("kubectl", true); | ||
var kubectlTool = tl.tool(kubectlToolPath); | ||
kubectlTool.arg("--help"); | ||
return kubectlTool.exec() | ||
} | ||
|
||
configureKubectl() | ||
.then(() => verifyKubectl()) | ||
.then(() => { | ||
tl.setResult(tl.TaskResult.Succeeded, ""); | ||
}).catch((error) => { | ||
tl.setResult(tl.TaskResult.Failed, error) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict" | ||
|
||
import tl = require("azure-pipelines-task-lib/task"); | ||
import toolLib = require("azure-pipelines-tool-lib/tool"); | ||
import kubectlutility = require("utility-common/kubectlutility"); | ||
|
||
export async function getKuberctlVersion(): Promise<string> { | ||
let kubectlVersion = tl.getInput("kubectlVersion"); | ||
if(kubectlVersion && kubectlVersion != "latest") { | ||
return sanitizeVersionString(kubectlVersion.trim()); | ||
} | ||
|
||
return await kubectlutility.getStableKubectlVersion(); | ||
} | ||
|
||
export async function downloadKubectl(version : string): Promise<string> { | ||
return await kubectlutility.downloadKubectl(version); | ||
} | ||
|
||
// handle user input scenerios | ||
export function sanitizeVersionString(inputVersion: string) : string{ | ||
var version = toolLib.cleanVersion(inputVersion); | ||
if(!version) { | ||
throw new Error(tl.loc("NotAValidSemverVersion")); | ||
} | ||
|
||
return "v"+version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"id": "8413C881-4959-43D5-8840-B4EA0FFC5CFD", | ||
"name": "KubectlInstaller", | ||
"friendlyName": "Kubectl tool installer", | ||
"description": "Install Kubectl on agent machine.", | ||
"helpUrl": "https://go.microsoft.com/fwlink/?linkid=851275", | ||
"helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=851275)", | ||
"category": "Tool", | ||
"visibility": [ | ||
"Build", | ||
"Release" | ||
], | ||
"preview": true, | ||
"author": "Microsoft Corporation", | ||
"version": { | ||
"Major": 0, | ||
"Minor": 150, | ||
"Patch": 0 | ||
}, | ||
"demands": [], | ||
"satisfies": [ | ||
"Kubectl" | ||
], | ||
"groups": [], | ||
"inputs": [ | ||
{ | ||
"name": "kubectlVersion", | ||
"label": "Kubectl Version Spec", | ||
"type": "string", | ||
"helpMarkDown": "Specify the version of Kubectl to install", | ||
"defaultValue": "latest" | ||
} | ||
], | ||
"instanceNameFormat": "Install Kubectl $(kubectlVersion)", | ||
"execution": { | ||
"Node": { | ||
"target": "src//kubectltoolinstaller.js" | ||
} | ||
}, | ||
"messages": { | ||
"NotAValidSemverVersion": "Version not specified in correct format. E.g: 1.8.2, v1.8.2, 2.8.2, v2.8.2.", | ||
"VerifyKubectlInstallation": "Verifying kubectl installation..." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"id": "8413C881-4959-43D5-8840-B4EA0FFC5CFD", | ||
"name": "KubectlInstaller", | ||
"friendlyName": "ms-resource:loc.friendlyName", | ||
"description": "ms-resource:loc.description", | ||
"helpUrl": "https://go.microsoft.com/fwlink/?linkid=851275", | ||
"helpMarkDown": "ms-resource:loc.helpMarkDown", | ||
"category": "Tool", | ||
"visibility": [ | ||
"Build", | ||
"Release" | ||
], | ||
"preview": true, | ||
"author": "Microsoft Corporation", | ||
"version": { | ||
"Major": 0, | ||
"Minor": 150, | ||
"Patch": 0 | ||
}, | ||
"demands": [], | ||
"satisfies": [ | ||
"Kubectl" | ||
], | ||
"groups": [], | ||
"inputs": [ | ||
{ | ||
"name": "kubectlVersion", | ||
"label": "ms-resource:loc.input.label.kubectlVersion", | ||
"type": "string", | ||
"helpMarkDown": "ms-resource:loc.input.help.kubectlVersion", | ||
"defaultValue": "latest" | ||
} | ||
], | ||
"instanceNameFormat": "ms-resource:loc.instanceNameFormat", | ||
"execution": { | ||
"Node": { | ||
"target": "src//kubectltoolinstaller.js" | ||
} | ||
}, | ||
"messages": { | ||
"NotAValidSemverVersion": "ms-resource:loc.messages.NotAValidSemverVersion", | ||
"VerifyKubectlInstallation": "ms-resource:loc.messages.VerifyKubectlInstallation" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES6", | ||
"module": "commonjs", | ||
"typeRoots": [ "node_modules/@types" ] | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters