Cloud Providers

The cloud providers, and the one that the platform uses.

smarter_settings.cloud_provider (SMARTER_CLOUD_PROVIDER) names the provider, e.g. aws, and get_provider() returns it. Tests replace it with configure_provider():

from smarter.apps.infrastructure.providers import configure_provider
from smarter.apps.infrastructure.providers.memory import InMemoryProvider

configure_provider(InMemoryProvider)
...
configure_provider(None)
class smarter.apps.infrastructure.providers.CloudProvider(allow_in_tests=False, **kwargs)[source]

Bases: InfrastructureService

A cloud provider: the cloud-specific half of the infrastructure services.

Parameters:

allow_in_tests (bool) – Allow the provider to reach its cloud in the unit tests, e.g. in a test tagged INFRASTRUCTURE.

__init__(allow_in_tests=False, **kwargs)[source]
property account_id: str | None

The cloud account’s id, or None if the provider is not authenticated.

authentication_state(identity, error=None)[source]

Record whether the provider is authenticated with its cloud.

Sends infrastructure_authenticated or infrastructure_authentication_failed when the state changes, rather than on every check.

Parameters:
  • identity (dict[str, Any] | None) – The provider’s identity, or None if it is not authenticated.

  • error (str | None) – Why it is not authenticated.

Return type:

bool

Returns:

Whether it is authenticated.

abstract property certificates: CertificateService

The provider’s TLS certificate service.

abstract property dns: DNSService

The provider’s DNS service.

get_kubernetes_cluster_health()[source]

Describe the health of the platform’s Kubernetes cluster, as the cloud provider sees it.

The MCPServer’s staff-only eks_status tool reports it. This implementation knows only what get_kubernetes_cluster_info() returns: the control plane’s status, versions and health issues. A provider overrides it to add its node groups, add-ons and recommendations, as AWSProvider does with EKS.

Return type:

ClusterHealth

Returns:

The cluster’s health, with no node groups, add-ons or insights.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

abstractmethod get_kubernetes_cluster_info()[source]

Describe the platform’s Kubernetes cluster, e.g. for the status API.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

Return type:

dict[str, Any]

get_kubernetes_cluster_resources()[source]

Return the cloud resources of the platform’s Kubernetes cluster, for the inventory.

e.g. the cluster itself, its add-ons, and its node groups, which are provisioned outside the platform, e.g. with Terraform, so that no signal records them.

Return type:

dict[str, list[DiscoveredResource]]

Returns:

The resources, by resource type, e.g. kubernetes.cluster. A type that could not be listed is left out, so that the inventory does not record its resources as destroyed. This implementation lists none.

get_kubernetes_token()[source]

Return a bearer token for the platform’s Kubernetes cluster, which kubectl uses instead of its kubeconfig’s.

The kubeconfig of a managed cluster usually runs a command to fetch a token, e.g. aws eks get-token, on every kubectl call, which takes seconds. A provider that can create a token itself returns one, which is used until it expires.

Return type:

tuple[str, float] | None

Returns:

The token and when it expires, as a time.time(), or None for kubectl to use its kubeconfig’s credentials.

abstract property identity: dict[str, Any] | None

The identity that the provider authenticates as, e.g. its account, or None.

name: str = 'cloud'

The provider’s name, see CloudProviders.

abstract property sdk_version: str

The version of the provider’s SDK.

service_name: str = 'provider'

The name of the service in signals and logs, see InfrastructureServiceNames.

abstract property storage: StorageService

The provider’s private object storage.

abstractmethod update_kubeconfig()[source]

Write the kubeconfig of the platform’s Kubernetes cluster, for kubectl.

Return type:

bool

Returns:

True if it was written.

smarter.apps.infrastructure.providers.configure_provider(factory)[source]

Use another provider, e.g. a fake in tests.

Parameters:

factory (Callable[[], CloudProvider] | None) – Returns the provider, or None to restore smarter_settings.cloud_provider.

Return type:

None

smarter.apps.infrastructure.providers.get_provider()[source]

Return the cloud provider, which is created once.

Raises:

InfrastructureConfigurationError – If smarter_settings.cloud_provider is not registered.

Return type:

CloudProvider

smarter.apps.infrastructure.providers.register_provider(name, factory)[source]

Register a cloud provider under its name, so that smarter_settings.cloud_provider can select it.

Parameters:
Return type:

None

smarter.apps.infrastructure.providers.registered_providers()[source]

The names of the registered providers.

Return type:

list[str]

The base class of the cloud providers.

A cloud provider implements the services that depend on a cloud, CloudProvider.dns, CloudProvider.certificates and CloudProvider.storage, and contributes what the cloud-independent services need from it: the Kubernetes cluster’s kubeconfig, the cluster’s description, and the cloud resources of the cluster, for the inventory.

To add a cloud, e.g. Azure:

  1. Add a package, smarter.apps.infrastructure.providers.azure, with a CloudProvider whose DNS, certificate and storage services implement the primitives of DNSService, CertificateService and StorageService.

  2. Register it, in smarter.apps.infrastructure.providers, under its CloudProviders name.

  3. Set SMARTER_CLOUD_PROVIDER=azure.

The platform does not change.

class smarter.apps.infrastructure.providers.base.CloudProvider(allow_in_tests=False, **kwargs)[source]

Bases: InfrastructureService

A cloud provider: the cloud-specific half of the infrastructure services.

Parameters:

allow_in_tests (bool) – Allow the provider to reach its cloud in the unit tests, e.g. in a test tagged INFRASTRUCTURE.

__init__(allow_in_tests=False, **kwargs)[source]
property account_id: str | None

The cloud account’s id, or None if the provider is not authenticated.

authentication_state(identity, error=None)[source]

Record whether the provider is authenticated with its cloud.

Sends infrastructure_authenticated or infrastructure_authentication_failed when the state changes, rather than on every check.

Parameters:
  • identity (dict[str, Any] | None) – The provider’s identity, or None if it is not authenticated.

  • error (str | None) – Why it is not authenticated.

Return type:

bool

Returns:

Whether it is authenticated.

abstract property certificates: CertificateService

The provider’s TLS certificate service.

abstract property dns: DNSService

The provider’s DNS service.

get_kubernetes_cluster_health()[source]

Describe the health of the platform’s Kubernetes cluster, as the cloud provider sees it.

The MCPServer’s staff-only eks_status tool reports it. This implementation knows only what get_kubernetes_cluster_info() returns: the control plane’s status, versions and health issues. A provider overrides it to add its node groups, add-ons and recommendations, as AWSProvider does with EKS.

Return type:

ClusterHealth

Returns:

The cluster’s health, with no node groups, add-ons or insights.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

abstractmethod get_kubernetes_cluster_info()[source]

Describe the platform’s Kubernetes cluster, e.g. for the status API.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

Return type:

dict[str, Any]

get_kubernetes_cluster_resources()[source]

Return the cloud resources of the platform’s Kubernetes cluster, for the inventory.

e.g. the cluster itself, its add-ons, and its node groups, which are provisioned outside the platform, e.g. with Terraform, so that no signal records them.

Return type:

dict[str, list[DiscoveredResource]]

Returns:

The resources, by resource type, e.g. kubernetes.cluster. A type that could not be listed is left out, so that the inventory does not record its resources as destroyed. This implementation lists none.

get_kubernetes_token()[source]

Return a bearer token for the platform’s Kubernetes cluster, which kubectl uses instead of its kubeconfig’s.

The kubeconfig of a managed cluster usually runs a command to fetch a token, e.g. aws eks get-token, on every kubectl call, which takes seconds. A provider that can create a token itself returns one, which is used until it expires.

Return type:

tuple[str, float] | None

Returns:

The token and when it expires, as a time.time(), or None for kubectl to use its kubeconfig’s credentials.

abstract property identity: dict[str, Any] | None

The identity that the provider authenticates as, e.g. its account, or None.

name: str = 'cloud'

The provider’s name, see CloudProviders.

abstract property sdk_version: str

The version of the provider’s SDK.

service_name: str = 'provider'

The name of the service in signals and logs, see InfrastructureServiceNames.

abstract property storage: StorageService

The provider’s private object storage.

abstractmethod update_kubeconfig()[source]

Write the kubeconfig of the platform’s Kubernetes cluster, for kubectl.

Return type:

bool

Returns:

True if it was written.