Skip to content

Commit

Permalink
integrate with google cloud provider (#168)
Browse files Browse the repository at this point in the history
* integrate with google cloud provider

* Apply suggestions from code review

Co-authored-by: Kevin W Monroe <[email protected]>

---------

Co-authored-by: Kevin W Monroe <[email protected]>
  • Loading branch information
addyess and kwmonroe authored Mar 7, 2024
1 parent bfaeaec commit 802d4c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ provides:
requires:
aws:
interface: aws-integration
gcp:
interface: gcp-integration
certificates:
interface: tls-certificates
kube-control:
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ charm-lib-reconciler @ git+https://github.com/charmed-kubernetes/charm-lib-recon
cosl == 0.0.7
jinja2
ops >= 2.2.0
ops.interface_kube_control @ git+https://github.com/juju-solutions/interface-kube-control#subdirectory=ops
ops.interface_tls_certificates @ git+https://github.com/juju-solutions/interface-tls-certificates#subdirectory=ops
ops.interface_aws @ git+https://github.com/juju-solutions/interface-aws-integration#subdirectory=ops
ops.interface_kube_control @ git+https://github.com/charmed-kubernetes/interface-kube-control@main#subdirectory=ops
ops.interface_tls_certificates @ git+https://github.com/charmed-kubernetes/interface-tls-certificates@main#subdirectory=ops
ops.interface_aws @ git+https://github.com/charmed-kubernetes/interface-aws-integration@main#subdirectory=ops
ops.interface_gcp @ git+https://github.com/charmed-kubernetes/interface-gcp-integration@main#subdirectory=ops
pydantic==1.*
tenacity
43 changes: 22 additions & 21 deletions src/cloud_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"""Cloud Integration for Charmed Kubernetes Worker."""

import logging
from typing import Union

import charms.contextual_status as status
import ops
from ops.interface_aws.requires import AWSIntegrationRequires
from ops.interface_gcp.requires import GCPIntegrationRequires

log = logging.getLogger(__name__)

Expand All @@ -29,31 +31,38 @@ def __init__(self, charm: ops.CharmBase) -> None:
"""Integrate with all possible clouds."""
self.charm = charm
self.aws = AWSIntegrationRequires(charm)
self.gcp = None # GCPIntegrationRequires(charm)
self.gcp = GCPIntegrationRequires(charm)
self.azure = None # AzureIntegrationRequires(charm)

@status.on_error(ops.WaitingStatus("Waiting for cloud-integration"))
def integrate(self, event: ops.EventBase):
"""Request tags and permissions for a control-plane node."""
cluster_tag = self.charm.get_cluster_name()
@property
def cloud(self) -> Union[None, AWSIntegrationRequires, GCPIntegrationRequires]:
"""Determine if we're integrated with a known cloud."""
cloud_name = self.charm.get_cloud_name()
cloud_support = {
"aws": self.aws,
"gce": self.gcp,
}

if not (cloud := cloud_support.get(cloud_name)):
log.error(
"Skipping Cloud integration: unsupported cloud %s",
)
log.error("Skipping Cloud integration: unsupported cloud %s", cloud_name)
return

if not cloud.relation:
log.info(
"Skipping Cloud integration: Needs an active %s relation to integrate.", cloud_name
)
return
return cloud

status.add(ops.MaintenanceStatus(f"Integrate with {cloud}"))
@status.on_error(ops.WaitingStatus("Waiting for cloud-integration"))
def integrate(self, event: ops.EventBase):
"""Request tags and permissions for a worker node."""
if not (cloud := self.cloud):
return None

cloud_name = self.charm.get_cloud_name()
cluster_tag = self.charm.get_cluster_name()

status.add(ops.MaintenanceStatus(f"Integrate with {cloud_name}"))
if cloud_name == "aws":
cloud.tag_instance(
{
Expand All @@ -71,19 +80,11 @@ def integrate(self, event: ops.EventBase):
}
)
cloud.enable_object_storage_management(["kubernetes-*"])
elif cloud_name == "gcp":
cloud.tag_instance(
{
"k8s-io-cluster-name": cluster_tag,
}
)
elif cloud_name == "gce":
cloud.tag_instance({"k8s-io-cluster-name": cluster_tag})
cloud.enable_object_storage_management()
elif cloud_name == "azure":
cloud.tag_instance(
{
"k8s-io-cluster-name": cluster_tag,
}
)
cloud.tag_instance({"k8s-io-cluster-name": cluster_tag})
cloud.enable_object_storage_management()
cloud.enable_instance_inspection()
cloud.enable_dns_management()
Expand Down

0 comments on commit 802d4c8

Please sign in to comment.