Skip to content
Permalink
Browse files

Merge pull request #1032 from PrefectHQ/docker-auth-creds

Correctly create the k8s docker secret
  • Loading branch information...
cicdw committed May 16, 2019
2 parents 6e6d99f + cf2bbf8 commit f1734d7f359d2c550ae06c467d1b4282cf542f01
Showing with 16 additions and 4 deletions.
  1. +16 −4 src/prefect/environments/execution/cloud/environment.py
@@ -83,10 +83,22 @@ def _create_namespaced_secret(self) -> None:
from kubernetes import client

docker_creds = Secret("DOCKER_REGISTRY_CREDENTIALS").get()
assert isinstance(docker_creds, dict)

v1 = client.CoreV1Api()
data = { # type: ignore
k: base64.b64encode(v.encode()).decode()
for k, v in docker_creds.items() # type: ignore
cred_payload = {
"auths": {
docker_creds["docker-server"]: {
"Username": docker_creds["docker-username"],
"Password": docker_creds["docker-password"],
"Email": docker_creds["docker-email"],
}
}
}
data = {
".dockerconfigjson": base64.b64encode(
json.dumps(cred_payload).encode()
).decode()
}
namespace = prefect.context.get("namespace", "unknown")
name = namespace + "-docker"
@@ -95,7 +107,7 @@ def _create_namespaced_secret(self) -> None:
data=data,
kind="Secret",
metadata=dict(name=name, namespace=namespace),
type="docker-registry",
type="kubernetes.io/dockerconfigjson",
)
v1.create_namespaced_secret(namespace, body=secret)

0 comments on commit f1734d7

Please sign in to comment.
You can’t perform that action at this time.