class OwnerReference(Model): api_version = StringField(name="apiVersion") block_owner_deletion = BoolField(name="blockOwnerDeletion") controller = BoolField() kind = StringField() name = StringField() uid = StringField()
class StatusDetails(Model): causes = ListField(StatusCause) group = StringField() kind = StringField() name = StringField() retry_after_seconds = IntField(name="retryAfterSeconds") uid = StringField()
class KubernetesObject(Model): api_version = None kind = None metadata = ModelField(ObjectMeta) _api_version = StringField(lambda instance: instance.api_version, name="apiVersion") _kind = StringField(lambda instance: instance.kind, name="kind") def __init__(self, name: str): super().__init__() self._name = name def prepare(self): super().prepare() self.metadata.name = self.metadata.name or f"{self.chart.prefix}-{self._name}"
class Secret(KubernetesObject): api_version = "v1" kind = "Secret" data = DictField() metadata = ModelField(ObjectMeta) string_data = DictField(name="stringData") type = StringField(default=lambda obj: "Opaque")
class ObjectMeta(Model): annotations = DictField() cluster_name = StringField(name="clusterName") creation_timestamp = StringField(name="creationTimestamp") deletion_grace_period_seconds = IntField(name="deletionGracePeriodSeconds") deletion_timestamp = StringField(name="deletionTimestamp") finalizers = ListField() generate_name = StringField(name="generateName") generation = IntField(name="generation") initializers = ModelField(Initializers) labels = DictField() name = StringField() namespace = StringField() owner_references = ListField(OwnerReference, name="ownerReferences") resource_version = StringField() self_link = StringField(name="selfLink") uid = StringField()
class ServiceSpec(Model): cluster_ip = StringField(name="clusterIP") external_ips = ListField(str, name="externalIPs") external_name = StringField(name="externalName") external_traffic_policy = StringField(name="externalTrafficPolicy") health_check_node_port = IntField(name="healthCheckNodePort") load_balancer_ip = StringField(name="loadBalancerIP") load_balancer_source_ranges = ListField(str, name="loadBalancerSourceRanges") ports = ListField(ServicePort) publish_not_ready_addresses = BoolField(name="publishNotReadyAddresses") selector = DictField() session_affinity = StringField(name="sessionAffinity") session_affinity_config = ModelField( SessionAffinityConfig, name="sessionAffinityConfig" ) type = StringField() def add_port( self, port: int, target_port: int, protocol: str = None, name: str = None ): service_port = ServicePort() service_port.port = port service_port.target_port = target_port service_port.protocol = protocol service_port.name = name self.ports.append(service_port)
class Status(Model): api_version = StringField(name="apiVersion") code = StringField() details = ModelField(StatusDetails) kind = StringField() message = StringField() metadata = ModelField(ListMeta) reason = StringField() status = StringField()
class Container(Model): args = ListField(str) command = ListField(str) env = ListField(EnvVar) env_from = ListField(EnvVarSource, "envFrom") image = StringField() image_pull_policy = StringField(name="imagePullPolicy") lifecycle = ModelField(Lifecycle) liveness_probe = ModelField(Probe, name="livenessProbe") name = StringField() ports = ListField(ContainerPort) # readiness_probe = ModelField(Probe, name="readinessProbe") resources = ModelField(ResourceRequirements) security_context = ModelField(SecurityContext, "securityContext") stdin = BoolField() stdin_once = BoolField(name="stdinOnce") termination_message_path = StringField(name="terminationMessagePath") termination_message_policy = StringField(name="terminationMessagePolicy") tty = BoolField() volume_devices = ListField(VolumeDevices, name="volumeDevices") volume_mounts = ListField(VolumeMount, "volumeMounts") working_dir = StringField(name="workingDir") def add_port( self, name: str = None, container_port: int = None, protocol: str = None ): port = ContainerPort() port.name = name port.container_port = container_port port.protocol = protocol self.ports.append(port) def add_env_from(self, typename: str, name: str): self.env_from.append({typename: {"name": name}}) def add_env(self, name: str, value: str): env = EnvVar() env.name = name env.value = value self.env.append(env) def add_volume_mount(self, name: str, mount_path: str): volume = VolumeMount() volume.name = name volume.mount_path = mount_path self.volume_mounts.append(volume) def set_image(self, repository: str, registry: str = None, tag: str = None): if (repository or repository != "docker.io") and tag: self.image = f"{registry}/{repository}:{tag}" elif repository or repository != "docker.io": self.image = f"{registry}/{repository}" elif tag: self.image = f"{repository}:tag" else: raise RuntimeError("This should not happen ever!")
class PodSpec(Model): active_deadline_seconds = IntField(name="activeDeadlineSeconds") affinity = ModelField(Affinity) automount_service_account_token = BoolField( name="automountServiceAccountToken") containers = ListField(Container) dns_config = ModelField(PodDNSConfig, "dnsConfig") dns_policy = EnumField( [ "ClusterFirst", "ClusterFirstWithHostNet", "ClusterFirst", "Default", "None" ], name="dnsPolicy", ) host_aliases = ListField(HostAlias, "hostAliases") host_ipc = BoolField(name="hostIPC") host_network = BoolField(name="hostNetwork") host_pid = BoolField(name="hostPID") hostname = StringField() image_pull_secrets = ListField(LocalObjectReference, "imagePullSecrets") init_containers = ListField(Container, "initContainers") node_name = StringField(name="nodeName") node_selector = DictField(name="nodeSelector") priority = IntField() priority_class_name = StringField(name="priorityClassName") readiness_gates = ListField(PodReadlinessGate, name="readinessGates") restart_policy = EnumField(["Always", "OnFailure", "Never"], name="restartPolicy") scheduler_name = StringField(name="schedulerName") security_context = ModelField(SecurityContext, "securityContext") service_account_name = StringField(name="serviceAccountName") share_process_namespace = BoolField(name="shareProcessNamespace") subdomain = StringField() termination_grace_period_seconds = IntField( name="terminationGracePeriodSeconds") tolerations = ListField(Toleration, "tolerations") volumes = ListField(Volume)
class ContainerPort(Model): container_port = PortField(name="containerPort") host_ip = StringField(name="hostIP") host_port = PortField(name="hostPort") name = StringField() protocol = StringField()
class SELinuxOptions(Model): level = StringField() role = StringField() type = StringField() user = StringField()
class StatusCause(Model): field = StringField() message = StringField() reason = StringField()
class LabelSelectorRequirement(Model): key = StringField() operator = StringField() values = ListField(str)
class ListMeta(Model): continue_ = StringField(name="continue") resource_version = StringField(name="resourceVersion") self_link = StringField(name="selfLink")
class ResourceRequirementsElement(Model): cpu = StringField() memory = StringField()
class ServicePort(Model): name = StringField() node_port = PortField(name="nodePort") port = PortField() protocol = StringField() target_port = PortField(name="targetPort")
class VolumeMount(Model): mount_path = StringField(name="mountPath") mount_propagation = StringField(name="mountPropagation") name = StringField() readOnly = BoolField() sub_path = StringField()
class Initializer(Model): name = StringField()