Make 'docker-email' optional on dockercfg secrets

It is not required for most username/password registries.
parent 6d9e2afe
...@@ -126,7 +126,7 @@ var ( ...@@ -126,7 +126,7 @@ var (
$ docker login DOCKER_REGISTRY_SERVER --username=DOCKER_USER --password=DOCKER_PASSWORD --email=DOCKER_EMAIL'. $ docker login DOCKER_REGISTRY_SERVER --username=DOCKER_USER --password=DOCKER_PASSWORD --email=DOCKER_EMAIL'.
That produces a ~/.dockercfg file that is used by subsequent 'docker push' and 'docker pull' commands to That produces a ~/.dockercfg file that is used by subsequent 'docker push' and 'docker pull' commands to
authenticate to the registry. authenticate to the registry. The email address is optional.
When creating applications, you may have a Docker registry that requires authentication. In order for the When creating applications, you may have a Docker registry that requires authentication. In order for the
nodes to pull images on your behalf, they have to have the credentials. You can provide this information nodes to pull images on your behalf, they have to have the credentials. You can provide this information
...@@ -158,7 +158,6 @@ func NewCmdCreateSecretDockerRegistry(f cmdutil.Factory, cmdOut io.Writer) *cobr ...@@ -158,7 +158,6 @@ func NewCmdCreateSecretDockerRegistry(f cmdutil.Factory, cmdOut io.Writer) *cobr
cmd.Flags().String("docker-password", "", i18n.T("Password for Docker registry authentication")) cmd.Flags().String("docker-password", "", i18n.T("Password for Docker registry authentication"))
cmd.MarkFlagRequired("docker-password") cmd.MarkFlagRequired("docker-password")
cmd.Flags().String("docker-email", "", i18n.T("Email for Docker registry")) cmd.Flags().String("docker-email", "", i18n.T("Email for Docker registry"))
cmd.MarkFlagRequired("docker-email")
cmd.Flags().String("docker-server", "https://index.docker.io/v1/", i18n.T("Server location for Docker registry")) cmd.Flags().String("docker-server", "https://index.docker.io/v1/", i18n.T("Server location for Docker registry"))
cmdutil.AddInclude3rdPartyFlags(cmd) cmdutil.AddInclude3rdPartyFlags(cmd)
return cmd return cmd
......
...@@ -31,7 +31,7 @@ type SecretForDockerRegistryGeneratorV1 struct { ...@@ -31,7 +31,7 @@ type SecretForDockerRegistryGeneratorV1 struct {
Name string Name string
// Username for registry (required) // Username for registry (required)
Username string Username string
// Email for registry (required) // Email for registry (optional)
Email string Email string
// Password for registry (required) // Password for registry (required)
Password string Password string
...@@ -91,7 +91,7 @@ func (s SecretForDockerRegistryGeneratorV1) ParamNames() []GeneratorParam { ...@@ -91,7 +91,7 @@ func (s SecretForDockerRegistryGeneratorV1) ParamNames() []GeneratorParam {
return []GeneratorParam{ return []GeneratorParam{
{"name", true}, {"name", true},
{"docker-username", true}, {"docker-username", true},
{"docker-email", true}, {"docker-email", false},
{"docker-password", true}, {"docker-password", true},
{"docker-server", true}, {"docker-server", true},
} }
...@@ -105,9 +105,6 @@ func (s SecretForDockerRegistryGeneratorV1) validate() error { ...@@ -105,9 +105,6 @@ func (s SecretForDockerRegistryGeneratorV1) validate() error {
if len(s.Username) == 0 { if len(s.Username) == 0 {
return fmt.Errorf("username must be specified") return fmt.Errorf("username must be specified")
} }
if len(s.Email) == 0 {
return fmt.Errorf("email must be specified")
}
if len(s.Password) == 0 { if len(s.Password) == 0 {
return fmt.Errorf("password must be specified") return fmt.Errorf("password must be specified")
} }
......
...@@ -30,6 +30,10 @@ func TestSecretForDockerRegistryGenerate(t *testing.T) { ...@@ -30,6 +30,10 @@ func TestSecretForDockerRegistryGenerate(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
secretDataNoEmail, err := handleDockercfgContent(username, password, "", server)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
tests := map[string]struct { tests := map[string]struct {
params map[string]interface{} params map[string]interface{}
...@@ -55,6 +59,24 @@ func TestSecretForDockerRegistryGenerate(t *testing.T) { ...@@ -55,6 +59,24 @@ func TestSecretForDockerRegistryGenerate(t *testing.T) {
}, },
expectErr: false, expectErr: false,
}, },
"test-valid-use-no-email": {
params: map[string]interface{}{
"name": "foo",
"docker-server": server,
"docker-username": username,
"docker-password": password,
},
expected: &api.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Data: map[string][]byte{
api.DockerConfigKey: secretDataNoEmail,
},
Type: api.SecretTypeDockercfg,
},
expectErr: false,
},
"test-missing-required-param": { "test-missing-required-param": {
params: map[string]interface{}{ params: map[string]interface{}{
"name": "foo", "name": "foo",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment