Skip to content

Commit

Permalink
kubectl download fix (#4620) (#4621)
Browse files Browse the repository at this point in the history
* kubectl download fix

* loc fix
  • Loading branch information
jikuma authored Jun 23, 2017
1 parent 42b2393 commit f2728ba
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loc.friendlyName": "Deploy to Kubernetes",
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=846415)",
"loc.helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=851275)",
"loc.description": "Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.",
"loc.instanceNameFormat": "kubectl $(command)",
"loc.group.displayName.registry": "Container Registry Details",
Expand Down Expand Up @@ -37,5 +37,8 @@
"loc.messages.DownloadingClient": "Downloading kubernetes client.",
"loc.messages.CreatingSecret": "Executing create docker-registry %s secret.",
"loc.messages.DeleteSecret": "Executing delete docker-registry %s secret",
"loc.messages.DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified"
"loc.messages.DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified",
"loc.messages.FileNotFoundException": "Can not find file at location: %s",
"loc.messages.DownloadingKubeCtlFromUrl": "Downloading Kubectl from Url: %s",
"loc.messages.DownloadPathForStableTxt": "Download path for stable.txt: %s"
}
26 changes: 20 additions & 6 deletions Tasks/Kubernetes/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,30 @@ function ensureDirExists(dirPath : string) : void
}

export async function getStableKubectlVersion() : Promise<string> {
var version = "v1.6.2";
var stableVersion = "v1.6.6";
var version;
var stableVersionUrl = "https://storage.googleapis.com/kubernetes-release/release/stable.txt";
var downloadPath = path.join(getTempDirectory(), getCurrentTime().toString());
var downloadPath = path.join(getTempDirectory(), getCurrentTime().toString()+".txt");
await downloadutility.download(stableVersionUrl, downloadPath);
version = fs.readFileSync(downloadPath).toString();
return version.trim();
tl.debug(tl.loc('DownloadPathForStableTxt', downloadPath));
version = fs.readFileSync(downloadPath, "utf8").toString().trim();
if(!version){
version = stableVersion;
}
return version;
}

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

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

}
}

function assertFileExists(path: string) {
if(!fs.existsSync(path)) {
tl.error(tl.loc('FileNotFoundException', path));
throw new Error(tl.loc('FileNotFoundException', path));
}
}
9 changes: 6 additions & 3 deletions Tasks/Kubernetes/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Kubernetes",
"friendlyName": "Deploy to Kubernetes",
"description": "Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.",
"helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=846415)",
"helpMarkDown": "[More Information](https://go.microsoft.com/fwlink/?linkid=851275)",
"category": "Deploy",
"visibility": [
"Build",
Expand All @@ -13,7 +13,7 @@
"version": {
"Major": 0,
"Minor": 1,
"Patch": 2
"Patch": 3
},
"demands": [],
"preview": "true",
Expand Down Expand Up @@ -199,6 +199,9 @@
"DownloadingClient":"Downloading kubernetes client.",
"CreatingSecret":"Executing create docker-registry %s secret.",
"DeleteSecret": "Executing delete docker-registry %s secret",
"DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified"
"DockerRegistryConnectionNotSpecified": "Docker Registry connection details not specified",
"FileNotFoundException": "Can not find file at location: %s",
"DownloadingKubeCtlFromUrl": "Downloading Kubectl from Url: %s",
"DownloadPathForStableTxt": "Download path for stable.txt: %s"
}
}
7 changes: 5 additions & 2 deletions Tasks/Kubernetes/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 0,
"Minor": 1,
"Patch": 2
"Patch": 3
},
"demands": [],
"preview": "true",
Expand Down Expand Up @@ -199,6 +199,9 @@
"DownloadingClient": "ms-resource:loc.messages.DownloadingClient",
"CreatingSecret": "ms-resource:loc.messages.CreatingSecret",
"DeleteSecret": "ms-resource:loc.messages.DeleteSecret",
"DockerRegistryConnectionNotSpecified": "ms-resource:loc.messages.DockerRegistryConnectionNotSpecified"
"DockerRegistryConnectionNotSpecified": "ms-resource:loc.messages.DockerRegistryConnectionNotSpecified",
"FileNotFoundException": "ms-resource:loc.messages.FileNotFoundException",
"DownloadingKubeCtlFromUrl": "ms-resource:loc.messages.DownloadingKubeCtlFromUrl",
"DownloadPathForStableTxt": "ms-resource:loc.messages.DownloadPathForStableTxt"
}
}

0 comments on commit f2728ba

Please sign in to comment.