From ca316659e580d3427e62dec93d59dc19c8e158da Mon Sep 17 00:00:00 2001 From: roi-codefresh <60569147+roi-codefresh@users.noreply.github.com> Date: Thu, 25 Jun 2020 07:28:09 +0300 Subject: [PATCH] Saas 7627 - run in cluster mode (#515) --- codefresh.yml | 11 ++++++--- lib/interface/cli/helpers/kubernetes.js | 32 +++++++++++++------------ package.json | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/codefresh.yml b/codefresh.yml index 1c9845f9f..13fa02510 100644 --- a/codefresh.yml +++ b/codefresh.yml @@ -34,11 +34,16 @@ steps: image-name: codefresh/cli tag: ${{CF_BRANCH_TAG_NORMALIZED}} - push_to_registry_revision: - title: "Pushing image tagged with revision to registry" + push_step: type: push + tag: '${{CF_SHORT_REVISION}}' candidate: ${{build_step}} - tag: ${{CF_SHORT_REVISION}} + scale: + push_to_dockerhub: + registry: dockerhub + title: "push to dockerhub" + push_to_gcr: + title: "push to gcr" execute_release_pipeline: title: "Execute release pipeline in case version was changed" diff --git a/lib/interface/cli/helpers/kubernetes.js b/lib/interface/cli/helpers/kubernetes.js index cf1ab0459..71aa0afd4 100644 --- a/lib/interface/cli/helpers/kubernetes.js +++ b/lib/interface/cli/helpers/kubernetes.js @@ -1,22 +1,28 @@ const path = require('path'); +const fs = require('fs'); const { KubeConfig, Client } = require('kubernetes-client'); const Request = require('kubernetes-client/backends/request'); const _ = require('lodash'); +const { homedir } = require('os'); + +const _getKubeConfig = (kubeconfigPath) => { + const kc = new KubeConfig(); + const kubePath = kubeconfigPath || process.env.KUBECONFIG || path.join(homedir(), '.kube', 'config'); + if (fs.existsSync(kubePath)) { + kc.loadFromFile(kubePath); + } else { + kc.loadFromCluster(); + } + + return kc; +} const getKubeContext = (kubeconfigPath) => { - // eslint-disable-next-line global-require - const homedir = require('os').homedir(); - const kubePath = kubeconfigPath || process.env.KUBECONFIG || path.join(homedir, '.kube', 'config'); - const kubeconfig = new KubeConfig(); - kubeconfig.loadFromFile(kubePath); + const kubeconfig = _getKubeConfig(kubeconfigPath); return kubeconfig.currentContext; }; const getAllKubeContexts = (kubeconfigPath) => { - // eslint-disable-next-line global-require - const homedir = require('os').homedir(); - const kubePath = kubeconfigPath || process.env.KUBECONFIG || path.join(homedir, '.kube', 'config'); - const kubeconfig = new KubeConfig(); - kubeconfig.loadFromFile(kubePath); + const kubeconfig = _getKubeConfig(kubeconfigPath); const { contexts } = kubeconfig; if (contexts) { return contexts.reduce((acc, curr) => { @@ -26,11 +32,7 @@ const getAllKubeContexts = (kubeconfigPath) => { } }; const getAllNamespaces = async (kubeconfigPath, kubeContextName) => { - // eslint-disable-next-line global-require - const homedir = require('os').homedir(); - const kubePath = kubeconfigPath || process.env.KUBECONFIG || path.join(homedir, '.kube', 'config'); - const kubeconfig = new KubeConfig(); - kubeconfig.loadFromFile(kubePath); + const kubeconfig = _getKubeConfig(kubeconfigPath); kubeconfig.setCurrentContext(kubeContextName); const backend = new Request({ kubeconfig }); const client = new Client({ backend, version: 1.13 }); diff --git a/package.json b/package.json index 020af4e34..a63256b69 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.69.0", + "version": "0.69.2", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,