Skip to content

Commit f097cee

Browse files
authored
Merge pull request kubernetes#90960 from zhouya0/fix_kubectl_create_secret_docker_registry
Fix kubectl create secret docker-registry --from-file
2 parents a82d71c + bbf4144 commit f097cee

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

hack/testdata/dockerconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"auths":{
3+
"http://foo.example.com":{
4+
"username":"foo",
5+
"password":"bar",
6+
7+
},
8+
"http://bar.example.com":{
9+
"username":"bar",
10+
"password":"baz",
11+
12+
}
13+
}
14+
}

staging/src/k8s.io/kubectl/pkg/cmd/create/create_secret.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ func NewCmdCreateSecretDockerRegistry(f cmdutil.Factory, ioStreams genericcliopt
190190
cmdutil.AddValidateFlags(cmd)
191191
cmdutil.AddGeneratorFlags(cmd, generateversioned.SecretForDockerRegistryV1GeneratorName)
192192
cmd.Flags().String("docker-username", "", i18n.T("Username for Docker registry authentication"))
193-
cmd.MarkFlagRequired("docker-username")
194193
cmd.Flags().String("docker-password", "", i18n.T("Password for Docker registry authentication"))
195-
cmd.MarkFlagRequired("docker-password")
196194
cmd.Flags().String("docker-email", "", i18n.T("Email for Docker registry"))
197195
cmd.Flags().String("docker-server", "https://index.docker.io/v1/", i18n.T("Server location for Docker registry"))
198196
cmd.Flags().Bool("append-hash", false, "Append a hash of the secret to its name.")

test/cmd/core.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,21 @@ run_secrets_test() {
855855
# Clean-up
856856
kubectl delete secret test-secret --namespace=test-secrets
857857

858+
### Create a docker-registry secret in a specific namespace with docker config file
859+
if [[ "${WAIT_FOR_DELETION:-}" == "true" ]]; then
860+
kube::test::wait_object_assert 'secrets --namespace=test-secrets' "{{range.items}}{{$id_field}}:{{end}}" ''
861+
fi
862+
# Pre-condition: no SECRET exists
863+
kube::test::get_object_assert 'secrets --namespace=test-secrets' "{{range.items}}{{$id_field}}:{{end}}" ''
864+
# Command
865+
kubectl create secret docker-registry test-secret --from-file=.dockerconfigjson=hack/testdata/dockerconfig.json --namespace=test-secrets
866+
# Post-condition: secret exists and has expected values
867+
kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$id_field}}" 'test-secret'
868+
kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$secret_type}}" 'kubernetes.io/dockerconfigjson'
869+
grep -q '.dockerconfigjson: ewogICAgImF1dGhzIjp7CiAgICAgICAgImh0dHA6Ly9mb28uZXhhbXBsZS5jb20iOnsKICAgICAgICAgICAgInVzZXJuYW1lIjoiZm9vIiwKICAgICAgICAgICAgInBhc3N3b3JkIjoiYmFyIiwKICAgICAgICAgICAgImVtYWlsIjoiZm9vQGV4YW1wbGUuY29tIgogICAgICAgIH0sCiAgICAgICAgImh0dHA6Ly9iYXIuZXhhbXBsZS5jb20iOnsKICAgICAgICAgICAgInVzZXJuYW1lIjoiYmFyIiwKICAgICAgICAgICAgInBhc3N3b3JkIjoiYmF6IiwKICAgICAgICAgICAgImVtYWlsIjoiYmFyQGV4YW1wbGUuY29tIgogICAgICAgIH0KICAgIH0KfQo=' <<< "$(kubectl get secret/test-secret --namespace=test-secrets -o yaml "${kube_flags[@]}")"
870+
# Clean-up
871+
kubectl delete secret test-secret --namespace=test-secrets
872+
858873
### Create a tls secret
859874
if [[ "${WAIT_FOR_DELETION:-}" == "true" ]]; then
860875
kube::test::wait_object_assert 'secrets --namespace=test-secrets' "{{range.items}}{{$id_field}}:{{end}}" ''

0 commit comments

Comments
 (0)