spark-integration-hub-k8s

Spark Integration Hub K8s

Channel Revision Published Runs on
latest/edge 67 28 Jul 2025
Ubuntu 22.04
3/stable 67 29 Jul 2025
Ubuntu 22.04
3/candidate 67 28 Jul 2025
Ubuntu 22.04
3/beta 67 28 Jul 2025
Ubuntu 22.04
3/edge 73 22 Aug 2025
Ubuntu 22.04
juju deploy spark-integration-hub-k8s --channel 3/stable
Show information

Platform:

charms.spark_integration_hub_k8s.v0.spark_service_account

Library for creating service accounts that are configured to run Spark jobs.

This library contains the SparkServiceAccountProvider and SparkServiceAccountRequirer classes for handling the relation between charms that require Spark Service Account to be created in order to function, and charms that create and provide them.

SparkServiceAccountRequirer

Following is an example of using the SparkServiceAccountRequirer class in the context of the application charm code:

import json

from charms.spark_integration_hub_k8s.v0.spark_service_account import (
    SparkServiceAccountRequirer,
    ServiceAccountGrantedEvent,
    ServiceAccountPropertyChangedEvent,
    ServiceAccountGoneEvent
)
from ops.model import ActiveStatus, BlockedStatus


class RequirerCharm(CharmBase):

    def __init__(self, *args):
        super().__init__(*args)

        namespace, username = "default", "test"
        self.spark_service_account_requirer = SparkServiceAccountRequirer(self, relation_name="service-account", service_account=f"{namespace}:{username}", skip_creation=False)
        self.framework.observe(
            self.spark_service_account_requirer.on.account_granted, self._on_account_granted
        )
        self.framework.observe(
            self.spark_service_account_requirer.on.account_gone, self._on_account_gone
        )
        self.framework.observe(
            self.spark_service_account_requirer.on.properties_changed, self._on_spark_properties_changed
        )

    def _on_account_granted(self, event: ServiceAccountGrantedEvent):
        # Handle the account_granted event

        namespace, username = event.service_account.split(":")
        props_string = self.service_account_requirer.relation_data.fetch_relation_field(event.relation.id, "spark-properties")
        props = json.loads(props_string)

        resource_manifest = self.service_account_requirer.relation_data.fetch_relation_field(event.relation.id, "resource-manifest")

        # Create configuration file for app
        config_file = self._render_app_config_file(
            namespace=namespace,
            username=username,
            spark_properties=props,
            resource_manifest=resource_manifest
        )

        # Start application with rendered configuration
        self._start_application(config_file)

        # Set appropriate status
        self.unit.status = ActiveStatus("Received Spark service account")

    def _on_spark_properties_changed(self, event: ServiceAccountPropertyChangedEvent):
        # Handle the properties_changed event
        namespace, username = event.service_account.split(":")

        # Fetch the Spark properties from event data
        props_string = self.service_account_requirer.relation_data.fetch_relation_field(event.relation.id, "spark-properties")
        props = json.loads(props_string)

        resource_manifest = self.service_account_requirer.relation_data.fetch_relation_field(event.relation.id, "resource-manifest")

        # Create configuration file for app
        config_file = self._render_app_config_file(
            namespace=namespace,
            username=username,
            spark_properties=props,
            resource_manifest=resource_manifest
        )

        # Start application with rendered configuration
        self._start_application(config_file)

        # Set appropriate status
        self.unit.status = ActiveStatus("Spark service account properties changed")

    def _on_account_gone(self, event: ServiceAccountGoneEvent):
        # Handle the account_gone event

        # Create configuration file for app
        config_file = self._render_app_config_file(
            namespace=None,
            username=None,
            spark_properties=None,
            resource_manifest=None,
        )

        # Start application with rendered configuration
        self._start_application(config_file)

        # Set appropriate status
        self.unit.status = BlockedStatus("Missing spark service account")
SparkServiceAccountProvider

Following is an example of using the SparkServiceAccountProvider class in the context of the application charm code:

from charms.spark_integration_hub_k8s.v0.spark_service_account import (
    SparkServiceAccountProvider,
    ServiceAccountRequestedEvent,
    ServiceAccountReleasedEvent,
)


class ProviderCharm(CharmBase):

    def __init__(self, *args):
        super().__init__(*args)

        self.spark_service_account_provider = SparkServiceAccountProvider(self, relation_name="service-account")
        self.framework.observe(self.sa.on.account_requested, self._on_service_account_requested)
        self.framework.observe(self.sa.on.account_released, self._on_service_account_released)


    def _on_service_account_requested(self, event: ServiceAccountRequestedEvent):
        # Handle the account_requested event

        namespace, username = event.service_account.split(":")
        skip_creation = event.skip_creation

        if not skip_creation:
            # Create the service account
            self.create_service_account(namespace, username)

        resource_manifest = self.generate_resource_manifest(namespace, username)
        spark_properties = self.generate_spark_properties(namespace, username)

        # Write the service account, Spark properties and resource manifest to relation data
        self.spark_service_account_provider.set_service_account(event.relation.id, f"{namespace}:{username}")
        self.spark_service_account_provider.set_spark_properties(event.relation.id, spark_properties)
        self.spark_service_account_provider.set_resource_manifest(event.relation.id, resource_manifest)


    def _on_service_account_released(self, event: ServiceAccountReleasedEvent):
        # Handle account_released event

        namespace, username = event.service_account.split(":")
        skip_creation = event.skip_creation

        if not skip_creation:
            # Delete the service account
            self.delete_service_account(namespace, username)

class ServiceAccountEvent

Description

Base class for Service account events. None

Methods

ServiceAccountEvent. service_account( self )

Description

Returns the service account was requested. None

ServiceAccountEvent. spark_properties( self )

Description

Returns the Spark properties associated with service account. None

ServiceAccountEvent. resource_manifest( self )

Description

Returns the resource manifest associated with service account. None

ServiceAccountEvent. skip_creation( self )

Description

Returns the skip-creation flag associated with service account. None

class ServiceAccountRequestedEvent

Description

Event emitted when a set of service account is requested for use on this relation. None

class ServiceAccountReleasedEvent

Description

Event emitted when a set of service account is released. None

class SparkServiceAccountProviderEvents

Description

Event descriptor for events raised by ServiceAccountProvider. None

class ServiceAccountGrantedEvent

Description

Event emitted when service account are granted on this relation. None

class ServiceAccountGoneEvent

Description

Event emitted when service account are removed from this relation. None

class ServiceAccountPropertyChangedEvent

Description

Event emitted when Spark properties for the service account are changed in this relation. None

class SparkServiceAccountRequirerEvents

Description

Event descriptor for events raised by the Requirer. None

class SparkServiceAccountProviderData

Description

Implementation of ProviderData for the Spark Service Account relation. None

Methods

SparkServiceAccountProviderData. __init__( self , model: Model , relation_name: str )

SparkServiceAccountProviderData. set_service_account( self , relation_id: int , service_account: str )

Set the service account name in the application relation databag.

Arguments

relation_id

the identifier for a particular relation.

service_account

the service account name.

SparkServiceAccountProviderData. set_spark_properties( self , relation_id: int , spark_properties: str )

Set the Spark properties in the application relation databag.

Arguments

relation_id

the identifier for a particular relation.

spark_properties

the dictionary that contains key-value for Spark properties.

SparkServiceAccountProviderData. set_resource_manifest( self , relation_id: int , resource_manifest: str )

Set the resource manifest in the application relation databag.

Arguments

relation_id

the identifier for a particular relation.

resource_manifest

the dictionary that contains key-value for resource manifest.

class SparkServiceAccountProviderEventHandlers

Description

Provider-side of the Spark Service Account relation. None

Methods

SparkServiceAccountProviderEventHandlers. __init__( self , charm: CharmBase , relation_data: SparkServiceAccountProviderData )

class SparkServiceAccountProvider

Description

Provider-side of the Spark Service Account relation. None

Methods

SparkServiceAccountProvider. __init__( self , charm: CharmBase , relation_name: str )

class SparkServiceAccountRequirerData

Description

Implementation of RequirerData for the Spark Service Account relation. None

Methods

SparkServiceAccountRequirerData. __init__( self , model: Model , relation_name: str , service_account: str , skip_creation: bool , additional_secret_fields )

Description

Manager of Spark Service Account relations. None

SparkServiceAccountRequirerData. service_account( self )

Description

Service account used for Spark. None

SparkServiceAccountRequirerData. service_account( self , value )

class SparkServiceAccountRequirerEventHandlers

Description

Requirer-side event handlers of the Spark Service Account relation. None

Methods

SparkServiceAccountRequirerEventHandlers. __init__( self , charm: CharmBase , relation_data: SparkServiceAccountRequirerData )

class SparkServiceAccountRequirer

Description

Requirer side of the Spark Service Account relation. None

Methods

SparkServiceAccountRequirer. __init__( self , charm: CharmBase , relation_name: str , service_account: str , skip_creation: bool , additional_secret_fields )