-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cmd to generate image pull secret
This requires kubernetes cluster and docker registry integrated with codefresh
- Loading branch information
Oleg Sucharevich
authored
Feb 13, 2018
1 parent
7cf9284
commit 9cd2079
Showing
5 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
lib/interface/cli/commands/imagePullSecret/generate.cmd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters