Skip to content

Commit

Permalink
Partially support the keystone-credentials relation enough to uplift …
Browse files Browse the repository at this point in the history
…the keystone service
  • Loading branch information
addyess committed Jun 7, 2024
1 parent a81bd63 commit f7c9db2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ requires:
interface: gcp-integration
azure:
interface: azure-integration
keystone-credentials:
interface: keystone-credentials
certificates:
interface: tls-certificates
dns-provider:
Expand Down
33 changes: 30 additions & 3 deletions src/auth_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,38 @@ class Secret:
password: str


def configure(
charm_dir, aws_iam_endpoint=None, custom_authn_endpoint=None, keystone_endpoint=None
):
def _uplift_keystone_endpoint() -> str:
"""Uplift the keystone auth service from a cdk-addons installation."""
try:
keystone_auth_service = kubectl_get(
"service", "-n", "kube-system", "k8s-keystone-auth-service"
)
except CalledProcessError:
log.info("No k8s-keystone-auth-service to uplift")
return None
labels = keystone_auth_service.get("metadata", {}).get("labels", {})
if labels.get("cdk-addons") != "true":
log.info("No cdk-addons based k8s-keystone-auth-service to uplift")
return None
if not (spec := keystone_auth_service.get("spec")):
log.error("No spec found for k8s-keystone-auth-service")
return None
cluster_ip, port = spec.get("clusterIP"), spec.get("ports")[0].get("port")
if not cluster_ip or not port:
log.error("No clusterIP or port found for k8s-keystone-auth-service")
return None
return f"https://{cluster_ip}:{port}/webhook"


def _uplift_aws_iam_endpoint() -> str:
return None


def configure(charm_dir, custom_authn_endpoint=None):
"""Render auth webhook templates and start the related service."""
status.add(MaintenanceStatus("Configuring auth webhook"))
keystone_endpoint = _uplift_keystone_endpoint()
aws_iam_endpoint = _uplift_aws_iam_endpoint()

# Set the number of gunicorn workers based on our core count. (2*cores)+1 is
# recommended: https://docs.gunicorn.org/en/stable/design.html#how-many-workers
Expand Down
15 changes: 12 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,19 @@ def configure_auth_webhook(self):
auth_webhook.configure(
charm_dir=self.charm_dir,
custom_authn_endpoint=self.model.config["authn-webhook-endpoint"],
# TODO: aws iam, keystone
# aws_iam_endpoint=???,
# keystone_endpoint=???
)

def warn_keystone_management(self):
relation = self.model.relations.get("keystone-credentials")
if relation and any(r.units for r in relation):
log.warning(
"------------------------------------------------------------\n"
"Keystone credential relation is no longer managed\n"
"Please remove the relation and manage keystone manually\n"
"Run `juju remove-relation kubernetes-control-plane:keystone-credentials keystone`"
)
status.add(ops.BlockedStatus("Keystone credential relation is no longer managed"))

@status.on_error(ops.WaitingStatus("Waiting for container runtime"))
def configure_container_runtime(self):
assert self.container_runtime.relations, "Missing container-runtime integration"
Expand Down Expand Up @@ -510,6 +518,7 @@ def reconcile(self, event):
self.write_etcd_client_credentials()
self.write_service_account_key()
self.configure_auth_webhook()
self.warn_keystone_management()
self.configure_loadbalancers()
if self.api_dependencies_ready():
self.encryption_at_rest.prepare()
Expand Down

0 comments on commit f7c9db2

Please sign in to comment.