Skip to content

Commit

Permalink
refactor: make the pod owner of the secret once created
Browse files Browse the repository at this point in the history
  • Loading branch information
sgaist committed Dec 5, 2022
1 parent b5eef26 commit 274e525
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions binderhub/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,17 @@ def submit(self):

env = []
if self.git_credentials:
secret = client.V1Secret()
secret.string_data = {"credentials": self.git_credentials}
secret.metadata = {"name": self.name}
secret.type = "Opaque"
secret = client.V1Secret(
metadata=client.V1ObjectMeta(
name=self.name,
labels={
"name": self.name,
"component": self._component_label,
},
),
string_data={"credentials": self.git_credentials},
type="Opaque",
)

self.api.create_namespaced_secret(self.namespace, secret)

Expand Down Expand Up @@ -497,6 +504,24 @@ def submit(self):
# https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase
phase = self.pod.status.phase
if phase == "Pending":
if self.git_credentials:
owner_reference = client.V1OwnerReference(
api_version="v1",
kind="Pod",
name=self.pod.metadata.name,
uid=self.pod.metadata.uid,
)
self.api.patch_namespaced_secret(
namespace=self.namespace,
name=self.pod.metadata.name,
body=[
{
"op": "replace",
"path": "/metadata/ownerReferences",
"value": [owner_reference],
}
],
)
self.progress(
ProgressEvent.Kind.BUILD_STATUS_CHANGE,
ProgressEvent.BuildStatus.PENDING,
Expand Down

0 comments on commit 274e525

Please sign in to comment.