Skip to content

Commit

Permalink
Merge pull request #1806 from sgaist/build_image_pull_secrets
Browse files Browse the repository at this point in the history
Implement support for image pull secrets for build pod
  • Loading branch information
manics authored Dec 15, 2023
2 parents 819bba8 + 0ebb9d7 commit 34996b3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
17 changes: 17 additions & 0 deletions binderhub/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ def _default_namespace(self):
def _default_builder_info(self):
return {"build_image": self.build_image}

image_pull_secrets = List(
[], help="Pull secrets for the builder image", config=True
)

docker_host = Unicode(
"/var/run/docker.sock",
allow_none=True,
Expand Down Expand Up @@ -455,6 +459,18 @@ def get_builder_volumes(self):

return volumes, volume_mounts

def get_image_pull_secrets(self):
"""
Get the list of image pull secrets to be used for the builder image
"""

image_pull_secrets = []

for secret in self.image_pull_secrets:
image_pull_secrets.append(client.V1LocalObjectReference(name=secret))

return image_pull_secrets

def submit(self):
"""
Submit a build pod to create the image for the repository.
Expand Down Expand Up @@ -526,6 +542,7 @@ def submit(self):
volumes=volumes,
restart_policy="Never",
affinity=self.get_affinity(),
image_pull_secrets=self.get_image_pull_secrets(),
),
)

Expand Down
38 changes: 38 additions & 0 deletions binderhub/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,44 @@ class EnvBuild(KubernetesBuildExecutor):
assert env == extra_environments


def test_build_image_pull_secrets():
build_pull_secrets = ["build-image-secret", "build-image-secret-2"]

mock_k8s_api = _list_image_builder_pods_mock()

class PullBuild(KubernetesBuildExecutor):
q = mock.MagicMock()
api = mock_k8s_api
name = "test_build"
repo_url = "repo"
ref = "ref"
image_name = "name"
namespace = "build_namespace"
push_secret = ""
build_image = "image"
image_pull_secrets = build_pull_secrets
memory_limit = 0
docker_host = "http://mydockerregistry.local"
node_selector = {}

build = PullBuild()

with mock.patch.object(build.stop_event, "is_set", return_value=True):
build.submit()

call_args_list = mock_k8s_api.create_namespaced_pod.call_args_list
assert len(call_args_list) == 1

args = call_args_list[0][0]
pod = args[1]

assert len(pod.spec.containers) == 1

pull_secrets = [secret.name for secret in pod.spec.image_pull_secrets]

assert pull_secrets == build_pull_secrets


async def test_local_repo2docker_build():
q = Queue()
repo_url = "https://github.com/binderhub-ci-repos/cached-minimal-dockerfile"
Expand Down

0 comments on commit 34996b3

Please sign in to comment.