Skip to content

Commit

Permalink
don't register cluster on inCluster mode (#599)
Browse files Browse the repository at this point in the history
* don't register cluster on inCluster mode

* wip
  • Loading branch information
oren-codefresh authored Dec 7, 2020
1 parent c9341f7 commit 5b5e661
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/interface/cli/commands/hybrid/init.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const inquirer = require('inquirer');
const colors = require('colors');
const _ = require('lodash');
const { addProxyVariables, detectProxy, keyValueArrayToObject } = require('../../helpers/general');
const { getAllKubeContexts, getKubeContext } = require('../../helpers/kubernetes');
const { getAllKubeContexts, getKubeContext, isInCluster } = require('../../helpers/kubernetes');
const installMonitoring = require('../monitor/install.cmd');
const createClusterCmd = require('../cluster/create.cmd');
const createContext = require('../auth/create-context.cmd');
Expand Down Expand Up @@ -635,6 +635,10 @@ const initCmd = new Command({
},
installationEvent: installationProgress.events.CLUSTER_INTEGRATION_ADDED,
condition: async () => {
if (isInCluster()) {
console.log('Cluster integration was not added , please add it via codefresh create clusters [name] ');
return false;
}
const clusters = await sdk.clusters.list() || [];
if (clusters.find(cluster => cluster.selector === kubeContextName)) {
return false; // cluster already exists
Expand Down
5 changes: 5 additions & 0 deletions lib/interface/cli/helpers/kubernetes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const _getKubeConfig = (kubeconfigPath) => {
return kc;
};

const isInCluster = () => {
return fs.existsSync('/var/run/secrets/kubernetes.io/serviceaccount');
};

const getKubeContext = (kubeconfigPath) => {
const kubeconfig = _getKubeConfig(kubeconfigPath);
return kubeconfig.currentContext;
Expand Down Expand Up @@ -49,4 +53,5 @@ module.exports = {
getKubeContext,
getAllKubeContexts,
getAllNamespaces,
isInCluster,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.73.23",
"version": "0.73.24",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit 5b5e661

Please sign in to comment.