Skip to content

Commit bbf4144

Browse files
committed
Fix kubectl create secret docker-registry
1 parent 7937aa6 commit bbf4144

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
@@ -189,9 +189,7 @@ func NewCmdCreateSecretDockerRegistry(f cmdutil.Factory, ioStreams genericcliopt
189189
cmdutil.AddValidateFlags(cmd)
190190
cmdutil.AddGeneratorFlags(cmd, generateversioned.SecretForDockerRegistryV1GeneratorName)
191191
cmd.Flags().String("docker-username", "", i18n.T("Username for Docker registry authentication"))
192-
cmd.MarkFlagRequired("docker-username")
193192
cmd.Flags().String("docker-password", "", i18n.T("Password for Docker registry authentication"))
194-
cmd.MarkFlagRequired("docker-password")
195193
cmd.Flags().String("docker-email", "", i18n.T("Email for Docker registry"))
196194
cmd.Flags().String("docker-server", "https://index.docker.io/v1/", i18n.T("Server location for Docker registry"))
197195
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
@@ -830,6 +830,21 @@ run_secrets_test() {
830830
# Clean-up
831831
kubectl delete secret test-secret --namespace=test-secrets
832832

833+
### Create a docker-registry secret in a specific namespace with docker config file
834+
if [[ "${WAIT_FOR_DELETION:-}" == "true" ]]; then
835+
kube::test::wait_object_assert 'secrets --namespace=test-secrets' "{{range.items}}{{$id_field}}:{{end}}" ''
836+
fi
837+
# Pre-condition: no SECRET exists
838+
kube::test::get_object_assert 'secrets --namespace=test-secrets' "{{range.items}}{{$id_field}}:{{end}}" ''
839+
# Command
840+
kubectl create secret docker-registry test-secret --from-file=.dockerconfigjson=hack/testdata/dockerconfig.json --namespace=test-secrets
841+
# Post-condition: secret exists and has expected values
842+
kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$id_field}}" 'test-secret'
843+
kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$secret_type}}" 'kubernetes.io/dockerconfigjson'
844+
grep -q '.dockerconfigjson: ewogICAgImF1dGhzIjp7CiAgICAgICAgImh0dHA6Ly9mb28uZXhhbXBsZS5jb20iOnsKICAgICAgICAgICAgInVzZXJuYW1lIjoiZm9vIiwKICAgICAgICAgICAgInBhc3N3b3JkIjoiYmFyIiwKICAgICAgICAgICAgImVtYWlsIjoiZm9vQGV4YW1wbGUuY29tIgogICAgICAgIH0sCiAgICAgICAgImh0dHA6Ly9iYXIuZXhhbXBsZS5jb20iOnsKICAgICAgICAgICAgInVzZXJuYW1lIjoiYmFyIiwKICAgICAgICAgICAgInBhc3N3b3JkIjoiYmF6IiwKICAgICAgICAgICAgImVtYWlsIjoiYmFyQGV4YW1wbGUuY29tIgogICAgICAgIH0KICAgIH0KfQo=' <<< "$(kubectl get secret/test-secret --namespace=test-secrets -o yaml "${kube_flags[@]}")"
845+
# Clean-up
846+
kubectl delete secret test-secret --namespace=test-secrets
847+
833848
### Create a tls secret
834849
if [[ "${WAIT_FOR_DELETION:-}" == "true" ]]; then
835850
kube::test::wait_object_assert 'secrets --namespace=test-secrets' "{{range.items}}{{$id_field}}:{{end}}" ''

0 commit comments

Comments
 (0)