Skip to content

Commit

Permalink
fix: Fix the certificate deletion
Browse files Browse the repository at this point in the history
- Raise exception when the cert_ref is none in get_object
- Delete the k8s secret using its metadata only
  • Loading branch information
okozachenko1203 authored and mnaser committed Jun 26, 2023
1 parent 9d3312c commit 17c243a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,23 @@ def get_object(self) -> objects.ClusterResourceSet:


class CertificateAuthoritySecret(ClusterBase):
def delete(self) -> None:
resource = self.get_or_none()
if resource:
resource.delete()

def get_or_none(self) -> pykube.Secret:
return pykube.Secret.objects(self.api, namespace="magnum-system").get_or_none(
name=f"{self.cluster.stack_id}-{self.CERT}"
)

def get_object(self) -> pykube.Secret:
cert_ref = getattr(self.cluster, self.REF)
if cert_ref is None:
raise Exception("Certificate for %s doesn't exist." % self.REF)

ca_cert = cert_manager.get_backend().CertManager.get_cert(
getattr(self.cluster, self.REF),
cert_ref,
resource_ref=self.cluster.uuid,
)

Expand Down

0 comments on commit 17c243a

Please sign in to comment.