def get_test_deployment(number: int): return Deployment( metadata=ObjectMeta(name=f"test-deployment-{number}", labels={"type": "master"}), spec=DeploymentSpec( replicas=1, template=PodTemplateSpec( ObjectMeta(labels={"container_type": "master"}), spec=PodSpec(containers=[get_test_container(number)]), ), selector=LabelSelector(match_labels={"container_type": "master"}), ), )
def __init__(self, airflow_options: AirflowOptions): values = ValueOrchestrator() super().__init__( ObjectMeta( name=values.airflow_pod_service_account, namespace=airflow_options.namespace, ))
def get_pod_with_options( volume: Optional[Volume] = None, volume_mount: Optional[VolumeMount] = None, pod_security_context: Optional[PodSecurityContext] = None, readiness_probe: Optional[Probe] = None, environment_var: Optional[EnvVar] = None, volume_device: Optional[VolumeDevice] = None, command: Optional[List[str]] = None, container_security_context: Optional[SecurityContext] = None, lifecycle: Optional[Lifecycle] = None, host_alias: Optional[HostAlias] = None, env_from: Optional[List[EnvFromSource]] = None, topology_spread: Optional[TopologySpreadConstraint] = None, dns_config: Optional[PodDNSConfig] = None, ephemeral: bool = False, affinity: Optional[Affinity] = None, name: str = "test-pod", ): container = get_test_container(0, environment_var, ephemeral) if volume_mount is not None: container.volumeMounts = [volume_mount] if volume_device is not None: container.volumeDevices = [volume_device] if readiness_probe is not None: container.readinessProbe = readiness_probe container.livenessProbe = readiness_probe container.startupProbe = readiness_probe container.securityContext = container_security_context container.command = command container.lifecycle = lifecycle container.envFrom = env_from volumes = [] if volume is not None: volumes.append(volume) host_aliases = [] if host_alias is not None: host_aliases.append(host_alias) topology_spread_constraints = [] if topology_spread is not None: topology_spread_constraints.append(topology_spread) return Pod( ObjectMeta(name=name), PodSpec( [container], volumes=volumes, security_context=pod_security_context, host_aliases=host_aliases, topology_spread_constraints=topology_spread_constraints, dns_config=dns_config, affinity=affinity, ), )
def test_user_version_priority(version: str, expected_api_version: str, dependency_chart_info): class NonStandardVersionClass(Extensions): _non_standard_version = "v1beta1" def __init__(self, metadata: ObjectMeta, api_version: Optional[str] = None): super().__init__(api_version) self.metadata = metadata version_class = NonStandardVersionClass(ObjectMeta(name="test"), api_version=version) assert version_class.apiVersion == expected_api_version
def __init__( self, service_account: ServiceAccount, airflow_options: AirflowOptions ): self.role = AirflowPodRole(airflow_options) self.role_binding = RoleBinding( ObjectMeta( name="pod-controller-binding", namespace=airflow_options.pods_namespace ), RoleRef(self.role.metadata.name, "rbac.authorization.k8s.io", kind="Role"), [ Subject( service_account.metadata.name, kind="ServiceAccount", namespace=service_account.metadata.namespace, ) ], )
def metadata(): return ObjectMeta(annotations={"role": "user"}, )
from avionix.tests.utils import get_test_deployment @pytest.fixture def metadata(): return ObjectMeta(annotations={"role": "user"}, ) @pytest.mark.parametrize( "args,yaml", [ ( { "api_version": "v1", "kind": "Deployment", "metadata": ObjectMeta(name="test"), }, """apiVersion: v1 kind: Deployment metadata: name: test """, ), ( { "api_version": "v1", "kind": "Deployment", "metadata": ObjectMeta(
def __init__( self, sql_options: SqlOptions, redis_options: RedisOptions, airflow_options: AirflowOptions, monitoring_options: MonitoringOptions, cloud_options: CloudOptions, service_factory: ServiceFactory, ): storage_group_factory = StorageGroupFactory(airflow_options, cloud_options, airflow_options.namespace) dag_group = storage_group_factory.dag_volume_group log_group = storage_group_factory.log_volume_group external_volume_group = storage_group_factory.external_storage_volume_group components = [ AirflowDeployment( sql_options, redis_options, airflow_options, monitoring_options, cloud_options, ), service_factory.webserver_service, dag_group.pv, log_group.pv, dag_group.pvc, log_group.pvc, external_volume_group.pv, external_volume_group.pvc, DagRetrievalJob(airflow_options, cloud_options), AirflowIngress(airflow_options, cloud_options, service_factory), AirflowSecret( sql_options, airflow_options, redis_options, airflow_options.namespace, service_factory, ), PodTemplateWorkerConfig( sql_options, redis_options, airflow_options, monitoring_options, cloud_options, ), ] if monitoring_options.enabled: components.append(service_factory.statsd_service) if airflow_options.in_celery_mode: components.append(service_factory.flower_service) if airflow_options.in_kube_mode: airflow_pod_service_account = AirflowPodServiceAccount( airflow_options) role_group = AirflowPodRoleGroup(airflow_pod_service_account, airflow_options) components.extend([ airflow_pod_service_account, role_group.role, role_group.role_binding ]) if (airflow_options.pods_namespace != airflow_options.namespace) and airflow_options.in_kube_mode: worker_storage_groups = StorageGroupFactory( airflow_options, cloud_options, airflow_options.pods_namespace) components.extend([ Namespace(ObjectMeta(name=airflow_options.pods_namespace)), worker_storage_groups.dag_volume_group.pvc, worker_storage_groups.dag_volume_group.pv, worker_storage_groups.log_volume_group.pvc, worker_storage_groups.log_volume_group.pv, worker_storage_groups.external_storage_volume_group.pvc, worker_storage_groups.external_storage_volume_group.pv, AirflowSecret( sql_options, airflow_options, redis_options, airflow_options.pods_namespace, service_factory, ), ]) super().__init__(components)
def __init__(self, airflow_options: AirflowOptions): super().__init__( ObjectMeta(name="pod-controller", namespace=airflow_options.pods_namespace), [PolicyRule(resources=["pods"], verbs=["*"], api_groups=[""],)], )