Skip to content

Commit f2728ba

Browse files
authored
kubectl download fix (#4620) (#4621)
* kubectl download fix * loc fix
1 parent 42b2393 commit f2728ba

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"loc.friendlyName": "Deploy to Kubernetes",
3-
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=846415)",
3+
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=851275)",
44
"loc.description": "Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.",
55
"loc.instanceNameFormat": "kubectl $(command)",
66
"loc.group.displayName.registry": "Container Registry Details",
@@ -37,5 +37,8 @@
3737
"loc.messages.DownloadingClient": "Downloading kubernetes client.",
3838
"loc.messages.CreatingSecret": "Executing create docker-registry %s secret.",
3939
"loc.messages.DeleteSecret": "Executing delete docker-registry %s secret",
40-
"loc.messages.DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified"
40+
"loc.messages.DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified",
41+
"loc.messages.FileNotFoundException": "Can not find file at location: %s",
42+
"loc.messages.DownloadingKubeCtlFromUrl": "Downloading Kubectl from Url: %s",
43+
"loc.messages.DownloadPathForStableTxt": "Download path for stable.txt: %s"
4144
}

Tasks/Kubernetes/src/utilities.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,30 @@ function ensureDirExists(dirPath : string) : void
3535
}
3636

3737
export async function getStableKubectlVersion() : Promise<string> {
38-
var version = "v1.6.2";
38+
var stableVersion = "v1.6.6";
39+
var version;
3940
var stableVersionUrl = "https://storage.googleapis.com/kubernetes-release/release/stable.txt";
40-
var downloadPath = path.join(getTempDirectory(), getCurrentTime().toString());
41+
var downloadPath = path.join(getTempDirectory(), getCurrentTime().toString()+".txt");
4142
await downloadutility.download(stableVersionUrl, downloadPath);
42-
version = fs.readFileSync(downloadPath).toString();
43-
return version.trim();
43+
tl.debug(tl.loc('DownloadPathForStableTxt', downloadPath));
44+
version = fs.readFileSync(downloadPath, "utf8").toString().trim();
45+
if(!version){
46+
version = stableVersion;
47+
}
48+
return version;
4449
}
4550

4651
export async function downloadKubectl(version: string, kubectlPath: string): Promise<void> {
4752
var kubectlURL = getkubectlDownloadURL(version);
53+
tl.debug(tl.loc('DownloadingKubeCtlFromUrl', kubectlURL));
4854
var kubectlPathTmp = kubectlPath+".tmp";
4955
await downloadutility.download(kubectlURL, kubectlPathTmp);
5056
tl.cp(kubectlPathTmp, kubectlPath, "-f");
57+
fs.chmod(kubectlPath, "777");
58+
assertFileExists(kubectlPath);
5159
}
5260

53-
function getkubectlDownloadURL(version: string) : string
54-
{
61+
function getkubectlDownloadURL(version: string) : string {
5562
switch(os.type())
5663
{
5764
case 'Linux':
@@ -65,4 +72,11 @@ function getkubectlDownloadURL(version: string) : string
6572
return util.format("https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/amd64/kubectl.exe", version);
6673

6774
}
75+
}
76+
77+
function assertFileExists(path: string) {
78+
if(!fs.existsSync(path)) {
79+
tl.error(tl.loc('FileNotFoundException', path));
80+
throw new Error(tl.loc('FileNotFoundException', path));
81+
}
6882
}

Tasks/Kubernetes/task.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Kubernetes",
44
"friendlyName": "Deploy to Kubernetes",
55
"description": "Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.",
6-
"helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=846415)",
6+
"helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=851275)",
77
"category": "Deploy",
88
"visibility": [
99
"Build",
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 0,
1515
"Minor": 1,
16-
"Patch": 2
16+
"Patch": 3
1717
},
1818
"demands": [],
1919
"preview": "true",
@@ -199,6 +199,9 @@
199199
"DownloadingClient":"Downloading kubernetes client.",
200200
"CreatingSecret":"Executing create docker-registry %s secret.",
201201
"DeleteSecret": "Executing delete docker-registry %s secret",
202-
"DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified"
202+
"DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified",
203+
"FileNotFoundException": "Can not find file at location: %s",
204+
"DownloadingKubeCtlFromUrl": "Downloading Kubectl from Url: %s",
205+
"DownloadPathForStableTxt": "Download path for stable.txt: %s"
203206
}
204207
}

Tasks/Kubernetes/task.loc.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 0,
1515
"Minor": 1,
16-
"Patch": 2
16+
"Patch": 3
1717
},
1818
"demands": [],
1919
"preview": "true",
@@ -199,6 +199,9 @@
199199
"DownloadingClient": "ms-resource:loc.messages.DownloadingClient",
200200
"CreatingSecret": "ms-resource:loc.messages.CreatingSecret",
201201
"DeleteSecret": "ms-resource:loc.messages.DeleteSecret",
202-
"DockerRegistryConnectionNotSpecified": "ms-resource:loc.messages.DockerRegistryConnectionNotSpecified"
202+
"DockerRegistryConnectionNotSpecified": "ms-resource:loc.messages.DockerRegistryConnectionNotSpecified",
203+
"FileNotFoundException": "ms-resource:loc.messages.FileNotFoundException",
204+
"DownloadingKubeCtlFromUrl": "ms-resource:loc.messages.DownloadingKubeCtlFromUrl",
205+
"DownloadPathForStableTxt": "ms-resource:loc.messages.DownloadPathForStableTxt"
203206
}
204207
}

0 commit comments

Comments
 (0)