mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
add --from-file flag to docker-registry secret
This commit is contained in:
@@ -30,6 +30,8 @@ import (
|
||||
type SecretForDockerRegistryGeneratorV1 struct {
|
||||
// Name of secret (required)
|
||||
Name string
|
||||
// FileSources to derive the secret from (optional)
|
||||
FileSources []string
|
||||
// Username for registry (required)
|
||||
Username string
|
||||
// Email for registry (optional)
|
||||
@@ -85,15 +87,22 @@ func (s SecretForDockerRegistryGeneratorV1) StructuredGenerate() (runtime.Object
|
||||
if err := s.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dockercfgJsonContent, err := handleDockerCfgJsonContent(s.Username, s.Password, s.Email, s.Server)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
secret := &v1.Secret{}
|
||||
secret.Name = s.Name
|
||||
secret.Type = v1.SecretTypeDockerConfigJson
|
||||
secret.Data = map[string][]byte{}
|
||||
secret.Data[v1.DockerConfigJsonKey] = dockercfgJsonContent
|
||||
if len(s.FileSources) > 0 {
|
||||
if err := handleFromFileSources(secret, s.FileSources); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if len(s.FileSources) == 0 {
|
||||
dockercfgJsonContent, err := handleDockerCfgJsonContent(s.Username, s.Password, s.Email, s.Server)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
secret.Data[v1.DockerConfigJsonKey] = dockercfgJsonContent
|
||||
}
|
||||
if s.AppendHash {
|
||||
h, err := hash.SecretHash(secret)
|
||||
if err != nil {
|
||||
@@ -108,6 +117,7 @@ func (s SecretForDockerRegistryGeneratorV1) StructuredGenerate() (runtime.Object
|
||||
func (s SecretForDockerRegistryGeneratorV1) ParamNames() []GeneratorParam {
|
||||
return []GeneratorParam{
|
||||
{"name", true},
|
||||
{"from-file", false},
|
||||
{"docker-username", true},
|
||||
{"docker-email", false},
|
||||
{"docker-password", true},
|
||||
@@ -121,14 +131,17 @@ func (s SecretForDockerRegistryGeneratorV1) validate() error {
|
||||
if len(s.Name) == 0 {
|
||||
return fmt.Errorf("name must be specified")
|
||||
}
|
||||
if len(s.Username) == 0 {
|
||||
return fmt.Errorf("username must be specified")
|
||||
}
|
||||
if len(s.Password) == 0 {
|
||||
return fmt.Errorf("password must be specified")
|
||||
}
|
||||
if len(s.Server) == 0 {
|
||||
return fmt.Errorf("server must be specified")
|
||||
|
||||
if len(s.FileSources) == 0 {
|
||||
if len(s.Username) == 0 {
|
||||
return fmt.Errorf("username must be specified")
|
||||
}
|
||||
if len(s.Password) == 0 {
|
||||
return fmt.Errorf("password must be specified")
|
||||
}
|
||||
if len(s.Server) == 0 {
|
||||
return fmt.Errorf("server must be specified")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user