mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Fix create secret docker-registry compatibility
This commit is contained in:
		@@ -17,6 +17,7 @@ limitations under the License.
 | 
				
			|||||||
package versioned
 | 
					package versioned
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/base64"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -152,6 +153,7 @@ func handleDockerCfgJSONContent(username, password, email, server string) ([]byt
 | 
				
			|||||||
		Username: username,
 | 
							Username: username,
 | 
				
			||||||
		Password: password,
 | 
							Password: password,
 | 
				
			||||||
		Email:    email,
 | 
							Email:    email,
 | 
				
			||||||
 | 
							Auth:     encodeDockerConfigFieldAuth(username, password),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dockerCfgJSON := DockerConfigJSON{
 | 
						dockerCfgJSON := DockerConfigJSON{
 | 
				
			||||||
@@ -161,6 +163,11 @@ func handleDockerCfgJSONContent(username, password, email, server string) ([]byt
 | 
				
			|||||||
	return json.Marshal(dockerCfgJSON)
 | 
						return json.Marshal(dockerCfgJSON)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func encodeDockerConfigFieldAuth(username, password string) string {
 | 
				
			||||||
 | 
						fieldValue := username + ":" + password
 | 
				
			||||||
 | 
						return base64.StdEncoding.EncodeToString([]byte(fieldValue))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// DockerConfigJSON represents a local docker auth config file
 | 
					// DockerConfigJSON represents a local docker auth config file
 | 
				
			||||||
// for pulling images.
 | 
					// for pulling images.
 | 
				
			||||||
type DockerConfigJSON struct {
 | 
					type DockerConfigJSON struct {
 | 
				
			||||||
@@ -175,7 +182,8 @@ type DockerConfigJSON struct {
 | 
				
			|||||||
type DockerConfig map[string]DockerConfigEntry
 | 
					type DockerConfig map[string]DockerConfigEntry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DockerConfigEntry struct {
 | 
					type DockerConfigEntry struct {
 | 
				
			||||||
	Username string
 | 
						Username string `json:"username,omitempty"`
 | 
				
			||||||
	Password string
 | 
						Password string `json:"password,omitempty"`
 | 
				
			||||||
	Email    string
 | 
						Email    string `json:"email,omitempty"`
 | 
				
			||||||
 | 
						Auth     string `json:"auth,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,7 +73,7 @@ func TestSecretForDockerRegistryGenerate(t *testing.T) {
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
			expected: &v1.Secret{
 | 
								expected: &v1.Secret{
 | 
				
			||||||
				ObjectMeta: metav1.ObjectMeta{
 | 
									ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
					Name: "foo-7566tc6mgc",
 | 
										Name: "foo-548cm7fgdh",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				Data: map[string][]byte{
 | 
									Data: map[string][]byte{
 | 
				
			||||||
					v1.DockerConfigJsonKey: secretData,
 | 
										v1.DockerConfigJsonKey: secretData,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -739,7 +739,7 @@ run_secrets_test() {
 | 
				
			|||||||
  # Post-condition: secret exists and has expected values
 | 
					  # Post-condition: secret exists and has expected values
 | 
				
			||||||
  kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$id_field}}" 'test-secret'
 | 
					  kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$id_field}}" 'test-secret'
 | 
				
			||||||
  kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$secret_type}}" 'kubernetes.io/dockerconfigjson'
 | 
					  kube::test::get_object_assert 'secret/test-secret --namespace=test-secrets' "{{$secret_type}}" 'kubernetes.io/dockerconfigjson'
 | 
				
			||||||
  [[ "$(kubectl get secret/test-secret --namespace=test-secrets -o yaml "${kube_flags[@]}" | grep '.dockerconfigjson:')" ]]
 | 
					  [[ "$(kubectl get secret/test-secret --namespace=test-secrets -o yaml "${kube_flags[@]}" | grep '.dockerconfigjson: eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNlcm5hbWUiOiJ0ZXN0LXVzZXIiLCJwYXNzd29yZCI6InRlc3QtcGFzc3dvcmQiLCJlbWFpbCI6InRlc3QtdXNlckB0ZXN0LmNvbSIsImF1dGgiOiJkR1Z6ZEMxMWMyVnlPblJsYzNRdGNHRnpjM2R2Y21RPSJ9fX0=')" ]]
 | 
				
			||||||
  # Clean-up
 | 
					  # Clean-up
 | 
				
			||||||
  kubectl delete secret test-secret --namespace=test-secrets
 | 
					  kubectl delete secret test-secret --namespace=test-secrets
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user