Skip to content

Commit 1a51293

Browse files
authored
Users/jikuma/cherry pick helm tasks (#6902)
* added support for kubernetes endpoint (#6697) * added support for kubernetes endpoint * Update task.loc.json * helm deploy task improvement (#6754) * helm deploy task improvement * resolve path install command * resource group and bug fix (#6806) * Users/jikuma/helmtoolinstaller (#6869) * Helm inster kubernetes done * Helm installer improvements * self review * review commit
1 parent 1de96c2 commit 1a51293

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5919
-198
lines changed

Tasks/Common/azure-arm-rest/azure-arm-aks-service.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ export class AzureAksService {
3535
});
3636
}
3737

38-
// list all the manages cluster. They don't have continuation token now, so only one call.
39-
public list(): Promise<Model.AKSCluster[]> {
40-
return this.beginRequest(`//subscriptions/{subscriptionId}/providers/Microsoft.ContainerService/managedClusters`, {}).then((response) => {
41-
return response.body.value;
42-
}, (reason) => {
43-
throw Error(tl.loc('FailedToListClusters', this._client.getFormattedError(reason)));
44-
});
45-
}
46-
4738
public getAccessProfile(resourceGroup : string , clusterName : string ): Promise<Model.AKSClusterAccessProfile> {
4839
return this.beginRequest(`//subscriptions/{subscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{ClusterName}/accessProfiles/clusterUser`,
4940
{
@@ -55,6 +46,4 @@ export class AzureAksService {
5546
throw Error(tl.loc('CantDownloadAccessProfile',clusterName, this._client.getFormattedError(reason)));
5647
});
5748
}
58-
59-
6049
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import * as os from "os";
2+
import * as path from "path";
3+
import * as toolLib from 'vsts-task-tool-lib/tool';
4+
import * as tl from "vsts-task-lib/task";
5+
import * as downloadutility from "./downloadutility";
6+
import * as util from "util";
7+
const uuidV4 = require('uuid/v4');
8+
const kubectlToolName = "kubectl"
9+
export const stableKubectlVersion = "1.8.9"
10+
11+
12+
var fs = require('fs');
13+
14+
// get a stable version from the url https://storage.googleapis.com/kubernetes-release/release/stable.txt
15+
export async function getStableKubectlVersion() : Promise<string> {
16+
var version;
17+
var stableVersionUrl = "https://storage.googleapis.com/kubernetes-release/release/stable.txt";
18+
var downloadPath = path.join(getTempDirectory(), uuidV4() +".txt");
19+
return downloadutility.download(stableVersionUrl, downloadPath).then((resolve) => {
20+
version = fs.readFileSync(downloadPath, "utf8").toString().trim();
21+
if(!version){
22+
version = stableKubectlVersion;
23+
}
24+
return version;
25+
},
26+
(reject) => {
27+
tl.debug(reject);
28+
tl.warning(tl.loc('DownloadStableVersionFailed', stableVersionUrl, stableKubectlVersion));
29+
return stableKubectlVersion;
30+
})
31+
}
32+
33+
34+
export async function downloadKubectl(version: string) : Promise<string> {
35+
var kubectlURL = getkubectlDownloadURL(version);
36+
var cachedToolpath = toolLib.findLocalTool(kubectlToolName, version);
37+
if(!cachedToolpath) {
38+
try {
39+
var KubectlDownloadPath = await toolLib.downloadTool(getkubectlDownloadURL(version));
40+
} catch(exception) {
41+
throw new Error(tl.loc("DownloadKubectlFailedFromLocation", getkubectlDownloadURL(version), exception));
42+
}
43+
44+
cachedToolpath = await toolLib.cacheFile(KubectlDownloadPath, kubectlToolName + getExecutableExtention() , kubectlToolName, version);
45+
}
46+
47+
var kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtention());
48+
fs.chmod(kubectlPath, "777");
49+
return kubectlPath;
50+
}
51+
52+
function getTempDirectory(): string {
53+
return tl.getVariable('agent.tempDirectory') || os.tmpdir();
54+
}
55+
56+
function getkubectlDownloadURL(version: string) : string {
57+
switch(os.type())
58+
{
59+
case 'Linux':
60+
return util.format("https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64/kubectl", version);
61+
62+
case 'Darwin':
63+
return util.format("https://storage.googleapis.com/kubernetes-release/release/%s/bin/darwin/amd64/kubectl", version);
64+
65+
default:
66+
case 'Windows_NT':
67+
return util.format("https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/amd64/kubectl.exe", version);
68+
69+
}
70+
}
71+
72+
function getExecutableExtention(): string {
73+
if(os.type().match(/^Win/)){
74+
return ".exe";
75+
}
76+
77+
return "";
78+
}
79+

Tasks/Common/utility-common/package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/Common/utility-common/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"semver": "^5.4.1",
1717
"vso-node-api": "6.0.1-preview",
18-
"vsts-task-lib": "2.0.6"
18+
"vsts-task-lib": "2.0.6",
19+
"vsts-task-tool-lib": "0.4.0"
1920
}
2021
}

Tasks/HelmDeploy/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,63 @@
1010
"loc.input.help.connectionType": "Select a Connection Type.",
1111
"loc.input.label.azureSubscriptionEndpoint": "Azure subscription",
1212
"loc.input.help.azureSubscriptionEndpoint": "Select an Azure subscription, which has your Azure Container Registry.",
13+
"loc.input.label.azureResourceGroup": "Resource group",
14+
"loc.input.help.azureResourceGroup": "Select an Azure Resource Group.",
1315
"loc.input.label.kubernetesCluster": "Kubernetes cluster",
1416
"loc.input.help.kubernetesCluster": "Select an Azure Managed Cluster.",
17+
"loc.input.label.kubernetesServiceEndpoint": "Kubernetes Service Connection",
18+
"loc.input.help.kubernetesServiceEndpoint": "Select a Kubernetes service connection.",
1519
"loc.input.label.namespace": "Namespace",
1620
"loc.input.help.namespace": "Specify K8 namespace to use. Use Tiller namespace in advance section to specify tiller namespace.",
1721
"loc.input.label.command": "Command",
1822
"loc.input.help.command": "Select a helm command.",
19-
"loc.input.label.chart": "Chart",
20-
"loc.input.help.chart": "Name of the chart to install.",
23+
"loc.input.label.chartType": "Chart Type",
24+
"loc.input.help.chartType": "Select how you want to enter chart info. You can either provide name of the chart or folder/file path to the chart.",
25+
"loc.input.label.chartName": "Chart Name",
26+
"loc.input.help.chartName": "Name of the chart to install or upgrade.",
27+
"loc.input.label.chartPath": "Chart Path",
28+
"loc.input.help.chartPath": "Path to the chart to install or upgrade.",
2129
"loc.input.label.version": "Version",
22-
"loc.input.help.version": "Specify the exact chart version to install. If this is not specified, the latest version is installed.",
30+
"loc.input.help.version": "Specify the exact chart version to install. If this is not specified, the latest version is installed. Set the version on the chart to this semver version​",
2331
"loc.input.label.releaseName": "Release Name",
2432
"loc.input.help.releaseName": "Release name. If unspecified, it will autogenerate one for you.",
2533
"loc.input.label.overrideValues": "Set Values",
2634
"loc.input.help.overrideValues": "Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2).",
35+
"loc.input.label.valueFile": "Value File",
36+
"loc.input.help.valueFile": "Specify values in a YAML file or a URL.",
37+
"loc.input.label.destination": "Destination",
38+
"loc.input.help.destination": "Specify values in a YAML file or a URL.",
2739
"loc.input.label.canaryimage": "Use canary image version.",
2840
"loc.input.help.canaryimage": "Use the canary Tiller image. Will install the latest pre-release version of Tiller.",
2941
"loc.input.label.upgradetiller": "Upgrade Tiller",
3042
"loc.input.help.upgradetiller": "Upgrade if Tiller is already installed.",
3143
"loc.input.label.updatedependency": "Update Dependency",
32-
"loc.input.help.updatedependency": "Run helm dependency update before installing the chart.",
44+
"loc.input.help.updatedependency": "Run helm dependency update before installing the chart. Update dependencies from 'requirements.yaml' to dir 'charts/' before packaging",
45+
"loc.input.label.save": "Save",
46+
"loc.input.help.save": "Save packaged chart to local chart repository (default true)​",
47+
"loc.input.label.install": "Install if release not present.",
48+
"loc.input.help.install": "If a release by this name doesn't already exist, run an install​.",
49+
"loc.input.label.recreate": "Recreate Pods.",
50+
"loc.input.help.recreate": "Performs pods restart for the resource if applicable.",
51+
"loc.input.label.resetValues": "Reset Values.",
52+
"loc.input.help.resetValues": "Reset the values to the ones built into the chart.",
53+
"loc.input.label.force": "Force",
54+
"loc.input.help.force": "Force resource update through delete/recreate if needed​",
3355
"loc.input.label.waitForExecution": "Wait",
34-
"loc.input.help.waitForExecution": "Block till command execution completes and Tiller is ready.",
56+
"loc.input.help.waitForExecution": "Block till command execution completes.",
3557
"loc.input.label.arguments": "Arguments",
3658
"loc.input.help.arguments": "Command arguments.",
3759
"loc.input.label.tillernamespace": "Tiller namespace",
3860
"loc.input.help.tillernamespace": "Specify K8 namespace of tiller.",
39-
"loc.messages.HelmNotFound": "Helm not installed on the machine.",
40-
"loc.messages.KubernetesNotFound": "Kubernetes not installed on the machine.",
4161
"loc.messages.CantDownloadAccessProfile": "Cannot download access profile/kube config file for the cluster %s. Reason %s.",
4262
"loc.messages.KubeConfigFilePath": "Kubeconfig file path: %s",
4363
"loc.messages.KubernetesClusterInfo": "Kubernetes cluster Id : %s, kubernetes server version %s, kuberenettes provision state %s",
4464
"loc.messages.KubernetesClusterResourceGroup": "Kubernetes cluster %s, resource group %s.",
4565
"loc.messages.ClusterNotProvisioned": "Observed that the cluster %s is in %s state.",
4666
"loc.messages.ClusterNotFound": "%s cluster does not exists",
4767
"loc.messages.FailedToListClusters": "Failed to list managed clusters in the subscription. %s",
48-
"loc.messages.RetryingRequest": "Retrying request after %s seconds."
68+
"loc.messages.RetryingRequest": "Retrying request after %s seconds.",
69+
"loc.messages.PatternNotFoundInFilePath": "Pattern not found in file path %s.",
70+
"loc.messages.CantResolvePatternInPath": "Can not resolve pattern in file path %s.",
71+
"loc.messages.PatternFoundInPath": "Pattern found in file path %s."
4972
}

Tasks/HelmDeploy/package-lock.json

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/HelmDeploy/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"azure-arm-rest": "file:../../_build/Tasks/Common/azure-arm-rest-1.0.2.tgz",
44
"del": "2.2.0",
55
"js-base64": "2.4.3",
6-
"js-yaml": "3.6.1",
76
"vsts-task-tool-lib": "0.4.0"
87
}
98
}

Tasks/HelmDeploy/src/basecommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ abstract class basecommand {
1111
abstract login(): void;
1212
abstract logout(): void;
1313

14-
constructor() {
15-
this.toolPath = tl.which(this.getTool(), true);
14+
constructor(required: boolean) {
15+
this.toolPath = tl.which(this.getTool(), required);
1616
}
1717

1818
public getToolPath(): string {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
import tl = require('vsts-task-lib/task');
4+
import { AzureAksService } from 'azure-arm-rest/azure-arm-aks-service';
5+
import { AzureRMEndpoint } from 'azure-arm-rest/azure-arm-endpoint';
6+
import { AzureEndpoint, AKSCluster, AKSClusterAccessProfile} from 'azure-arm-rest/azureModels';
7+
8+
// get kubeconfig file content
9+
async function getKubeConfigFromAKS(azureSubscriptionEndpoint: string, resourceGroup: string, clusterName: string) : Promise<string> {
10+
var azureEndpoint: AzureEndpoint = await (new AzureRMEndpoint(azureSubscriptionEndpoint)).getEndpoint();
11+
var aks = new AzureAksService(azureEndpoint);
12+
13+
tl.debug(tl.loc("KubernetesClusterResourceGroup", clusterName, resourceGroup));
14+
15+
var clusterInfo : AKSClusterAccessProfile = await aks.getAccessProfile(resourceGroup, clusterName);
16+
var Base64 = require('js-base64').Base64;
17+
return Base64.decode(clusterInfo.properties.kubeConfig);
18+
}
19+
20+
export async function getKubeConfig(): Promise<string> {
21+
var clusterName : string = tl.getInput("kubernetesCluster", true);
22+
var azureSubscriptionEndpoint : string = tl.getInput("azureSubscriptionEndpoint", true);
23+
var resourceGroup : string = tl.getInput("azureResourceGroup", true);
24+
return getKubeConfigFromAKS(azureSubscriptionEndpoint, resourceGroup, clusterName);
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
import tl = require('vsts-task-lib/task');
4+
5+
export async function getKubeConfig(): Promise<string> {
6+
var kubernetesServiceEndpoint = tl.getInput("kubernetesServiceEndpoint", true);
7+
return tl.getEndpointAuthorizationParameter(kubernetesServiceEndpoint, 'kubeconfig', false);
8+
}

0 commit comments

Comments
 (0)