Source code for k8s.models.pod
#!/usr/bin/env python
# -*- coding: utf-8
# Copyright 2017-2019 The FIAAS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .common import ObjectMeta, LocalObjectReference
from ..base import Model
from ..fields import Field, ListField, RequiredField
[docs]
class ContainerPort(Model):
name = Field(str)
hostPort = Field(int)
containerPort = Field(int)
protocol = Field(str, "TCP")
[docs]
class ObjectFieldSelector(Model):
apiVersion = Field(str)
fieldPath = RequiredField(str)
[docs]
class ResourceFieldSelector(Model):
containerName = Field(str)
resource = RequiredField(str)
divisor = Field(str)
[docs]
class ConfigMapKeySelector(Model):
name = Field(str)
key = RequiredField(str)
[docs]
class SecretKeySelector(Model):
name = Field(str)
key = RequiredField(str)
[docs]
class EnvVarSource(Model):
fieldRef = Field(ObjectFieldSelector)
resourceFieldRef = Field(ResourceFieldSelector)
configMapKeyRef = Field(ConfigMapKeySelector)
secretKeyRef = Field(SecretKeySelector)
[docs]
class SecretEnvSource(Model):
name = Field(str)
optional = Field(bool)
[docs]
class ConfigMapEnvSource(Model):
name = Field(str)
optional = Field(bool)
[docs]
class EnvFromSource(Model):
configMapRef = Field(ConfigMapEnvSource)
secretRef = Field(SecretEnvSource)
[docs]
class EnvVar(Model):
name = Field(str)
value = Field(str)
valueFrom = Field(EnvVarSource)
[docs]
class ResourceRequirements(Model):
limits = Field(dict)
requests = Field(dict)
[docs]
class VolumeMount(Model):
name = Field(str)
readOnly = Field(bool)
mountPath = Field(str)
[docs]
class HTTPGetAction(Model):
path = Field(str)
port = Field(str, alt_type=int)
scheme = Field(str, "HTTP")
httpHeaders = ListField(HTTPHeader)
[docs]
class TCPSocketAction(Model):
port = Field(str, alt_type=int)
[docs]
class ExecAction(Model):
command = Field(list)
[docs]
class Probe(Model):
httpGet = Field(HTTPGetAction)
tcpSocket = Field(TCPSocketAction)
_exec = Field(ExecAction)
initialDelaySeconds = Field(int, 5)
timeoutSeconds = Field(int)
successThreshold = Field(int)
failureThreshold = Field(int)
periodSeconds = Field(int)
[docs]
class Handler(Model):
httpGet = Field(HTTPGetAction)
tcpSocket = Field(TCPSocketAction)
_exec = Field(ExecAction)
[docs]
class Lifecycle(Model):
postStart = Field(Handler)
preStop = Field(Handler)
[docs]
class Container(Model):
name = Field(str)
image = Field(str)
ports = ListField(ContainerPort)
env = ListField(EnvVar)
envFrom = ListField(EnvFromSource)
resources = Field(ResourceRequirements)
volumeMounts = ListField(VolumeMount)
lifecycle = Field(Lifecycle)
livenessProbe = Field(Probe)
readinessProbe = Field(Probe)
imagePullPolicy = Field(str, "IfNotPresent")
command = ListField(str)
args = ListField(str)
[docs]
class SecretVolumeSource(Model):
secretName = Field(str)
optional = Field(bool)
defaultMode = Field(int)
[docs]
class KeyToPath(Model):
key = RequiredField(str)
path = RequiredField(str)
[docs]
class ConfigMapVolumeSource(Model):
name = Field(str)
optional = Field(bool)
defaultMode = Field(int)
[docs]
class EmptyDirVolumeSource(Model):
medium = Field(str)
[docs]
class NFSVolumeSource(Model):
path = Field(str)
readOnly = Field(bool)
server = Field(str)
[docs]
class HostPathVolumeSource(Model):
path = Field(str)
[docs]
class GCEPersistentDiskVolumeSource(Model):
fsType = Field(str)
partition = Field(int)
pdName = Field(str)
readOnly = Field(bool)
[docs]
class AWSElasticBlockStoreVolumeSource(Model):
fsType = Field(str)
partition = Field(int)
readOnly = Field(bool)
volumeID = Field(str)
[docs]
class Volume(Model):
name = Field(str)
awsElasticBlockStore = Field(AWSElasticBlockStoreVolumeSource)
configMap = Field(ConfigMapVolumeSource)
emptyDir = Field(EmptyDirVolumeSource)
gcePersistentDisk = Field(GCEPersistentDiskVolumeSource)
hostPath = Field(HostPathVolumeSource)
nfs = Field(NFSVolumeSource)
secret = Field(SecretVolumeSource)
[docs]
class PodSpec(Model):
volumes = ListField(Volume)
containers = ListField(Container)
restartPolicy = Field(str, "Always")
terminationGracePeriodSeconds = Field(int)
activeDeadlineSeconds = Field(int)
dnsPolicy = Field(str, "ClusterFirst")
nodeName = Field(str)
nodeSelector = Field(dict)
selector = Field(dict)
serviceAccountName = Field(str, "default")
automountServiceAccountToken = Field(bool)
imagePullSecrets = ListField(LocalObjectReference)
initContainers = ListField(Container)
enableServiceLinks = Field(bool)
[docs]
class PodTemplateSpec(Model):
metadata = Field(ObjectMeta)
spec = Field(PodSpec)
[docs]
class Pod(Model):
class Meta:
list_url = "/api/v1/pods"
url_template = "/api/v1/namespaces/{namespace}/pods/{name}"
metadata = Field(ObjectMeta)
spec = Field(PodSpec)