-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kops create secret dockerconfig
feature
#3087
Merged
k8s-github-robot
merged 8 commits into
kubernetes:master
from
blakebarnett:bdb/add_node_docker_config_secret
Aug 4, 2017
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
60dc81f
Add `kops create secret nodedockercfg` feature
760311f
Kubelet $HOME is /var/lib/kubelet
7946f08
symlink to /root/.docker/config.json for hooks
bd779e7
Move task up so so it applies to all nodes
4d9c69c
Add documentation and update text fixture
e8c6e50
Don't error when no docker config is supplied
4f95fe4
Incorporate review feedback
e093702
Don't error if the dockerconfig isn't present
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,124 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/kops/cmd/kops/util" | ||
"k8s.io/kops/pkg/apis/kops/registry" | ||
"k8s.io/kops/upup/pkg/fi" | ||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates" | ||
"k8s.io/kubernetes/pkg/util/i18n" | ||
) | ||
|
||
var ( | ||
create_secret_dockerconfig_long = templates.LongDesc(i18n.T(` | ||
Create a new docker config, and store it in the state store. | ||
Used to configure docker on each master or node (ie. for auth) | ||
Use update to modify it, this command will only create a new entry.`)) | ||
|
||
create_secret_dockerconfig_example = templates.Examples(i18n.T(` | ||
# Create an new docker config. | ||
kops create secret dockerconfig -f /path/to/docker/config.json \ | ||
--name k8s-cluster.example.com --state s3://example.com | ||
`)) | ||
|
||
create_secret_dockerconfig_short = i18n.T(`Create a docker config.`) | ||
) | ||
|
||
type CreateSecretDockerConfigOptions struct { | ||
ClusterName string | ||
DockerConfigPath string | ||
} | ||
|
||
func NewCmdCreateSecretDockerConfig(f *util.Factory, out io.Writer) *cobra.Command { | ||
options := &CreateSecretDockerConfigOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "dockerconfig", | ||
Short: create_secret_dockerconfig_short, | ||
Long: create_secret_dockerconfig_long, | ||
Example: create_secret_dockerconfig_example, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 0 { | ||
exitWithError(fmt.Errorf("syntax: -f <DockerConfigPath>")) | ||
} | ||
|
||
err := rootCommand.ProcessArgs(args[0:]) | ||
if err != nil { | ||
exitWithError(err) | ||
} | ||
|
||
options.ClusterName = rootCommand.ClusterName() | ||
|
||
err = RunCreateSecretDockerConfig(f, os.Stdout, options) | ||
if err != nil { | ||
exitWithError(err) | ||
} | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&options.DockerConfigPath, "", "f", "", "Path to docker config JSON file") | ||
|
||
return cmd | ||
} | ||
|
||
func RunCreateSecretDockerConfig(f *util.Factory, out io.Writer, options *CreateSecretDockerConfigOptions) error { | ||
if options.DockerConfigPath == "" { | ||
return fmt.Errorf("docker config path is required (use -f)") | ||
} | ||
secret, err := fi.CreateSecret() | ||
if err != nil { | ||
return fmt.Errorf("error creating docker config secret: %v", err) | ||
} | ||
|
||
cluster, err := GetCluster(f, options.ClusterName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
secretStore, err := registry.SecretStore(cluster) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
data, err := ioutil.ReadFile(options.DockerConfigPath) | ||
if err != nil { | ||
return fmt.Errorf("error reading docker config %v: %v", options.DockerConfigPath, err) | ||
} | ||
|
||
var parsedData map[string]interface{} | ||
err = json.Unmarshal(data, &parsedData) | ||
if err != nil { | ||
return fmt.Errorf("Unable to parse JSON %v: %v", options.DockerConfigPath, err) | ||
} | ||
|
||
secret.Data = data | ||
|
||
_, _, err = secretStore.GetOrCreateSecret("dockerconfig", secret) | ||
if err != nil { | ||
return fmt.Errorf("error adding docker config secret: %v", err) | ||
} | ||
|
||
return nil | ||
} |
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
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,48 @@ | ||
|
||
<!--- This file is automatically generated by make gen-cli-docs; changes should be made in the go CLI command code (under cmd/kops) --> | ||
|
||
## kops create secret dockerconfig | ||
|
||
Create a docker config. | ||
|
||
### Synopsis | ||
|
||
|
||
Create a new docker config, and store it in the state store. Used to configure docker on each master or node (ie. for auth) Use update to modify it, this command will only create a new entry. | ||
|
||
``` | ||
kops create secret dockerconfig | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Create an new docker config. | ||
kops create secret dockerconfig -f /path/to/docker/config.json \ | ||
--name k8s-cluster.example.com --state s3://example.com | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-f, -- string Path to docker config JSON file | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--alsologtostderr log to standard error as well as files | ||
--config string config file (default is $HOME/.kops.yaml) | ||
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0) | ||
--log_dir string If non-empty, write log files in this directory | ||
--logtostderr log to standard error instead of files (default false) | ||
--name string Name of cluster | ||
--state string Location of state storage | ||
--stderrthreshold severity logs at or above this threshold go to stderr (default 2) | ||
-v, --v Level log level for V logs | ||
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging | ||
``` | ||
|
||
### SEE ALSO | ||
* [kops create secret](kops_create_secret.md) - Create a secret. | ||
|
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
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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
contents: | | ||
DAEMON_ARGS="--feature-gates=AllowExtTrafficLocalEndpoints=false,ExperimentalCriticalPodAnnotation=true --node-labels=kubernetes.io/role=node,node-role.kubernetes.io/node= --cni-bin-dir=/opt/cni/bin/ --cni-conf-dir=/etc/cni/net.d/ --network-plugin-dir=/opt/cni/bin/" | ||
HOME="/root" | ||
path: /etc/sysconfig/kubelet | ||
type: file |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Came across this with the ~/.aws directory as well - it is a pain...
Wondering if we should give kubelet etc their own directories, but if we do we can just change it when we need it. Thanks for fixing :-)