Skip to content

Commit bc9ddd4

Browse files
committed
Merge remote-tracking branch 'origin/master' into Localization
2 parents 300bff8 + fa50b3a commit bc9ddd4

Some content is hidden

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

46 files changed

+3524
-1218
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"loc.messages.KubernetesServiceConnectionNotFound": "Kubernetes service connection details not found.",
105105
"loc.messages.ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.",
106106
"loc.messages.SaveSupportedInHelmsV3Only": "Save chart to Azure Container Registry is only supported in Helms V3.",
107+
"loc.messages.PackageSupportedInHelmsV37Only": "Helm package to Azure Container Registry is only supported in Helms V3.7+.",
107108
"loc.messages.OutputVariableDataSizeExceeded": "Output variable not set as Helm command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s",
108109
"loc.messages.KubeloginFailed": "Kubelogin authentication failed. Exception: %s"
109110
}

Tasks/HelmDeployV1/Tests/L0.ts

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as ttm from 'azure-pipelines-task-lib/mock-test';
55
import * as shared from './TestShared';
66
import * as tl from 'azure-pipelines-task-lib';
77

8-
describe("HelmDeployV0 Suite", function () {
8+
describe("HelmDeployV1 Suite", function () {
99
this.timeout(30000);
1010

1111
before(async () => {
@@ -17,12 +17,19 @@ describe("HelmDeployV0 Suite", function () {
1717
delete process.env[shared.TestEnvVars.valueFile];
1818
delete process.env[shared.TestEnvVars.overrideValues];
1919
delete process.env[shared.TestEnvVars.updatedependency];
20+
delete process.env[shared.TestEnvVars.caFile];
21+
delete process.env[shared.TestEnvVars.certFile];
22+
delete process.env[shared.TestEnvVars.insecureSkipTlsVerify];
23+
delete process.env[shared.TestEnvVars.keyFile];
24+
delete process.env[shared.TestEnvVars.plainHttp];
2025
delete process.env[shared.isHelmV3];
26+
delete process.env[shared.isHelmV37];
2127
delete process.env[shared.TestEnvVars.releaseName];
2228
delete process.env[shared.TestEnvVars.waitForExecution];
2329
delete process.env[shared.TestEnvVars.arguments];
2430
delete process.env[shared.TestEnvVars.chartName];
2531
delete process.env[shared.TestEnvVars.chartPath];
32+
delete process.env[shared.TestEnvVars.chartPathForACR];
2633
delete process.env[shared.TestEnvVars.connectionType];
2734
delete process.env[shared.TestEnvVars.command];
2835
delete process.env[shared.TestEnvVars.chartType];
@@ -218,49 +225,10 @@ describe("HelmDeployV0 Suite", function () {
218225
process.env[shared.TestEnvVars.chartPath] = shared.testChartPath;
219226
process.env[shared.TestEnvVars.destination] = shared.testDestinationPath;
220227
process.env[shared.TestEnvVars.failOnStderr] = "false";
221-
process.env[shared.isHelmV3] = "true";
228+
process.env[shared.isHelmV37] = "true";
222229

223230
await tr.runAsync();
224231
assert(tr.stdout.indexOf(`Successfully packaged chart and saved it to: ${shared.testDestinationPath}/testChartName.tgz`) != -1, "Chart should have been successfully packaged");
225232
assert(tr.succeeded, "task should have succeeded");
226233
});
227-
228-
it("Run successfully with Helm save command (version 3)", async function () {
229-
const tp = path.join(__dirname, "TestSetup.js");
230-
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
231-
process.env[shared.TestEnvVars.command] = shared.Commands.save;
232-
process.env[shared.TestEnvVars.connectionType] = shared.ConnectionTypes.None;
233-
process.env[shared.TestEnvVars.chartPathForACR] = shared.testChartPathForACR;
234-
process.env[shared.TestEnvVars.chartNameForACR] = shared.testChartNameForACR;
235-
process.env[shared.TestEnvVars.azureSubscriptionEndpointForACR] = shared.testAzureSubscriptionEndpointForACR;
236-
process.env[shared.testEndpointAuthVar] = "ServicePrincipal";
237-
process.env[shared.TestEnvVars.azureResourceGroupForACR] = shared.testAzureResourceGroupForACR;
238-
process.env[shared.TestEnvVars.azureContainerRegistry] = shared.testAzureContainerRegistry;
239-
process.env[shared.TestEnvVars.failOnStderr] = "false";
240-
process.env[shared.isHelmV3] = "true";
241-
242-
await tr.runAsync();
243-
assert(tr.stdout.indexOf("Successfully saved the helm chart to local registry cache.") != -1, "Chart should have been successfully saved to local registry cache.");
244-
assert(tr.stdout.indexOf(`Successfully logged in to ${process.env[shared.TestEnvVars.azureContainerRegistry]}.`) != -1, "Azure container registry login should have been successful.");
245-
assert(tr.stdout.indexOf("Successfully pushed to the chart to container registry.") != -1, "Chart should have been successfully pushed to container registry.");
246-
assert(tr.stdout.indexOf("Successfully removed the chart from local cache.") != -1, "Chart should have been successfully removed from local cache.");
247-
assert(tr.succeeded, "task should have succeeded");
248-
});
249-
250-
it("Helm same should fail (version 2)", async function () {
251-
const tp = path.join(__dirname, "TestSetup.js");
252-
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
253-
process.env[shared.TestEnvVars.command] = shared.Commands.save;
254-
process.env[shared.TestEnvVars.connectionType] = shared.ConnectionTypes.None;
255-
process.env[shared.TestEnvVars.chartPathForACR] = shared.testChartPathForACR;
256-
process.env[shared.TestEnvVars.chartNameForACR] = shared.testChartNameForACR;
257-
process.env[shared.TestEnvVars.azureSubscriptionEndpointForACR] = shared.testAzureSubscriptionEndpointForACR;
258-
process.env[shared.TestEnvVars.azureResourceGroupForACR] = shared.testAzureResourceGroupForACR;
259-
process.env[shared.TestEnvVars.azureContainerRegistry] = shared.testAzureContainerRegistry;
260-
process.env[shared.TestEnvVars.failOnStderr] = "false";
261-
262-
await tr.runAsync();
263-
assert(tr.failed, "task should have failed");
264-
assert(tr.stdout.indexOf("loc_mock_SaveSupportedInHelmsV3Only") != -1, "Chart save should have failed when helm version is not 3.");
265-
})
266-
});
234+
});

Tasks/HelmDeployV1/Tests/TestSetup.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ tr.setInput("destination", process.env[shared.TestEnvVars.destination] || "");
4646
tr.setInput("canaryimage", process.env[shared.TestEnvVars.canaryimage] || "");
4747
tr.setInput("upgradetiller", process.env[shared.TestEnvVars.upgradetiller] || "");
4848
tr.setInput("updatedependency", process.env[shared.TestEnvVars.updatedependency] || "");
49+
tr.setInput("caFile", process.env[shared.TestEnvVars.caFile] || "");
50+
tr.setInput("certFile", process.env[shared.TestEnvVars.certFile] || "");
51+
tr.setInput("insecureSkipTlsVerify", process.env[shared.TestEnvVars.insecureSkipTlsVerify] || "");
52+
tr.setInput("keyFile", process.env[shared.TestEnvVars.keyFile] || "");
53+
tr.setInput("plainHttp", process.env[shared.TestEnvVars.plainHttp] || "");
4954
tr.setInput("save", process.env[shared.TestEnvVars.save] || "");
5055
tr.setInput("install", process.env[shared.TestEnvVars.install] || "");
5156
tr.setInput("recreate", process.env[shared.TestEnvVars.recreate] || "");
@@ -224,7 +229,7 @@ if (process.env[shared.TestEnvVars.command] === shared.Commands.package) {
224229
helmPackageCommand = helmPackageCommand.concat(" --dependency-update");
225230

226231
if (process.env[shared.TestEnvVars.save]) {
227-
if (process.env[shared.isHelmV3])
232+
if (process.env[shared.isHelmV37])
228233
helmPackageCommand = helmPackageCommand.concat(" --save");
229234
}
230235

@@ -246,7 +251,12 @@ if (process.env[shared.TestEnvVars.command] === shared.Commands.package) {
246251
}
247252

248253
const helmVersionCommand = "helm version --client --short";
249-
if (process.env[shared.isHelmV3]) {
254+
if (process.env[shared.isHelmV37]) {
255+
a.exec[helmVersionCommand] = {
256+
"code": 0,
257+
"stdout": "v3.7.0+ge29ce2a"
258+
};
259+
} else if (process.env[shared.isHelmV3]) {
250260
a.exec[helmVersionCommand] = {
251261
"code": 0,
252262
"stdout": "v3.2.1+ge29ce2a"
@@ -294,8 +304,8 @@ a.exec[kubectlClusterInfo] = {
294304
"stdout": `Kubernetes master is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443 \nhealthmodel-replicaset-service is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/healthmodel-replicaset-service/proxy \nCoreDNS is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy \nkubernetes-dashboard is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy \nMetrics-server is running at https://shigupt-cluster-dns-7489360e.hcp.southindia.azmk8s.io:443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy\n\nTo further debug and diagnose cluster problems, use "kubectl cluster-info dump".\n`
295305
}
296306

297-
const helmSaveCommand = `helm chart${formatDebugFlag()} save ${process.env[shared.TestEnvVars.chartPathForACR]} ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}`;
298-
a.exec[helmSaveCommand] = {
307+
const helmPackageCommand = `helm package${formatDebugFlag()} ${process.env[shared.TestEnvVars.chartPathForACR]} ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}`;
308+
a.exec[helmPackageCommand] = {
299309
"code": 0,
300310
"stdout": `ref: ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}:0.1.0 \n Successfully saved the helm chart to local registry cache.`
301311
}
@@ -306,18 +316,12 @@ a.exec[helmRegistryLoginCommand] = {
306316
"stdout": `Successfully logged in to ${process.env[shared.TestEnvVars.azureContainerRegistry]}.`
307317
};
308318

309-
const helmChartPushCommand = `helm chart${formatDebugFlag()} push ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}:0.1.0`;
310-
a.exec[helmChartPushCommand] = {
319+
const helmPushCommand = `helm push${formatDebugFlag()} ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}:0.1.0`;
320+
a.exec[helmPushCommand] = {
311321
"code": 0,
312322
"stdout": "Successfully pushed to the chart to container registry."
313323
}
314324

315-
const helmChartRemoveCommand = `helm chart${formatDebugFlag()} remove ${process.env[shared.TestEnvVars.azureContainerRegistry]}/helm/${process.env[shared.TestEnvVars.chartNameForACR]}:0.1.0`;
316-
a.exec[helmChartRemoveCommand] = {
317-
"code": 0,
318-
"stdout": "Successfully removed the chart from local cache."
319-
}
320-
321325
tr.setAnswers(<any>a);
322326
tr.registerMock("azure-pipelines-task-lib/toolrunner", require("azure-pipelines-task-lib/mock-toolrunner"));
323327

Tasks/HelmDeployV1/Tests/TestShared.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export let TestEnvVars = {
2424
canaryimage: "__canaryimage__",
2525
upgradetiller: "__upgradetiller__",
2626
updatedependency: "__updatedependency__",
27+
caFile: "__caFile__",
28+
certFile: "__certFile__",
29+
insecureSkipTlsVerify: "__insecureSkipTlsVerify__",
30+
keyFile: "__keyFile__",
31+
plainHttp: "__plainHttp__",
2732
save: "__save__",
2833
install: "__install__",
2934
recreate: "__recreate__",
@@ -41,7 +46,7 @@ export let Commands = {
4146
install: "install",
4247
upgrade: "upgrade",
4348
package: "package",
44-
save: "save",
49+
push: "push",
4550
init: "init"
4651
};
4752

@@ -66,6 +71,7 @@ export const testChartPath = "test/testChartPath";
6671
export const testChartVersion = "1.1.1";
6772
export const testReleaseName = "testReleaseName";
6873
export const isHelmV3 = "__isHelmV3__";
74+
export const isHelmV37 = "__isHelmV37__";
6975
export const testNamespace = "testNamespace";
7076
export const testDestinationPath = "testDestinationPath";
7177
export const testChartNameForACR = "testChartNameForACR";

Tasks/HelmDeployV1/src/helm.ts

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ function getClusterType(): any {
4141

4242
function isKubConfigSetupRequired(command: string): boolean {
4343
var connectionType = tl.getInput("connectionType", true);
44-
return command !== "package" && command !== "save" && connectionType !== "None";
44+
return command !== "package" && connectionType !== "None";
4545
}
4646

4747
function isKubConfigLogoutRequired(command: string): boolean {
4848
var connectionType = tl.getInput("connectionType", true);
49-
return command !== "package" && command !== "save" && command !== "login" && connectionType !== "None";
49+
return command !== "package" && command !== "login" && connectionType !== "None";
5050
}
5151

5252
// get kubeconfig file path
@@ -60,23 +60,6 @@ async function getKubeConfigFile(): Promise<string> {
6060
});
6161
}
6262

63-
async function runHelmSaveCommand(helmCli: helmcli, kubectlCli: kubernetescli, failOnStderr: boolean): Promise<void> {
64-
if (!helmCli.isHelmV3()) {
65-
//helm chart save and push commands are only supported in Helms v3
66-
throw new Error(tl.loc("SaveSupportedInHelmsV3Only"));
67-
}
68-
process.env.HELM_EXPERIMENTAL_OCI="1";
69-
await runHelm(helmCli, "saveChart", kubectlCli, failOnStderr);
70-
helmCli.resetArguments();
71-
const chartRef = getHelmChartRef(tl.getVariable("helmOutput"));
72-
tl.setVariable("helmChartRef", chartRef);
73-
await runHelm(helmCli, "registry", kubectlCli, false);
74-
helmCli.resetArguments();
75-
await runHelm(helmCli, "pushChart", kubectlCli, failOnStderr);
76-
helmCli.resetArguments();
77-
await runHelm(helmCli, "removeChart", kubectlCli, failOnStderr);
78-
}
79-
8063
async function run() {
8164
var command = tl.getInput("command", true).toLowerCase();
8265
var connectionType = tl.getInput("connectionType", true);
@@ -119,7 +102,7 @@ async function run() {
119102

120103
console.log("##vso[telemetry.publish area=%s;feature=%s]%s",
121104
"TaskEndpointId",
122-
"HelmDeployV0",
105+
"HelmDeployV1",
123106
JSON.stringify(telemetry));
124107

125108
try {
@@ -130,9 +113,6 @@ async function run() {
130113
case "logout":
131114
kubectlCli.unsetKubeConfigEnvVariable();
132115
break;
133-
case "save":
134-
await runHelmSaveCommand(helmCli, kubectlCli, failOnStderr);
135-
break;
136116
default:
137117
await runHelm(helmCli, command, kubectlCli, failOnStderr);
138118
}
@@ -154,10 +134,8 @@ async function runHelm(helmCli: helmcli, command: string, kubectlCli: kubernetes
154134
"init": "./helmcommands/helminit",
155135
"install": "./helmcommands/helminstall",
156136
"package": "./helmcommands/helmpackage",
157-
"pushChart": "./helmcommands/helmchartpush",
137+
"push": "./helmcommands/helmpush",
158138
"registry": "./helmcommands/helmregistrylogin",
159-
"removeChart": "./helmcommands/helmchartremove",
160-
"saveChart": "./helmcommands/helmchartsave",
161139
"upgrade": "./helmcommands/helmupgrade"
162140
}
163141

@@ -167,11 +145,7 @@ async function runHelm(helmCli: helmcli, command: string, kubectlCli: kubernetes
167145
}
168146

169147
//set command
170-
if (command === "saveChart" || command === "pushChart" || command === "removeChart") {
171-
helmCli.setCommand("chart");
172-
} else {
173-
helmCli.setCommand(command);
174-
}
148+
helmCli.setCommand(command);
175149

176150
// add arguments
177151
commonCommandOptions.addArguments(helmCli);

Tasks/HelmDeployV1/src/helmcli.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ export default class helmcli extends basecommand {
6464
return true;
6565
return false;
6666
}
67+
68+
public isHelmV37Plus(): boolean {
69+
if (!this.helmVersion)
70+
this.helmVersion = this.getHelmVersion().stdout;
71+
tl.debug("Helm version is " + this.helmVersion);
72+
// Parse the version string
73+
const version = this.helmVersion.match(/^v(\d+)\.(\d+)\.(\d+)/);
74+
if (version) {
75+
const major = parseInt(version[1]);
76+
const minor = parseInt(version[2]);
77+
const patch = parseInt(version[3]);
78+
79+
// Compare with v3.7.0
80+
if (major > 3 || (major === 3 && (minor > 7 || (minor === 7 && patch >= 0)))) {
81+
return true;
82+
}
83+
}
84+
return false;
85+
}
6786

6887
public execHelmCommand(silent?: boolean): tr.IExecSyncResult {
6988
var command = this.createCommand();

Tasks/HelmDeployV1/src/helmcommands/helmchartremove.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

Tasks/HelmDeployV1/src/helmcommands/helmchartsave.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

Tasks/HelmDeployV1/src/helmcommands/helmpackage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function addArguments(helmCli: helmcli): Promise<void> {
1717
helmCli.addArgument("--dependency-update");
1818
}
1919

20-
if (save && !helmCli.isHelmV3()) {
20+
if (save && !helmCli.isHelmV37Plus()) {
2121
helmCli.addArgument("--save ");
2222
}
2323

0 commit comments

Comments
 (0)