Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate with google cloud provider #168

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":
kwmonroe marked this conversation as resolved.
Show resolved Hide resolved
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
Loading