Skip to content

Commit

Permalink
Add cmd to generate image pull secret
Browse files Browse the repository at this point in the history
This requires kubernetes cluster and docker registry integrated with codefresh
  • Loading branch information
Oleg Sucharevich authored Feb 13, 2018
1 parent 7cf9284 commit 9cd2079
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/content/more/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
+++
title = "More"
weight = 40
+++


{{COMMANDS}}
50 changes: 50 additions & 0 deletions lib/interface/cli/commands/imagePullSecret/generate.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const debug = require('debug')('codefresh:cli:generate:imagePullSecret');
const Command = require('../../Command');
const genCmd = require('../root/generate.cmd');
const {
generateImagePullSecret,
} = require('./../../../../logic/api/kubernetes');

const command = new Command({
command: 'image-pull-secret',
parent: genCmd,
description: 'Generate image pull secret on Kubernetes cluster from integrated Docker registry',
usage: `
For Kuberentes cluster to pull an image from your private registry it needs special secret typed as \`kubernetes.io/dockercfg\`.
After this secret been created you can use them in pod template that lives in the same namespace.
You can generate this secret from any integrated Docker registry on your account.
More information about image pull secret can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/`,
webDocs: {
category: 'More',
title: 'Image Pull Secret',
},
builder: (yargs) => {
return yargs
.option('cluster', {
describe: 'cluster name',
required: true,
})
.option('namespace', {
describe: 'namespace name',
default: 'default',
})
.option('registry', {
describe: 'name of Docker registry to generate pull secret from',
required: true,
})
.example('codefresh generate image-pull-secret --cluster cluster --registry cfcr', 'Generate image pull secret');
},
handler: async (argv) => {
const res = await generateImagePullSecret({
cluster: argv.cluster,
namespace: argv.namespace,
registry: argv.registry,
});
console.log(`Image Pull Secret created with name: ${res.name}`);
console.log('Avaliable via kubectl:');
console.log(`kubectl get secret --context ${argv.cluster} --namespace ${argv.namespace} ${res.name}`);
},
});

module.exports = command;

14 changes: 14 additions & 0 deletions lib/interface/cli/commands/root/generate.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Command = require('../../Command');
const yargs = require('yargs');

const get = new Command({
root: true,
command: 'generate',
description: 'Generate resources as Kubernetes image pull secret and Codefresh Registry token',
usage: 'Codefresh generate --help',
handler: async () => {
yargs.showHelp();
},
});

module.exports = get;
25 changes: 25 additions & 0 deletions lib/logic/api/kubernetes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const CFError = require('cf-errors'); // eslint-disable-line
const { sendHttpRequest } = require('./helper');


const generateImagePullSecret = async (data) => {
const body = {
registry: data.registry,
};

const options = {
url: '/api/kubernetes/secrets/imagePullSecret',
method: 'POST',
qs: {
namespace: data.namespace,
selector: data.cluster,
},
body,
};
return sendHttpRequest(options);
};


module.exports = {
generateImagePullSecret,
};
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.8.19",
"version": "0.8.20",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit 9cd2079

Please sign in to comment.