Skip to content

Commit

Permalink
Merge pull request #9945 from Microsoft/users/ansheno/kubectlToolInst…
Browse files Browse the repository at this point in the history
…aller

Added Kubectl tool installer task
  • Loading branch information
Anumita authored Apr 1, 2019
2 parents 40d1b95 + a4cf0c0 commit fa3ec1a
Show file tree
Hide file tree
Showing 12 changed files with 1,294 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ Tasks/JenkinsDownloadArtifactsV1/* @Lovakumar @kasubram

Tasks/JenkinsQueueJobV2/* @madhurig

Tasks/KubectlInstallerV0/* @bansalaseem

Tasks/KubernetesV0/* @bansalaseem

Tasks/KubernetesV1/* @bansalaseem
Expand Down
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..."
}
1,098 changes: 1,098 additions & 0 deletions Tasks/KubectlInstallerV0/ThirdPartyNotices.txt

Large diffs are not rendered by default.

Binary file added Tasks/KubectlInstallerV0/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions Tasks/KubectlInstallerV0/make.json
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"
}
]
}
7 changes: 7 additions & 0 deletions Tasks/KubectlInstallerV0/package.json
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"
}
}
34 changes: 34 additions & 0 deletions Tasks/KubectlInstallerV0/src/kubectltoolinstaller.ts
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)
});
28 changes: 28 additions & 0 deletions Tasks/KubectlInstallerV0/src/utils.ts
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;
}
44 changes: 44 additions & 0 deletions Tasks/KubectlInstallerV0/task.json
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..."
}
}
44 changes: 44 additions & 0 deletions Tasks/KubectlInstallerV0/task.loc.json
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"
}
}
10 changes: 10 additions & 0 deletions Tasks/KubectlInstallerV0/tsconfig.json
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"
]
}
1 change: 1 addition & 0 deletions make-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"JavaToolInstallerV0",
"JenkinsDownloadArtifactsV1",
"JenkinsQueueJobV2",
"KubectlInstallerV0",
"KubernetesV0",
"KubernetesV1",
"KubernetesManifestV0",
Expand Down

0 comments on commit fa3ec1a

Please sign in to comment.