@@ -96,7 +96,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
9696 "--registry-user" , registryUser ,
9797 "--service-account" , "some-sa" ,
9898 "-n" , namespace },
99- ExpectedOutput : `Secret "my-registry-cred" created
99+ ExpectedOutput : `Secret "my-registry-cred" created for my-registry.io
100100` ,
101101 ExpectCreates : []runtime.Object {
102102 expectedRegistrySecret ,
@@ -136,7 +136,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
136136 defaultNamespacedServiceAccount ,
137137 },
138138 Args : []string {secretName , "--dockerhub" , dockerhubId , "-n" , namespace },
139- ExpectedOutput : `Secret "my-docker-cred" created
139+ ExpectedOutput : `Secret "my-docker-cred" created for https://index.docker.io/v1/
140140` ,
141141 ExpectCreates : []runtime.Object {
142142 expectedDockerSecret ,
@@ -148,6 +148,46 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
148148 })
149149 })
150150
151+ when ("creating a generic registry secret" , func () {
152+ var (
153+ registry = "https://index.docker.io/v1/"
154+ registryUser = "my-registry-user"
155+ registryPassword = "dummy-password"
156+ secretName = "my-registry-cred"
157+ expectedRegistryConfig = fmt .Sprintf (`{"auths":{"%s":{"username":"%s","password":"%s","auth":"bXktcmVnaXN0cnktdXNlcjpkdW1teS1wYXNzd29yZA=="}}}` , registry , registryUser , registryPassword )
158+ )
159+
160+ fetcher .passwords ["REGISTRY_PASSWORD" ] = registryPassword
161+
162+ it ("creates a secret with the correct annotations for the registry in the provided namespace and updates the default service account" , func () {
163+ expectedDockerSecret := & corev1.Secret {
164+ ObjectMeta : v1.ObjectMeta {
165+ Name : secretName ,
166+ Namespace : namespace ,
167+ },
168+ Data : map [string ][]byte {
169+ corev1 .DockerConfigJsonKey : []byte (expectedRegistryConfig ),
170+ },
171+ Type : corev1 .SecretTypeDockerConfigJson ,
172+ }
173+
174+ testhelpers.CommandTest {
175+ Objects : []runtime.Object {
176+ defaultNamespacedServiceAccount ,
177+ },
178+ Args : []string {secretName , "--registry" , registry , "--registry-user" , registryUser , "-n" , namespace },
179+ ExpectedOutput : `Secret "my-registry-cred" created for https://index.docker.io/v1/
180+ ` ,
181+ ExpectCreates : []runtime.Object {
182+ expectedDockerSecret ,
183+ },
184+ ExpectPatches : []string {
185+ `{"imagePullSecrets":[{"name":"my-registry-cred"}],"metadata":{"annotations":{"kpack.io/managedSecret":"{\"my-registry-cred\":\"https://index.docker.io/v1/\"}"}},"secrets":[{"name":"my-registry-cred"}]}` ,
186+ },
187+ }.TestK8s (t , cmdFunc )
188+ })
189+ })
190+
151191 when ("creating a generic registry secret" , func () {
152192 var (
153193 registry = "my-registry.io"
@@ -176,7 +216,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
176216 defaultNamespacedServiceAccount ,
177217 },
178218 Args : []string {secretName , "--registry" , registry , "--registry-user" , registryUser , "-n" , namespace },
179- ExpectedOutput : `Secret "my-registry-cred" created
219+ ExpectedOutput : `Secret "my-registry-cred" created for my-registry.io
180220` ,
181221 ExpectCreates : []runtime.Object {
182222 expectedDockerSecret ,
@@ -214,7 +254,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
214254 defaultNamespacedServiceAccount ,
215255 },
216256 Args : []string {secretName , "--gcr" , gcrServiceAccountFile , "-n" , namespace },
217- ExpectedOutput : `Secret "my-gcr-cred" created
257+ ExpectedOutput : `Secret "my-gcr-cred" created for gcr.io
218258` ,
219259 ExpectCreates : []runtime.Object {
220260 expectedDockerSecret ,
@@ -255,7 +295,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
255295 defaultNamespacedServiceAccount ,
256296 },
257297 Args : []string {secretName , "--git-url" , gitRepo , "--git-ssh-key" , gitSshFile , "-n" , namespace },
258- ExpectedOutput : `Secret "my-git-ssh-cred" created
298+ ExpectedOutput : `Secret "my-git-ssh-cred" created for git@github.com
259299` ,
260300 ExpectCreates : []runtime.Object {
261301 expectedGitSecret ,
@@ -298,7 +338,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
298338 defaultNamespacedServiceAccount ,
299339 },
300340 Args : []string {secretName , "--git-url" , gitRepo , "--git-user" , gitUser , "-n" , namespace },
301- ExpectedOutput : `Secret "my-git-basic-cred" created
341+ ExpectedOutput : `Secret "my-git-basic-cred" created for https://github.com
302342` ,
303343 ExpectCreates : []runtime.Object {
304344 expectedGitSecret ,
@@ -339,7 +379,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
339379 defaultServiceAccount ,
340380 },
341381 Args : []string {secretName , "--dockerhub" , dockerhubId },
342- ExpectedOutput : `Secret "my-docker-cred" created
382+ ExpectedOutput : `Secret "my-docker-cred" created for https://index.docker.io/v1/
343383` ,
344384 ExpectCreates : []runtime.Object {
345385 expectedDockerSecret ,
@@ -379,7 +419,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
379419 defaultServiceAccount ,
380420 },
381421 Args : []string {secretName , "--registry" , registry , "--registry-user" , registryUser },
382- ExpectedOutput : `Secret "my-registry-cred" created
422+ ExpectedOutput : `Secret "my-registry-cred" created for my-registry.io
383423` ,
384424 ExpectCreates : []runtime.Object {
385425 expectedDockerSecret ,
@@ -417,7 +457,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
417457 defaultServiceAccount ,
418458 },
419459 Args : []string {secretName , "--gcr" , gcrServiceAccountFile },
420- ExpectedOutput : `Secret "my-gcr-cred" created
460+ ExpectedOutput : `Secret "my-gcr-cred" created for gcr.io
421461` ,
422462 ExpectCreates : []runtime.Object {
423463 expectedDockerSecret ,
@@ -458,7 +498,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
458498 defaultServiceAccount ,
459499 },
460500 Args : []string {secretName , "--git-url" , gitRepo , "--git-ssh-key" , gitSshFile },
461- ExpectedOutput : `Secret "my-git-ssh-cred" created
501+ ExpectedOutput : `Secret "my-git-ssh-cred" created for git@github.com
462502` ,
463503 ExpectCreates : []runtime.Object {
464504 expectedGitSecret ,
@@ -501,7 +541,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
501541 defaultServiceAccount ,
502542 },
503543 Args : []string {secretName , "--git-url" , gitRepo , "--git-user" , gitUser },
504- ExpectedOutput : `Secret "my-git-basic-cred" created
544+ ExpectedOutput : `Secret "my-git-basic-cred" created for https://github.com
505545` ,
506546 ExpectCreates : []runtime.Object {
507547 expectedGitSecret ,
@@ -650,7 +690,7 @@ secrets:
650690 "--dockerhub" , "my-dockerhub-id" ,
651691 "--dry-run" ,
652692 },
653- ExpectedOutput : `Secret "my-docker-cred" created (dry run)
693+ ExpectedOutput : `Secret "my-docker-cred" created for https://index.docker.io/v1/ (dry run)
654694` ,
655695 }.TestK8s (t , cmdFunc )
656696 })
0 commit comments