TsuyoshiUshio / KubernetesTask

Kubernetes Task for Visual Studio Team Services
34 stars 14 forks source link

Fix: ConfigFile not found #10

Closed TsuyoshiUshio closed 7 years ago

TsuyoshiUshio commented 7 years ago

The error only happens when I use kube apply task without downloading kubectl. The error happnens at varidation of tl.checkPath(this.configfile, 'configfile'); after the kubectl apply task, I check if these is .kubeconfig or not. It exists.

I guess the problem is asyncronous related problem. That is why, I move the sesion of the writing .kubeconfig file and make it Sync method. Now it works.

TsuyoshiUshio commented 7 years ago

Hi @rakelkar,

https://github.com/TsuyoshiUshio/KubernetesTask/issues/8

I noticed that the problem only happens when I use kubectl apply task without downloading kubectl binary. I guess the problem is asyncronous related problem between write .kubeconfig file and tl.checkPath validation. That is why, I move the sesion of the writing .kubeconfig file and make it Sync method. Now it works.

Since it might not be a cool solution. I quite new to node. If you have any cool refactoring idea, please let me know.

TsuyoshiUshio commented 7 years ago

Ahh. I understand. we can't use await fs.writeFile(this.configfile, this.kubeconfig);. it is converted into,,,

        return __awaiter(this, void 0, void 0, function* () {
            try {
                tl.debug("cwd(): " + tl.cwd());
                tl.debug("configfile: " + this.configfile);
                yield fs.writeFile(this.configfile, this.kubeconfig);
                this.kubectl.arg('--kubeconfig').arg(this.configfile);
                tl.debug("settings kubectl exec perms");
                tl.checkPath(this.kubectlbinary, 'kubectlBinary');
                tl.checkPath(this.configfile, 'configFile');
                yield this.kubectl.exec();
                tl.setResult(tl.TaskResult.Succeeded, "kubectl works.");
                return;
            }
            catch (err) {
                tl.setResult(tl.TaskResult.Failed, err);
            }
        });

It is just added yield. yield fs.writeFile but it won't wait it. We need wrap the write file.

http://stackoverflow.com/questions/35673866/how-to-use-typescript-async-await-with-promise-in-node-js-fs-module

For this reason, writeSync might be a right solution. Since is not a big wait time.

rakelkar commented 7 years ago

Nice catch!

TsuyoshiUshio commented 7 years ago

Ok! I will marge this. :)