From d452a6db29282f72f10fa074c197d7e5ecc9491d Mon Sep 17 00:00:00 2001 From: iliapolo Date: Thu, 31 Mar 2022 20:13:53 +0300 Subject: [PATCH 1/2] daemon set Signed-off-by: iliapolo --- docs/java.md | 588 ++++++++++++- docs/python.md | 964 ++++++++++++++++++++- docs/typescript.md | 438 +++++++++- src/daemon-set.ts | 162 ++++ src/index.ts | 1 + test/__snapshots__/daemon-set.test.ts.snap | 105 +++ test/daemon-set.test.ts | 97 +++ 7 files changed, 2346 insertions(+), 9 deletions(-) create mode 100644 src/daemon-set.ts create mode 100644 test/__snapshots__/daemon-set.test.ts.snap create mode 100644 test/daemon-set.test.ts diff --git a/docs/java.md b/docs/java.md index 5c4e9fab0..55799366d 100644 --- a/docs/java.md +++ b/docs/java.md @@ -752,6 +752,388 @@ Returns an copy. To add data records, use `addData()` or `addBinaryData()`. --- +### DaemonSet + +- *Implements:* [`org.cdk8s.plus22.IPodTemplate`](#org.cdk8s.plus22.IPodTemplate) + +A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. + +As nodes are added to the cluster, Pods are added to them. +As nodes are removed from the cluster, those Pods are garbage collected. +Deleting a DaemonSet will clean up the Pods it created. + +Some typical uses of a DaemonSet are: + +* running a cluster storage daemon on every node +* running a logs collection daemon on every node +* running a node monitoring daemon on every node + +In a simple case, one DaemonSet, covering all nodes, would be used for each type of daemon. +A more complex setup might use multiple DaemonSets for a single type of daemon, +but with different flags and/or different memory and cpu requests for different hardware types. + +#### Initializers + +```java +import org.cdk8s.plus22.DaemonSet; + +DaemonSet.Builder.create(Construct scope, java.lang.String id) +// .metadata(ApiObjectMetadata) +// .containers(java.util.List) +// .hostAliases(java.util.List) +// .initContainers(java.util.List) +// .restartPolicy(RestartPolicy) +// .securityContext(PodSecurityContextProps) +// .serviceAccount(IServiceAccount) +// .volumes(java.util.List) +// .podMetadata(ApiObjectMetadata) +// .defaultSelector(java.lang.Boolean) +// .minReadySeconds(java.lang.Number) + .build(); +``` + +##### `scope`Required + +- *Type:* [`software.constructs.Construct`](#software.constructs.Construct) + +--- + +##### `id`Required + +- *Type:* `java.lang.String` + +--- + +##### `metadata`Optional + +- *Type:* [`org.cdk8s.ApiObjectMetadata`](#org.cdk8s.ApiObjectMetadata) + +Metadata that all persisted resources must have, which includes all objects users must create. + +--- + +##### `containers`Optional + +- *Type:* java.util.List<[`org.cdk8s.plus22.ContainerProps`](#org.cdk8s.plus22.ContainerProps)> +- *Default:* No containers. Note that a pod spec must include at least one container. + +List of containers belonging to the pod. + +Containers cannot currently be +added or removed. There must be at least one container in a Pod. + +You can add additionnal containers using `podSpec.addContainer()` + +--- + +##### `hostAliases`Optional + +- *Type:* java.util.List<[`org.cdk8s.plus22.HostAlias`](#org.cdk8s.plus22.HostAlias)> + +HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file. + +--- + +##### `initContainers`Optional + +- *Type:* java.util.List<[`org.cdk8s.plus22.ContainerProps`](#org.cdk8s.plus22.ContainerProps)> +- *Default:* No init containers. + +List of initialization containers belonging to the pod. + +Init containers are executed in order prior to containers being started. +If any init container fails, the pod is considered to have failed and is handled according to its restartPolicy. +The name for an init container or normal container must be unique among all containers. +Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. +The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limit +for each resource type, and then using the max of of that value or the sum of the normal containers. +Limits are applied to init containers in a similar fashion. + +Init containers cannot currently be added ,removed or updated. + +> https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ + +--- + +##### `restartPolicy`Optional + +- *Type:* [`org.cdk8s.plus22.RestartPolicy`](#org.cdk8s.plus22.RestartPolicy) +- *Default:* RestartPolicy.ALWAYS + +Restart policy for all containers within the pod. + +> https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy + +--- + +##### `securityContext`Optional + +- *Type:* [`org.cdk8s.plus22.PodSecurityContextProps`](#org.cdk8s.plus22.PodSecurityContextProps) +- *Default:* fsGroupChangePolicy: FsGroupChangePolicy.FsGroupChangePolicy.ALWAYS + ensureNonRoot: false + +SecurityContext holds pod-level security attributes and common container settings. + +--- + +##### `serviceAccount`Optional + +- *Type:* [`org.cdk8s.plus22.IServiceAccount`](#org.cdk8s.plus22.IServiceAccount) +- *Default:* No service account. + +A service account provides an identity for processes that run in a Pod. + +When you (a human) access the cluster (for example, using kubectl), you are +authenticated by the apiserver as a particular User Account (currently this +is usually admin, unless your cluster administrator has customized your +cluster). Processes in containers inside pods can also contact the +apiserver. When they do, they are authenticated as a particular Service +Account (for example, default). + +> https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ + +--- + +##### `volumes`Optional + +- *Type:* java.util.List<[`org.cdk8s.plus22.Volume`](#org.cdk8s.plus22.Volume)> +- *Default:* No volumes. + +List of volumes that can be mounted by containers belonging to the pod. + +You can also add volumes later using `podSpec.addVolume()` + +> https://kubernetes.io/docs/concepts/storage/volumes + +--- + +##### `podMetadata`Optional + +- *Type:* [`org.cdk8s.ApiObjectMetadata`](#org.cdk8s.ApiObjectMetadata) + +The pod metadata. + +--- + +##### `defaultSelector`Optional + +- *Type:* `java.lang.Boolean` +- *Default:* true + +Automatically allocates a pod selector for this daemon set. + +If this is set to `false` you must define your selector through +`dset.podMetadata.addLabel()` and `dset.selectByLabel()`. + +--- + +##### `minReadySeconds`Optional + +- *Type:* `java.lang.Number` +- *Default:* 0 + +Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. + +--- + +#### Methods + +##### `addContainer` + +```java +public addContainer(ContainerProps container) +``` + +###### `container`Required + +- *Type:* [`org.cdk8s.plus22.ContainerProps`](#org.cdk8s.plus22.ContainerProps) + +--- + +##### `addHostAlias` + +```java +public addHostAlias(HostAlias hostAlias) +``` + +###### `hostAlias`Required + +- *Type:* [`org.cdk8s.plus22.HostAlias`](#org.cdk8s.plus22.HostAlias) + +--- + +##### `addInitContainer` + +```java +public addInitContainer(ContainerProps container) +``` + +###### `container`Required + +- *Type:* [`org.cdk8s.plus22.ContainerProps`](#org.cdk8s.plus22.ContainerProps) + +--- + +##### `addVolume` + +```java +public addVolume(Volume volume) +``` + +###### `volume`Required + +- *Type:* [`org.cdk8s.plus22.Volume`](#org.cdk8s.plus22.Volume) + +--- + +##### `selectByLabel` + +```java +public selectByLabel(java.lang.String key, java.lang.String value) +``` + +###### `key`Required + +- *Type:* `java.lang.String` + +--- + +###### `value`Required + +- *Type:* `java.lang.String` + +--- + + +#### Properties + +##### `containers`Required + +```java +public java.util.List getContainers(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.Container`](#org.cdk8s.plus22.Container)> + +The containers belonging to the pod. + +Use `addContainer` to add containers. + +--- + +##### `hostAliases`Required + +```java +public java.util.List getHostAliases(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.HostAlias`](#org.cdk8s.plus22.HostAlias)> + +An optional list of hosts and IPs that will be injected into the pod's hosts file if specified. + +This is only valid for non-hostNetwork pods. + +--- + +##### `initContainers`Required + +```java +public java.util.List getInitContainers(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.Container`](#org.cdk8s.plus22.Container)> + +The init containers belonging to the pod. + +Use `addInitContainer` to add init containers. + +--- + +##### `labelSelector`Required + +```java +public java.util.Map getLabelSelector(); +``` + +- *Type:* java.util.Map + +The labels this daemon set will match against in order to select pods. + +Returns a a copy. Use `selectByLabel()` to add labels. + +--- + +##### `minReadySeconds`Required + +```java +public java.lang.Number getMinReadySeconds(); +``` + +- *Type:* `java.lang.Number` + +--- + +##### `podMetadata`Required + +```java +public ApiObjectMetadataDefinition getPodMetadata(); +``` + +- *Type:* [`org.cdk8s.ApiObjectMetadataDefinition`](#org.cdk8s.ApiObjectMetadataDefinition) + +Provides read/write access to the underlying pod metadata of the resource. + +--- + +##### `securityContext`Required + +```java +public PodSecurityContext getSecurityContext(); +``` + +- *Type:* [`org.cdk8s.plus22.PodSecurityContext`](#org.cdk8s.plus22.PodSecurityContext) + +--- + +##### `volumes`Required + +```java +public java.util.List getVolumes(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.Volume`](#org.cdk8s.plus22.Volume)> + +The volumes associated with this pod. + +Use `addVolume` to add volumes. + +--- + +##### `restartPolicy`Optional + +```java +public RestartPolicy getRestartPolicy(); +``` + +- *Type:* [`org.cdk8s.plus22.RestartPolicy`](#org.cdk8s.plus22.RestartPolicy) + +Restart policy for all containers within the pod. + +--- + +##### `serviceAccount`Optional + +```java +public IServiceAccount getServiceAccount(); +``` + +- *Type:* [`org.cdk8s.plus22.IServiceAccount`](#org.cdk8s.plus22.IServiceAccount) + +The service account used to run this pod. + +--- + + ### Deployment - *Implements:* [`org.cdk8s.plus22.IPodTemplate`](#org.cdk8s.plus22.IPodTemplate) @@ -5297,6 +5679,206 @@ public Cpu getRequest(); --- +### DaemonSetProps + +Properties for `DaemonSet`. + +#### Initializer + +```java +import org.cdk8s.plus22.DaemonSetProps; + +DaemonSetProps.builder() +// .metadata(ApiObjectMetadata) +// .containers(java.util.List) +// .hostAliases(java.util.List) +// .initContainers(java.util.List) +// .restartPolicy(RestartPolicy) +// .securityContext(PodSecurityContextProps) +// .serviceAccount(IServiceAccount) +// .volumes(java.util.List) +// .podMetadata(ApiObjectMetadata) +// .defaultSelector(java.lang.Boolean) +// .minReadySeconds(java.lang.Number) + .build(); +``` + +##### `metadata`Optional + +```java +public ApiObjectMetadata getMetadata(); +``` + +- *Type:* [`org.cdk8s.ApiObjectMetadata`](#org.cdk8s.ApiObjectMetadata) + +Metadata that all persisted resources must have, which includes all objects users must create. + +--- + +##### `containers`Optional + +```java +public java.util.List getContainers(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.ContainerProps`](#org.cdk8s.plus22.ContainerProps)> +- *Default:* No containers. Note that a pod spec must include at least one container. + +List of containers belonging to the pod. + +Containers cannot currently be +added or removed. There must be at least one container in a Pod. + +You can add additionnal containers using `podSpec.addContainer()` + +--- + +##### `hostAliases`Optional + +```java +public java.util.List getHostAliases(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.HostAlias`](#org.cdk8s.plus22.HostAlias)> + +HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file. + +--- + +##### `initContainers`Optional + +```java +public java.util.List getInitContainers(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.ContainerProps`](#org.cdk8s.plus22.ContainerProps)> +- *Default:* No init containers. + +List of initialization containers belonging to the pod. + +Init containers are executed in order prior to containers being started. +If any init container fails, the pod is considered to have failed and is handled according to its restartPolicy. +The name for an init container or normal container must be unique among all containers. +Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. +The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limit +for each resource type, and then using the max of of that value or the sum of the normal containers. +Limits are applied to init containers in a similar fashion. + +Init containers cannot currently be added ,removed or updated. + +> https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ + +--- + +##### `restartPolicy`Optional + +```java +public RestartPolicy getRestartPolicy(); +``` + +- *Type:* [`org.cdk8s.plus22.RestartPolicy`](#org.cdk8s.plus22.RestartPolicy) +- *Default:* RestartPolicy.ALWAYS + +Restart policy for all containers within the pod. + +> https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy + +--- + +##### `securityContext`Optional + +```java +public PodSecurityContextProps getSecurityContext(); +``` + +- *Type:* [`org.cdk8s.plus22.PodSecurityContextProps`](#org.cdk8s.plus22.PodSecurityContextProps) +- *Default:* fsGroupChangePolicy: FsGroupChangePolicy.FsGroupChangePolicy.ALWAYS + ensureNonRoot: false + +SecurityContext holds pod-level security attributes and common container settings. + +--- + +##### `serviceAccount`Optional + +```java +public IServiceAccount getServiceAccount(); +``` + +- *Type:* [`org.cdk8s.plus22.IServiceAccount`](#org.cdk8s.plus22.IServiceAccount) +- *Default:* No service account. + +A service account provides an identity for processes that run in a Pod. + +When you (a human) access the cluster (for example, using kubectl), you are +authenticated by the apiserver as a particular User Account (currently this +is usually admin, unless your cluster administrator has customized your +cluster). Processes in containers inside pods can also contact the +apiserver. When they do, they are authenticated as a particular Service +Account (for example, default). + +> https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ + +--- + +##### `volumes`Optional + +```java +public java.util.List getVolumes(); +``` + +- *Type:* java.util.List<[`org.cdk8s.plus22.Volume`](#org.cdk8s.plus22.Volume)> +- *Default:* No volumes. + +List of volumes that can be mounted by containers belonging to the pod. + +You can also add volumes later using `podSpec.addVolume()` + +> https://kubernetes.io/docs/concepts/storage/volumes + +--- + +##### `podMetadata`Optional + +```java +public ApiObjectMetadata getPodMetadata(); +``` + +- *Type:* [`org.cdk8s.ApiObjectMetadata`](#org.cdk8s.ApiObjectMetadata) + +The pod metadata. + +--- + +##### `defaultSelector`Optional + +```java +public java.lang.Boolean getDefaultSelector(); +``` + +- *Type:* `java.lang.Boolean` +- *Default:* true + +Automatically allocates a pod selector for this daemon set. + +If this is set to `false` you must define your selector through +`dset.podMetadata.addLabel()` and `dset.selectByLabel()`. + +--- + +##### `minReadySeconds`Optional + +```java +public java.lang.Number getMinReadySeconds(); +``` + +- *Type:* `java.lang.Number` +- *Default:* 0 + +Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. + +--- + ### DeploymentProps Properties for initialization of `Deployment`. @@ -10913,7 +11495,7 @@ The Kubernetes name of this resource. ### IPodSpec -- *Implemented By:* [`org.cdk8s.plus22.Deployment`](#org.cdk8s.plus22.Deployment), [`org.cdk8s.plus22.Job`](#org.cdk8s.plus22.Job), [`org.cdk8s.plus22.Pod`](#org.cdk8s.plus22.Pod), [`org.cdk8s.plus22.PodSpec`](#org.cdk8s.plus22.PodSpec), [`org.cdk8s.plus22.PodTemplate`](#org.cdk8s.plus22.PodTemplate), [`org.cdk8s.plus22.StatefulSet`](#org.cdk8s.plus22.StatefulSet), [`org.cdk8s.plus22.IPodSpec`](#org.cdk8s.plus22.IPodSpec), [`org.cdk8s.plus22.IPodTemplate`](#org.cdk8s.plus22.IPodTemplate) +- *Implemented By:* [`org.cdk8s.plus22.DaemonSet`](#org.cdk8s.plus22.DaemonSet), [`org.cdk8s.plus22.Deployment`](#org.cdk8s.plus22.Deployment), [`org.cdk8s.plus22.Job`](#org.cdk8s.plus22.Job), [`org.cdk8s.plus22.Pod`](#org.cdk8s.plus22.Pod), [`org.cdk8s.plus22.PodSpec`](#org.cdk8s.plus22.PodSpec), [`org.cdk8s.plus22.PodTemplate`](#org.cdk8s.plus22.PodTemplate), [`org.cdk8s.plus22.StatefulSet`](#org.cdk8s.plus22.StatefulSet), [`org.cdk8s.plus22.IPodSpec`](#org.cdk8s.plus22.IPodSpec), [`org.cdk8s.plus22.IPodTemplate`](#org.cdk8s.plus22.IPodTemplate) Represents a resource that can be configured with a kuberenets pod spec. (e.g `Deployment`, `Job`, `Pod`, ...). @@ -11049,7 +11631,7 @@ The service account used to run this pod. - *Extends:* [`org.cdk8s.plus22.IPodSpec`](#org.cdk8s.plus22.IPodSpec) -- *Implemented By:* [`org.cdk8s.plus22.Deployment`](#org.cdk8s.plus22.Deployment), [`org.cdk8s.plus22.Job`](#org.cdk8s.plus22.Job), [`org.cdk8s.plus22.PodTemplate`](#org.cdk8s.plus22.PodTemplate), [`org.cdk8s.plus22.StatefulSet`](#org.cdk8s.plus22.StatefulSet), [`org.cdk8s.plus22.IPodTemplate`](#org.cdk8s.plus22.IPodTemplate) +- *Implemented By:* [`org.cdk8s.plus22.DaemonSet`](#org.cdk8s.plus22.DaemonSet), [`org.cdk8s.plus22.Deployment`](#org.cdk8s.plus22.Deployment), [`org.cdk8s.plus22.Job`](#org.cdk8s.plus22.Job), [`org.cdk8s.plus22.PodTemplate`](#org.cdk8s.plus22.PodTemplate), [`org.cdk8s.plus22.StatefulSet`](#org.cdk8s.plus22.StatefulSet), [`org.cdk8s.plus22.IPodTemplate`](#org.cdk8s.plus22.IPodTemplate) Represents a resource that can be configured with a kuberenets pod template. (e.g `Deployment`, `Job`, ...). @@ -11152,7 +11734,7 @@ Provides read/write access to the underlying pod metadata of the resource. ### IResource -- *Implemented By:* [`org.cdk8s.plus22.AwsElasticBlockStorePersistentVolume`](#org.cdk8s.plus22.AwsElasticBlockStorePersistentVolume), [`org.cdk8s.plus22.AzureDiskPersistentVolume`](#org.cdk8s.plus22.AzureDiskPersistentVolume), [`org.cdk8s.plus22.BasicAuthSecret`](#org.cdk8s.plus22.BasicAuthSecret), [`org.cdk8s.plus22.ConfigMap`](#org.cdk8s.plus22.ConfigMap), [`org.cdk8s.plus22.Deployment`](#org.cdk8s.plus22.Deployment), [`org.cdk8s.plus22.DockerConfigSecret`](#org.cdk8s.plus22.DockerConfigSecret), [`org.cdk8s.plus22.GCEPersistentDiskPersistentVolume`](#org.cdk8s.plus22.GCEPersistentDiskPersistentVolume), [`org.cdk8s.plus22.Ingress`](#org.cdk8s.plus22.Ingress), [`org.cdk8s.plus22.Job`](#org.cdk8s.plus22.Job), [`org.cdk8s.plus22.PersistentVolume`](#org.cdk8s.plus22.PersistentVolume), [`org.cdk8s.plus22.PersistentVolumeClaim`](#org.cdk8s.plus22.PersistentVolumeClaim), [`org.cdk8s.plus22.Pod`](#org.cdk8s.plus22.Pod), [`org.cdk8s.plus22.Resource`](#org.cdk8s.plus22.Resource), [`org.cdk8s.plus22.Secret`](#org.cdk8s.plus22.Secret), [`org.cdk8s.plus22.Service`](#org.cdk8s.plus22.Service), [`org.cdk8s.plus22.ServiceAccount`](#org.cdk8s.plus22.ServiceAccount), [`org.cdk8s.plus22.ServiceAccountTokenSecret`](#org.cdk8s.plus22.ServiceAccountTokenSecret), [`org.cdk8s.plus22.SshAuthSecret`](#org.cdk8s.plus22.SshAuthSecret), [`org.cdk8s.plus22.StatefulSet`](#org.cdk8s.plus22.StatefulSet), [`org.cdk8s.plus22.TlsSecret`](#org.cdk8s.plus22.TlsSecret), [`org.cdk8s.plus22.IConfigMap`](#org.cdk8s.plus22.IConfigMap), [`org.cdk8s.plus22.IPersistentVolume`](#org.cdk8s.plus22.IPersistentVolume), [`org.cdk8s.plus22.IPersistentVolumeClaim`](#org.cdk8s.plus22.IPersistentVolumeClaim), [`org.cdk8s.plus22.IResource`](#org.cdk8s.plus22.IResource), [`org.cdk8s.plus22.ISecret`](#org.cdk8s.plus22.ISecret), [`org.cdk8s.plus22.IServiceAccount`](#org.cdk8s.plus22.IServiceAccount) +- *Implemented By:* [`org.cdk8s.plus22.AwsElasticBlockStorePersistentVolume`](#org.cdk8s.plus22.AwsElasticBlockStorePersistentVolume), [`org.cdk8s.plus22.AzureDiskPersistentVolume`](#org.cdk8s.plus22.AzureDiskPersistentVolume), [`org.cdk8s.plus22.BasicAuthSecret`](#org.cdk8s.plus22.BasicAuthSecret), [`org.cdk8s.plus22.ConfigMap`](#org.cdk8s.plus22.ConfigMap), [`org.cdk8s.plus22.DaemonSet`](#org.cdk8s.plus22.DaemonSet), [`org.cdk8s.plus22.Deployment`](#org.cdk8s.plus22.Deployment), [`org.cdk8s.plus22.DockerConfigSecret`](#org.cdk8s.plus22.DockerConfigSecret), [`org.cdk8s.plus22.GCEPersistentDiskPersistentVolume`](#org.cdk8s.plus22.GCEPersistentDiskPersistentVolume), [`org.cdk8s.plus22.Ingress`](#org.cdk8s.plus22.Ingress), [`org.cdk8s.plus22.Job`](#org.cdk8s.plus22.Job), [`org.cdk8s.plus22.PersistentVolume`](#org.cdk8s.plus22.PersistentVolume), [`org.cdk8s.plus22.PersistentVolumeClaim`](#org.cdk8s.plus22.PersistentVolumeClaim), [`org.cdk8s.plus22.Pod`](#org.cdk8s.plus22.Pod), [`org.cdk8s.plus22.Resource`](#org.cdk8s.plus22.Resource), [`org.cdk8s.plus22.Secret`](#org.cdk8s.plus22.Secret), [`org.cdk8s.plus22.Service`](#org.cdk8s.plus22.Service), [`org.cdk8s.plus22.ServiceAccount`](#org.cdk8s.plus22.ServiceAccount), [`org.cdk8s.plus22.ServiceAccountTokenSecret`](#org.cdk8s.plus22.ServiceAccountTokenSecret), [`org.cdk8s.plus22.SshAuthSecret`](#org.cdk8s.plus22.SshAuthSecret), [`org.cdk8s.plus22.StatefulSet`](#org.cdk8s.plus22.StatefulSet), [`org.cdk8s.plus22.TlsSecret`](#org.cdk8s.plus22.TlsSecret), [`org.cdk8s.plus22.IConfigMap`](#org.cdk8s.plus22.IConfigMap), [`org.cdk8s.plus22.IPersistentVolume`](#org.cdk8s.plus22.IPersistentVolume), [`org.cdk8s.plus22.IPersistentVolumeClaim`](#org.cdk8s.plus22.IPersistentVolumeClaim), [`org.cdk8s.plus22.IResource`](#org.cdk8s.plus22.IResource), [`org.cdk8s.plus22.ISecret`](#org.cdk8s.plus22.ISecret), [`org.cdk8s.plus22.IServiceAccount`](#org.cdk8s.plus22.IServiceAccount) Represents a resource. diff --git a/docs/python.md b/docs/python.md index 12cf89106..982c39e0a 100644 --- a/docs/python.md +++ b/docs/python.md @@ -783,6 +783,764 @@ Returns an copy. To add data records, use `addData()` or `addBinaryData()`. --- +### DaemonSet + +- *Implements:* [`cdk8s_plus_22.IPodTemplate`](#cdk8s_plus_22.IPodTemplate) + +A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. + +As nodes are added to the cluster, Pods are added to them. +As nodes are removed from the cluster, those Pods are garbage collected. +Deleting a DaemonSet will clean up the Pods it created. + +Some typical uses of a DaemonSet are: + +* running a cluster storage daemon on every node +* running a logs collection daemon on every node +* running a node monitoring daemon on every node + +In a simple case, one DaemonSet, covering all nodes, would be used for each type of daemon. +A more complex setup might use multiple DaemonSets for a single type of daemon, +but with different flags and/or different memory and cpu requests for different hardware types. + +#### Initializers + +```python +import cdk8s_plus_22 + +cdk8s_plus_22.DaemonSet( + scope: Construct, + id: str, + metadata: ApiObjectMetadata = None, + containers: typing.List[ContainerProps] = None, + host_aliases: typing.List[HostAlias] = None, + init_containers: typing.List[ContainerProps] = None, + restart_policy: RestartPolicy = None, + security_context: PodSecurityContextProps = None, + service_account: IServiceAccount = None, + volumes: typing.List[Volume] = None, + pod_metadata: ApiObjectMetadata = None, + default_selector: bool = None, + min_ready_seconds: typing.Union[int, float] = None +) +``` + +##### `scope`Required + +- *Type:* [`constructs.Construct`](#constructs.Construct) + +--- + +##### `id`Required + +- *Type:* `str` + +--- + +##### `metadata`Optional + +- *Type:* [`cdk8s.ApiObjectMetadata`](#cdk8s.ApiObjectMetadata) + +Metadata that all persisted resources must have, which includes all objects users must create. + +--- + +##### `containers`Optional + +- *Type:* typing.List[[`cdk8s_plus_22.ContainerProps`](#cdk8s_plus_22.ContainerProps)] +- *Default:* No containers. Note that a pod spec must include at least one container. + +List of containers belonging to the pod. + +Containers cannot currently be +added or removed. There must be at least one container in a Pod. + +You can add additionnal containers using `podSpec.addContainer()` + +--- + +##### `host_aliases`Optional + +- *Type:* typing.List[[`cdk8s_plus_22.HostAlias`](#cdk8s_plus_22.HostAlias)] + +HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file. + +--- + +##### `init_containers`Optional + +- *Type:* typing.List[[`cdk8s_plus_22.ContainerProps`](#cdk8s_plus_22.ContainerProps)] +- *Default:* No init containers. + +List of initialization containers belonging to the pod. + +Init containers are executed in order prior to containers being started. +If any init container fails, the pod is considered to have failed and is handled according to its restartPolicy. +The name for an init container or normal container must be unique among all containers. +Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. +The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limit +for each resource type, and then using the max of of that value or the sum of the normal containers. +Limits are applied to init containers in a similar fashion. + +Init containers cannot currently be added ,removed or updated. + +> https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ + +--- + +##### `restart_policy`Optional + +- *Type:* [`cdk8s_plus_22.RestartPolicy`](#cdk8s_plus_22.RestartPolicy) +- *Default:* RestartPolicy.ALWAYS + +Restart policy for all containers within the pod. + +> https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy + +--- + +##### `security_context`Optional + +- *Type:* [`cdk8s_plus_22.PodSecurityContextProps`](#cdk8s_plus_22.PodSecurityContextProps) +- *Default:* fsGroupChangePolicy: FsGroupChangePolicy.FsGroupChangePolicy.ALWAYS + ensureNonRoot: false + +SecurityContext holds pod-level security attributes and common container settings. + +--- + +##### `service_account`Optional + +- *Type:* [`cdk8s_plus_22.IServiceAccount`](#cdk8s_plus_22.IServiceAccount) +- *Default:* No service account. + +A service account provides an identity for processes that run in a Pod. + +When you (a human) access the cluster (for example, using kubectl), you are +authenticated by the apiserver as a particular User Account (currently this +is usually admin, unless your cluster administrator has customized your +cluster). Processes in containers inside pods can also contact the +apiserver. When they do, they are authenticated as a particular Service +Account (for example, default). + +> https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ + +--- + +##### `volumes`Optional + +- *Type:* typing.List[[`cdk8s_plus_22.Volume`](#cdk8s_plus_22.Volume)] +- *Default:* No volumes. + +List of volumes that can be mounted by containers belonging to the pod. + +You can also add volumes later using `podSpec.addVolume()` + +> https://kubernetes.io/docs/concepts/storage/volumes + +--- + +##### `pod_metadata`Optional + +- *Type:* [`cdk8s.ApiObjectMetadata`](#cdk8s.ApiObjectMetadata) + +The pod metadata. + +--- + +##### `default_selector`Optional + +- *Type:* `bool` +- *Default:* true + +Automatically allocates a pod selector for this daemon set. + +If this is set to `false` you must define your selector through +`dset.podMetadata.addLabel()` and `dset.selectByLabel()`. + +--- + +##### `min_ready_seconds`Optional + +- *Type:* `typing.Union[int, float]` +- *Default:* 0 + +Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. + +--- + +#### Methods + +##### `add_container` + +```python +def add_container( + image: str, + args: typing.List[str] = None, + command: typing.List[str] = None, + env: typing.Mapping[EnvValue] = None, + image_pull_policy: ImagePullPolicy = None, + lifecycle: ContainerLifecycle = None, + liveness: Probe = None, + name: str = None, + port: typing.Union[int, float] = None, + readiness: Probe = None, + resources: Resources = None, + security_context: ContainerSecurityContextProps = None, + startup: Probe = None, + volume_mounts: typing.List[VolumeMount] = None, + working_dir: str = None +) +``` + +###### `image`Required + +- *Type:* `str` + +Docker image name. + +--- + +###### `args`Optional + +- *Type:* typing.List[`str`] +- *Default:* [] + +Arguments to the entrypoint. The docker image's CMD is used if `command` is not provided. + +Variable references $(VAR_NAME) are expanded using the container's +environment. If a variable cannot be resolved, the reference in the input +string will be unchanged. The $(VAR_NAME) syntax can be escaped with a +double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, +regardless of whether the variable exists or not. + +Cannot be updated. + +> https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell + +--- + +###### `command`Optional + +- *Type:* typing.List[`str`] +- *Default:* The docker image's ENTRYPOINT. + +Entrypoint array. + +Not executed within a shell. The docker image's ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. +If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). +Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. +More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell + +--- + +###### `env`Optional + +- *Type:* typing.Mapping[[`cdk8s_plus_22.EnvValue`](#cdk8s_plus_22.EnvValue)] +- *Default:* No environment variables. + +List of environment variables to set in the container. + +Cannot be updated. + +--- + +###### `image_pull_policy`Optional + +- *Type:* [`cdk8s_plus_22.ImagePullPolicy`](#cdk8s_plus_22.ImagePullPolicy) +- *Default:* ImagePullPolicy.ALWAYS + +Image pull policy for this container. + +--- + +###### `lifecycle`Optional + +- *Type:* [`cdk8s_plus_22.ContainerLifecycle`](#cdk8s_plus_22.ContainerLifecycle) + +Describes actions that the management system should take in response to container lifecycle events. + +--- + +###### `liveness`Optional + +- *Type:* [`cdk8s_plus_22.Probe`](#cdk8s_plus_22.Probe) +- *Default:* no liveness probe is defined + +Periodic probe of container liveness. + +Container will be restarted if the probe fails. + +--- + +###### `name`Optional + +- *Type:* `str` +- *Default:* 'main' + +Name of the container specified as a DNS_LABEL. + +Each container in a pod must have a unique name (DNS_LABEL). Cannot be updated. + +--- + +###### `port`Optional + +- *Type:* `typing.Union[int, float]` +- *Default:* No port is exposed. + +Number of port to expose on the pod's IP address. + +This must be a valid port number, 0 < x < 65536. + +--- + +###### `readiness`Optional + +- *Type:* [`cdk8s_plus_22.Probe`](#cdk8s_plus_22.Probe) +- *Default:* no readiness probe is defined + +Determines when the container is ready to serve traffic. + +--- + +###### `resources`Optional + +- *Type:* [`cdk8s_plus_22.Resources`](#cdk8s_plus_22.Resources) + +Compute resources (CPU and memory requests and limits) required by the container. + +> https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + +--- + +###### `security_context`Optional + +- *Type:* [`cdk8s_plus_22.ContainerSecurityContextProps`](#cdk8s_plus_22.ContainerSecurityContextProps) +- *Default:* ensureNonRoot: false + privileged: false + readOnlyRootFilesystem: false + +SecurityContext defines the security options the container should be run with. + +If set, the fields override equivalent fields of the pod's security context. + +> https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + +--- + +###### `startup`Optional + +- *Type:* [`cdk8s_plus_22.Probe`](#cdk8s_plus_22.Probe) +- *Default:* no startup probe is defined. + +StartupProbe indicates that the Pod has successfully initialized. + +If specified, no other probes are executed until this completes successfully + +--- + +###### `volume_mounts`Optional + +- *Type:* typing.List[[`cdk8s_plus_22.VolumeMount`](#cdk8s_plus_22.VolumeMount)] + +Pod volumes to mount into the container's filesystem. + +Cannot be updated. + +--- + +###### `working_dir`Optional + +- *Type:* `str` +- *Default:* The container runtime's default. + +Container's working directory. + +If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. + +--- + +##### `add_host_alias` + +```python +def add_host_alias( + hostnames: typing.List[str], + ip: str +) +``` + +###### `hostnames`Required + +- *Type:* typing.List[`str`] + +Hostnames for the chosen IP address. + +--- + +###### `ip`Required + +- *Type:* `str` + +IP address of the host file entry. + +--- + +##### `add_init_container` + +```python +def add_init_container( + image: str, + args: typing.List[str] = None, + command: typing.List[str] = None, + env: typing.Mapping[EnvValue] = None, + image_pull_policy: ImagePullPolicy = None, + lifecycle: ContainerLifecycle = None, + liveness: Probe = None, + name: str = None, + port: typing.Union[int, float] = None, + readiness: Probe = None, + resources: Resources = None, + security_context: ContainerSecurityContextProps = None, + startup: Probe = None, + volume_mounts: typing.List[VolumeMount] = None, + working_dir: str = None +) +``` + +###### `image`Required + +- *Type:* `str` + +Docker image name. + +--- + +###### `args`Optional + +- *Type:* typing.List[`str`] +- *Default:* [] + +Arguments to the entrypoint. The docker image's CMD is used if `command` is not provided. + +Variable references $(VAR_NAME) are expanded using the container's +environment. If a variable cannot be resolved, the reference in the input +string will be unchanged. The $(VAR_NAME) syntax can be escaped with a +double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, +regardless of whether the variable exists or not. + +Cannot be updated. + +> https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell + +--- + +###### `command`Optional + +- *Type:* typing.List[`str`] +- *Default:* The docker image's ENTRYPOINT. + +Entrypoint array. + +Not executed within a shell. The docker image's ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME) are expanded using the container's environment. +If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). +Escaped references will never be expanded, regardless of whether the variable exists or not. Cannot be updated. +More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell + +--- + +###### `env`Optional + +- *Type:* typing.Mapping[[`cdk8s_plus_22.EnvValue`](#cdk8s_plus_22.EnvValue)] +- *Default:* No environment variables. + +List of environment variables to set in the container. + +Cannot be updated. + +--- + +###### `image_pull_policy`Optional + +- *Type:* [`cdk8s_plus_22.ImagePullPolicy`](#cdk8s_plus_22.ImagePullPolicy) +- *Default:* ImagePullPolicy.ALWAYS + +Image pull policy for this container. + +--- + +###### `lifecycle`Optional + +- *Type:* [`cdk8s_plus_22.ContainerLifecycle`](#cdk8s_plus_22.ContainerLifecycle) + +Describes actions that the management system should take in response to container lifecycle events. + +--- + +###### `liveness`Optional + +- *Type:* [`cdk8s_plus_22.Probe`](#cdk8s_plus_22.Probe) +- *Default:* no liveness probe is defined + +Periodic probe of container liveness. + +Container will be restarted if the probe fails. + +--- + +###### `name`Optional + +- *Type:* `str` +- *Default:* 'main' + +Name of the container specified as a DNS_LABEL. + +Each container in a pod must have a unique name (DNS_LABEL). Cannot be updated. + +--- + +###### `port`Optional + +- *Type:* `typing.Union[int, float]` +- *Default:* No port is exposed. + +Number of port to expose on the pod's IP address. + +This must be a valid port number, 0 < x < 65536. + +--- + +###### `readiness`Optional + +- *Type:* [`cdk8s_plus_22.Probe`](#cdk8s_plus_22.Probe) +- *Default:* no readiness probe is defined + +Determines when the container is ready to serve traffic. + +--- + +###### `resources`Optional + +- *Type:* [`cdk8s_plus_22.Resources`](#cdk8s_plus_22.Resources) + +Compute resources (CPU and memory requests and limits) required by the container. + +> https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + +--- + +###### `security_context`Optional + +- *Type:* [`cdk8s_plus_22.ContainerSecurityContextProps`](#cdk8s_plus_22.ContainerSecurityContextProps) +- *Default:* ensureNonRoot: false + privileged: false + readOnlyRootFilesystem: false + +SecurityContext defines the security options the container should be run with. + +If set, the fields override equivalent fields of the pod's security context. + +> https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ + +--- + +###### `startup`Optional + +- *Type:* [`cdk8s_plus_22.Probe`](#cdk8s_plus_22.Probe) +- *Default:* no startup probe is defined. + +StartupProbe indicates that the Pod has successfully initialized. + +If specified, no other probes are executed until this completes successfully + +--- + +###### `volume_mounts`Optional + +- *Type:* typing.List[[`cdk8s_plus_22.VolumeMount`](#cdk8s_plus_22.VolumeMount)] + +Pod volumes to mount into the container's filesystem. + +Cannot be updated. + +--- + +###### `working_dir`Optional + +- *Type:* `str` +- *Default:* The container runtime's default. + +Container's working directory. + +If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. + +--- + +##### `add_volume` + +```python +def add_volume( + volume: Volume +) +``` + +###### `volume`Required + +- *Type:* [`cdk8s_plus_22.Volume`](#cdk8s_plus_22.Volume) + +--- + +##### `select_by_label` + +```python +def select_by_label( + key: str, + value: str +) +``` + +###### `key`Required + +- *Type:* `str` + +--- + +###### `value`Required + +- *Type:* `str` + +--- + + +#### Properties + +##### `containers`Required + +```python +containers: typing.List[Container] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.Container`](#cdk8s_plus_22.Container)] + +The containers belonging to the pod. + +Use `addContainer` to add containers. + +--- + +##### `host_aliases`Required + +```python +host_aliases: typing.List[HostAlias] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.HostAlias`](#cdk8s_plus_22.HostAlias)] + +An optional list of hosts and IPs that will be injected into the pod's hosts file if specified. + +This is only valid for non-hostNetwork pods. + +--- + +##### `init_containers`Required + +```python +init_containers: typing.List[Container] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.Container`](#cdk8s_plus_22.Container)] + +The init containers belonging to the pod. + +Use `addInitContainer` to add init containers. + +--- + +##### `label_selector`Required + +```python +label_selector: typing.Mapping[str] +``` + +- *Type:* typing.Mapping[`str`] + +The labels this daemon set will match against in order to select pods. + +Returns a a copy. Use `selectByLabel()` to add labels. + +--- + +##### `min_ready_seconds`Required + +```python +min_ready_seconds: typing.Union[int, float] +``` + +- *Type:* `typing.Union[int, float]` + +--- + +##### `pod_metadata`Required + +```python +pod_metadata: ApiObjectMetadataDefinition +``` + +- *Type:* [`cdk8s.ApiObjectMetadataDefinition`](#cdk8s.ApiObjectMetadataDefinition) + +Provides read/write access to the underlying pod metadata of the resource. + +--- + +##### `security_context`Required + +```python +security_context: PodSecurityContext +``` + +- *Type:* [`cdk8s_plus_22.PodSecurityContext`](#cdk8s_plus_22.PodSecurityContext) + +--- + +##### `volumes`Required + +```python +volumes: typing.List[Volume] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.Volume`](#cdk8s_plus_22.Volume)] + +The volumes associated with this pod. + +Use `addVolume` to add volumes. + +--- + +##### `restart_policy`Optional + +```python +restart_policy: RestartPolicy +``` + +- *Type:* [`cdk8s_plus_22.RestartPolicy`](#cdk8s_plus_22.RestartPolicy) + +Restart policy for all containers within the pod. + +--- + +##### `service_account`Optional + +```python +service_account: IServiceAccount +``` + +- *Type:* [`cdk8s_plus_22.IServiceAccount`](#cdk8s_plus_22.IServiceAccount) + +The service account used to run this pod. + +--- + + ### Deployment - *Implements:* [`cdk8s_plus_22.IPodTemplate`](#cdk8s_plus_22.IPodTemplate) @@ -7162,6 +7920,206 @@ request: Cpu --- +### DaemonSetProps + +Properties for `DaemonSet`. + +#### Initializer + +```python +import cdk8s_plus_22 + +cdk8s_plus_22.DaemonSetProps( + metadata: ApiObjectMetadata = None, + containers: typing.List[ContainerProps] = None, + host_aliases: typing.List[HostAlias] = None, + init_containers: typing.List[ContainerProps] = None, + restart_policy: RestartPolicy = None, + security_context: PodSecurityContextProps = None, + service_account: IServiceAccount = None, + volumes: typing.List[Volume] = None, + pod_metadata: ApiObjectMetadata = None, + default_selector: bool = None, + min_ready_seconds: typing.Union[int, float] = None +) +``` + +##### `metadata`Optional + +```python +metadata: ApiObjectMetadata +``` + +- *Type:* [`cdk8s.ApiObjectMetadata`](#cdk8s.ApiObjectMetadata) + +Metadata that all persisted resources must have, which includes all objects users must create. + +--- + +##### `containers`Optional + +```python +containers: typing.List[ContainerProps] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.ContainerProps`](#cdk8s_plus_22.ContainerProps)] +- *Default:* No containers. Note that a pod spec must include at least one container. + +List of containers belonging to the pod. + +Containers cannot currently be +added or removed. There must be at least one container in a Pod. + +You can add additionnal containers using `podSpec.addContainer()` + +--- + +##### `host_aliases`Optional + +```python +host_aliases: typing.List[HostAlias] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.HostAlias`](#cdk8s_plus_22.HostAlias)] + +HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file. + +--- + +##### `init_containers`Optional + +```python +init_containers: typing.List[ContainerProps] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.ContainerProps`](#cdk8s_plus_22.ContainerProps)] +- *Default:* No init containers. + +List of initialization containers belonging to the pod. + +Init containers are executed in order prior to containers being started. +If any init container fails, the pod is considered to have failed and is handled according to its restartPolicy. +The name for an init container or normal container must be unique among all containers. +Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. +The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limit +for each resource type, and then using the max of of that value or the sum of the normal containers. +Limits are applied to init containers in a similar fashion. + +Init containers cannot currently be added ,removed or updated. + +> https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ + +--- + +##### `restart_policy`Optional + +```python +restart_policy: RestartPolicy +``` + +- *Type:* [`cdk8s_plus_22.RestartPolicy`](#cdk8s_plus_22.RestartPolicy) +- *Default:* RestartPolicy.ALWAYS + +Restart policy for all containers within the pod. + +> https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy + +--- + +##### `security_context`Optional + +```python +security_context: PodSecurityContextProps +``` + +- *Type:* [`cdk8s_plus_22.PodSecurityContextProps`](#cdk8s_plus_22.PodSecurityContextProps) +- *Default:* fsGroupChangePolicy: FsGroupChangePolicy.FsGroupChangePolicy.ALWAYS + ensureNonRoot: false + +SecurityContext holds pod-level security attributes and common container settings. + +--- + +##### `service_account`Optional + +```python +service_account: IServiceAccount +``` + +- *Type:* [`cdk8s_plus_22.IServiceAccount`](#cdk8s_plus_22.IServiceAccount) +- *Default:* No service account. + +A service account provides an identity for processes that run in a Pod. + +When you (a human) access the cluster (for example, using kubectl), you are +authenticated by the apiserver as a particular User Account (currently this +is usually admin, unless your cluster administrator has customized your +cluster). Processes in containers inside pods can also contact the +apiserver. When they do, they are authenticated as a particular Service +Account (for example, default). + +> https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ + +--- + +##### `volumes`Optional + +```python +volumes: typing.List[Volume] +``` + +- *Type:* typing.List[[`cdk8s_plus_22.Volume`](#cdk8s_plus_22.Volume)] +- *Default:* No volumes. + +List of volumes that can be mounted by containers belonging to the pod. + +You can also add volumes later using `podSpec.addVolume()` + +> https://kubernetes.io/docs/concepts/storage/volumes + +--- + +##### `pod_metadata`Optional + +```python +pod_metadata: ApiObjectMetadata +``` + +- *Type:* [`cdk8s.ApiObjectMetadata`](#cdk8s.ApiObjectMetadata) + +The pod metadata. + +--- + +##### `default_selector`Optional + +```python +default_selector: bool +``` + +- *Type:* `bool` +- *Default:* true + +Automatically allocates a pod selector for this daemon set. + +If this is set to `false` you must define your selector through +`dset.podMetadata.addLabel()` and `dset.selectByLabel()`. + +--- + +##### `min_ready_seconds`Optional + +```python +min_ready_seconds: typing.Union[int, float] +``` + +- *Type:* `typing.Union[int, float]` +- *Default:* 0 + +Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. + +--- + ### DeploymentProps Properties for initialization of `Deployment`. @@ -13602,7 +14560,7 @@ The Kubernetes name of this resource. ### IPodSpec -- *Implemented By:* [`cdk8s_plus_22.Deployment`](#cdk8s_plus_22.Deployment), [`cdk8s_plus_22.Job`](#cdk8s_plus_22.Job), [`cdk8s_plus_22.Pod`](#cdk8s_plus_22.Pod), [`cdk8s_plus_22.PodSpec`](#cdk8s_plus_22.PodSpec), [`cdk8s_plus_22.PodTemplate`](#cdk8s_plus_22.PodTemplate), [`cdk8s_plus_22.StatefulSet`](#cdk8s_plus_22.StatefulSet), [`cdk8s_plus_22.IPodSpec`](#cdk8s_plus_22.IPodSpec), [`cdk8s_plus_22.IPodTemplate`](#cdk8s_plus_22.IPodTemplate) +- *Implemented By:* [`cdk8s_plus_22.DaemonSet`](#cdk8s_plus_22.DaemonSet), [`cdk8s_plus_22.Deployment`](#cdk8s_plus_22.Deployment), [`cdk8s_plus_22.Job`](#cdk8s_plus_22.Job), [`cdk8s_plus_22.Pod`](#cdk8s_plus_22.Pod), [`cdk8s_plus_22.PodSpec`](#cdk8s_plus_22.PodSpec), [`cdk8s_plus_22.PodTemplate`](#cdk8s_plus_22.PodTemplate), [`cdk8s_plus_22.StatefulSet`](#cdk8s_plus_22.StatefulSet), [`cdk8s_plus_22.IPodSpec`](#cdk8s_plus_22.IPodSpec), [`cdk8s_plus_22.IPodTemplate`](#cdk8s_plus_22.IPodTemplate) Represents a resource that can be configured with a kuberenets pod spec. (e.g `Deployment`, `Job`, `Pod`, ...). @@ -14092,7 +15050,7 @@ The service account used to run this pod. - *Extends:* [`cdk8s_plus_22.IPodSpec`](#cdk8s_plus_22.IPodSpec) -- *Implemented By:* [`cdk8s_plus_22.Deployment`](#cdk8s_plus_22.Deployment), [`cdk8s_plus_22.Job`](#cdk8s_plus_22.Job), [`cdk8s_plus_22.PodTemplate`](#cdk8s_plus_22.PodTemplate), [`cdk8s_plus_22.StatefulSet`](#cdk8s_plus_22.StatefulSet), [`cdk8s_plus_22.IPodTemplate`](#cdk8s_plus_22.IPodTemplate) +- *Implemented By:* [`cdk8s_plus_22.DaemonSet`](#cdk8s_plus_22.DaemonSet), [`cdk8s_plus_22.Deployment`](#cdk8s_plus_22.Deployment), [`cdk8s_plus_22.Job`](#cdk8s_plus_22.Job), [`cdk8s_plus_22.PodTemplate`](#cdk8s_plus_22.PodTemplate), [`cdk8s_plus_22.StatefulSet`](#cdk8s_plus_22.StatefulSet), [`cdk8s_plus_22.IPodTemplate`](#cdk8s_plus_22.IPodTemplate) Represents a resource that can be configured with a kuberenets pod template. (e.g `Deployment`, `Job`, ...). @@ -14195,7 +15153,7 @@ Provides read/write access to the underlying pod metadata of the resource. ### IResource -- *Implemented By:* [`cdk8s_plus_22.AwsElasticBlockStorePersistentVolume`](#cdk8s_plus_22.AwsElasticBlockStorePersistentVolume), [`cdk8s_plus_22.AzureDiskPersistentVolume`](#cdk8s_plus_22.AzureDiskPersistentVolume), [`cdk8s_plus_22.BasicAuthSecret`](#cdk8s_plus_22.BasicAuthSecret), [`cdk8s_plus_22.ConfigMap`](#cdk8s_plus_22.ConfigMap), [`cdk8s_plus_22.Deployment`](#cdk8s_plus_22.Deployment), [`cdk8s_plus_22.DockerConfigSecret`](#cdk8s_plus_22.DockerConfigSecret), [`cdk8s_plus_22.GCEPersistentDiskPersistentVolume`](#cdk8s_plus_22.GCEPersistentDiskPersistentVolume), [`cdk8s_plus_22.Ingress`](#cdk8s_plus_22.Ingress), [`cdk8s_plus_22.Job`](#cdk8s_plus_22.Job), [`cdk8s_plus_22.PersistentVolume`](#cdk8s_plus_22.PersistentVolume), [`cdk8s_plus_22.PersistentVolumeClaim`](#cdk8s_plus_22.PersistentVolumeClaim), [`cdk8s_plus_22.Pod`](#cdk8s_plus_22.Pod), [`cdk8s_plus_22.Resource`](#cdk8s_plus_22.Resource), [`cdk8s_plus_22.Secret`](#cdk8s_plus_22.Secret), [`cdk8s_plus_22.Service`](#cdk8s_plus_22.Service), [`cdk8s_plus_22.ServiceAccount`](#cdk8s_plus_22.ServiceAccount), [`cdk8s_plus_22.ServiceAccountTokenSecret`](#cdk8s_plus_22.ServiceAccountTokenSecret), [`cdk8s_plus_22.SshAuthSecret`](#cdk8s_plus_22.SshAuthSecret), [`cdk8s_plus_22.StatefulSet`](#cdk8s_plus_22.StatefulSet), [`cdk8s_plus_22.TlsSecret`](#cdk8s_plus_22.TlsSecret), [`cdk8s_plus_22.IConfigMap`](#cdk8s_plus_22.IConfigMap), [`cdk8s_plus_22.IPersistentVolume`](#cdk8s_plus_22.IPersistentVolume), [`cdk8s_plus_22.IPersistentVolumeClaim`](#cdk8s_plus_22.IPersistentVolumeClaim), [`cdk8s_plus_22.IResource`](#cdk8s_plus_22.IResource), [`cdk8s_plus_22.ISecret`](#cdk8s_plus_22.ISecret), [`cdk8s_plus_22.IServiceAccount`](#cdk8s_plus_22.IServiceAccount) +- *Implemented By:* [`cdk8s_plus_22.AwsElasticBlockStorePersistentVolume`](#cdk8s_plus_22.AwsElasticBlockStorePersistentVolume), [`cdk8s_plus_22.AzureDiskPersistentVolume`](#cdk8s_plus_22.AzureDiskPersistentVolume), [`cdk8s_plus_22.BasicAuthSecret`](#cdk8s_plus_22.BasicAuthSecret), [`cdk8s_plus_22.ConfigMap`](#cdk8s_plus_22.ConfigMap), [`cdk8s_plus_22.DaemonSet`](#cdk8s_plus_22.DaemonSet), [`cdk8s_plus_22.Deployment`](#cdk8s_plus_22.Deployment), [`cdk8s_plus_22.DockerConfigSecret`](#cdk8s_plus_22.DockerConfigSecret), [`cdk8s_plus_22.GCEPersistentDiskPersistentVolume`](#cdk8s_plus_22.GCEPersistentDiskPersistentVolume), [`cdk8s_plus_22.Ingress`](#cdk8s_plus_22.Ingress), [`cdk8s_plus_22.Job`](#cdk8s_plus_22.Job), [`cdk8s_plus_22.PersistentVolume`](#cdk8s_plus_22.PersistentVolume), [`cdk8s_plus_22.PersistentVolumeClaim`](#cdk8s_plus_22.PersistentVolumeClaim), [`cdk8s_plus_22.Pod`](#cdk8s_plus_22.Pod), [`cdk8s_plus_22.Resource`](#cdk8s_plus_22.Resource), [`cdk8s_plus_22.Secret`](#cdk8s_plus_22.Secret), [`cdk8s_plus_22.Service`](#cdk8s_plus_22.Service), [`cdk8s_plus_22.ServiceAccount`](#cdk8s_plus_22.ServiceAccount), [`cdk8s_plus_22.ServiceAccountTokenSecret`](#cdk8s_plus_22.ServiceAccountTokenSecret), [`cdk8s_plus_22.SshAuthSecret`](#cdk8s_plus_22.SshAuthSecret), [`cdk8s_plus_22.StatefulSet`](#cdk8s_plus_22.StatefulSet), [`cdk8s_plus_22.TlsSecret`](#cdk8s_plus_22.TlsSecret), [`cdk8s_plus_22.IConfigMap`](#cdk8s_plus_22.IConfigMap), [`cdk8s_plus_22.IPersistentVolume`](#cdk8s_plus_22.IPersistentVolume), [`cdk8s_plus_22.IPersistentVolumeClaim`](#cdk8s_plus_22.IPersistentVolumeClaim), [`cdk8s_plus_22.IResource`](#cdk8s_plus_22.IResource), [`cdk8s_plus_22.ISecret`](#cdk8s_plus_22.ISecret), [`cdk8s_plus_22.IServiceAccount`](#cdk8s_plus_22.IServiceAccount) Represents a resource. diff --git a/docs/typescript.md b/docs/typescript.md index 8e77ad929..18d48603c 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -401,6 +401,250 @@ Returns an copy. To add data records, use `addData()` or `addBinaryData()`. --- +### DaemonSet + +- *Implements:* [`cdk8s-plus-22.IPodTemplate`](#cdk8s-plus-22.IPodTemplate) + +A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. + +As nodes are added to the cluster, Pods are added to them. +As nodes are removed from the cluster, those Pods are garbage collected. +Deleting a DaemonSet will clean up the Pods it created. + +Some typical uses of a DaemonSet are: + +- running a cluster storage daemon on every node +- running a logs collection daemon on every node +- running a node monitoring daemon on every node + +In a simple case, one DaemonSet, covering all nodes, would be used for each type of daemon. +A more complex setup might use multiple DaemonSets for a single type of daemon, +but with different flags and/or different memory and cpu requests for different hardware types. + +#### Initializers + +```typescript +import { DaemonSet } from 'cdk8s-plus-22' + +new DaemonSet(scope: Construct, id: string, props?: DaemonSetProps) +``` + +##### `scope`Required + +- *Type:* [`constructs.Construct`](#constructs.Construct) + +--- + +##### `id`Required + +- *Type:* `string` + +--- + +##### `props`Optional + +- *Type:* [`cdk8s-plus-22.DaemonSetProps`](#cdk8s-plus-22.DaemonSetProps) + +--- + +#### Methods + +##### `addContainer` + +```typescript +public addContainer(container: ContainerProps) +``` + +###### `container`Required + +- *Type:* [`cdk8s-plus-22.ContainerProps`](#cdk8s-plus-22.ContainerProps) + +--- + +##### `addHostAlias` + +```typescript +public addHostAlias(hostAlias: HostAlias) +``` + +###### `hostAlias`Required + +- *Type:* [`cdk8s-plus-22.HostAlias`](#cdk8s-plus-22.HostAlias) + +--- + +##### `addInitContainer` + +```typescript +public addInitContainer(container: ContainerProps) +``` + +###### `container`Required + +- *Type:* [`cdk8s-plus-22.ContainerProps`](#cdk8s-plus-22.ContainerProps) + +--- + +##### `addVolume` + +```typescript +public addVolume(volume: Volume) +``` + +###### `volume`Required + +- *Type:* [`cdk8s-plus-22.Volume`](#cdk8s-plus-22.Volume) + +--- + +##### `selectByLabel` + +```typescript +public selectByLabel(key: string, value: string) +``` + +###### `key`Required + +- *Type:* `string` + +--- + +###### `value`Required + +- *Type:* `string` + +--- + + +#### Properties + +##### `containers`Required + +```typescript +public readonly containers: Container[]; +``` + +- *Type:* [`cdk8s-plus-22.Container`](#cdk8s-plus-22.Container)[] + +The containers belonging to the pod. + +Use `addContainer` to add containers. + +--- + +##### `hostAliases`Required + +```typescript +public readonly hostAliases: HostAlias[]; +``` + +- *Type:* [`cdk8s-plus-22.HostAlias`](#cdk8s-plus-22.HostAlias)[] + +An optional list of hosts and IPs that will be injected into the pod's hosts file if specified. + +This is only valid for non-hostNetwork pods. + +--- + +##### `initContainers`Required + +```typescript +public readonly initContainers: Container[]; +``` + +- *Type:* [`cdk8s-plus-22.Container`](#cdk8s-plus-22.Container)[] + +The init containers belonging to the pod. + +Use `addInitContainer` to add init containers. + +--- + +##### `labelSelector`Required + +```typescript +public readonly labelSelector: {[ key: string ]: string}; +``` + +- *Type:* {[ key: string ]: `string`} + +The labels this daemon set will match against in order to select pods. + +Returns a a copy. Use `selectByLabel()` to add labels. + +--- + +##### `minReadySeconds`Required + +```typescript +public readonly minReadySeconds: number; +``` + +- *Type:* `number` + +--- + +##### `podMetadata`Required + +```typescript +public readonly podMetadata: ApiObjectMetadataDefinition; +``` + +- *Type:* [`cdk8s.ApiObjectMetadataDefinition`](#cdk8s.ApiObjectMetadataDefinition) + +Provides read/write access to the underlying pod metadata of the resource. + +--- + +##### `securityContext`Required + +```typescript +public readonly securityContext: PodSecurityContext; +``` + +- *Type:* [`cdk8s-plus-22.PodSecurityContext`](#cdk8s-plus-22.PodSecurityContext) + +--- + +##### `volumes`Required + +```typescript +public readonly volumes: Volume[]; +``` + +- *Type:* [`cdk8s-plus-22.Volume`](#cdk8s-plus-22.Volume)[] + +The volumes associated with this pod. + +Use `addVolume` to add volumes. + +--- + +##### `restartPolicy`Optional + +```typescript +public readonly restartPolicy: RestartPolicy; +``` + +- *Type:* [`cdk8s-plus-22.RestartPolicy`](#cdk8s-plus-22.RestartPolicy) + +Restart policy for all containers within the pod. + +--- + +##### `serviceAccount`Optional + +```typescript +public readonly serviceAccount: IServiceAccount; +``` + +- *Type:* [`cdk8s-plus-22.IServiceAccount`](#cdk8s-plus-22.IServiceAccount) + +The service account used to run this pod. + +--- + + ### Deployment - *Implements:* [`cdk8s-plus-22.IPodTemplate`](#cdk8s-plus-22.IPodTemplate) @@ -3756,6 +4000,194 @@ public readonly request: Cpu; --- +### DaemonSetProps + +Properties for `DaemonSet`. + +#### Initializer + +```typescript +import { DaemonSetProps } from 'cdk8s-plus-22' + +const daemonSetProps: DaemonSetProps = { ... } +``` + +##### `metadata`Optional + +```typescript +public readonly metadata: ApiObjectMetadata; +``` + +- *Type:* [`cdk8s.ApiObjectMetadata`](#cdk8s.ApiObjectMetadata) + +Metadata that all persisted resources must have, which includes all objects users must create. + +--- + +##### `containers`Optional + +```typescript +public readonly containers: ContainerProps[]; +``` + +- *Type:* [`cdk8s-plus-22.ContainerProps`](#cdk8s-plus-22.ContainerProps)[] +- *Default:* No containers. Note that a pod spec must include at least one container. + +List of containers belonging to the pod. + +Containers cannot currently be +added or removed. There must be at least one container in a Pod. + +You can add additionnal containers using `podSpec.addContainer()` + +--- + +##### `hostAliases`Optional + +```typescript +public readonly hostAliases: HostAlias[]; +``` + +- *Type:* [`cdk8s-plus-22.HostAlias`](#cdk8s-plus-22.HostAlias)[] + +HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file. + +--- + +##### `initContainers`Optional + +```typescript +public readonly initContainers: ContainerProps[]; +``` + +- *Type:* [`cdk8s-plus-22.ContainerProps`](#cdk8s-plus-22.ContainerProps)[] +- *Default:* No init containers. + +List of initialization containers belonging to the pod. + +Init containers are executed in order prior to containers being started. +If any init container fails, the pod is considered to have failed and is handled according to its restartPolicy. +The name for an init container or normal container must be unique among all containers. +Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. +The resourceRequirements of an init container are taken into account during scheduling by finding the highest request/limit +for each resource type, and then using the max of of that value or the sum of the normal containers. +Limits are applied to init containers in a similar fashion. + +Init containers cannot currently be added ,removed or updated. + +> https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ + +--- + +##### `restartPolicy`Optional + +```typescript +public readonly restartPolicy: RestartPolicy; +``` + +- *Type:* [`cdk8s-plus-22.RestartPolicy`](#cdk8s-plus-22.RestartPolicy) +- *Default:* RestartPolicy.ALWAYS + +Restart policy for all containers within the pod. + +> https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy + +--- + +##### `securityContext`Optional + +```typescript +public readonly securityContext: PodSecurityContextProps; +``` + +- *Type:* [`cdk8s-plus-22.PodSecurityContextProps`](#cdk8s-plus-22.PodSecurityContextProps) +- *Default:* fsGroupChangePolicy: FsGroupChangePolicy.FsGroupChangePolicy.ALWAYS + ensureNonRoot: false + +SecurityContext holds pod-level security attributes and common container settings. + +--- + +##### `serviceAccount`Optional + +```typescript +public readonly serviceAccount: IServiceAccount; +``` + +- *Type:* [`cdk8s-plus-22.IServiceAccount`](#cdk8s-plus-22.IServiceAccount) +- *Default:* No service account. + +A service account provides an identity for processes that run in a Pod. + +When you (a human) access the cluster (for example, using kubectl), you are +authenticated by the apiserver as a particular User Account (currently this +is usually admin, unless your cluster administrator has customized your +cluster). Processes in containers inside pods can also contact the +apiserver. When they do, they are authenticated as a particular Service +Account (for example, default). + +> https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ + +--- + +##### `volumes`Optional + +```typescript +public readonly volumes: Volume[]; +``` + +- *Type:* [`cdk8s-plus-22.Volume`](#cdk8s-plus-22.Volume)[] +- *Default:* No volumes. + +List of volumes that can be mounted by containers belonging to the pod. + +You can also add volumes later using `podSpec.addVolume()` + +> https://kubernetes.io/docs/concepts/storage/volumes + +--- + +##### `podMetadata`Optional + +```typescript +public readonly podMetadata: ApiObjectMetadata; +``` + +- *Type:* [`cdk8s.ApiObjectMetadata`](#cdk8s.ApiObjectMetadata) + +The pod metadata. + +--- + +##### `defaultSelector`Optional + +```typescript +public readonly defaultSelector: boolean; +``` + +- *Type:* `boolean` +- *Default:* true + +Automatically allocates a pod selector for this daemon set. + +If this is set to `false` you must define your selector through +`dset.podMetadata.addLabel()` and `dset.selectByLabel()`. + +--- + +##### `minReadySeconds`Optional + +```typescript +public readonly minReadySeconds: number; +``` + +- *Type:* `number` +- *Default:* 0 + +Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. + +--- + ### DeploymentProps Properties for initialization of `Deployment`. @@ -8609,7 +9041,7 @@ The Kubernetes name of this resource. ### IPodSpec -- *Implemented By:* [`cdk8s-plus-22.Deployment`](#cdk8s-plus-22.Deployment), [`cdk8s-plus-22.Job`](#cdk8s-plus-22.Job), [`cdk8s-plus-22.Pod`](#cdk8s-plus-22.Pod), [`cdk8s-plus-22.PodSpec`](#cdk8s-plus-22.PodSpec), [`cdk8s-plus-22.PodTemplate`](#cdk8s-plus-22.PodTemplate), [`cdk8s-plus-22.StatefulSet`](#cdk8s-plus-22.StatefulSet), [`cdk8s-plus-22.IPodSpec`](#cdk8s-plus-22.IPodSpec), [`cdk8s-plus-22.IPodTemplate`](#cdk8s-plus-22.IPodTemplate) +- *Implemented By:* [`cdk8s-plus-22.DaemonSet`](#cdk8s-plus-22.DaemonSet), [`cdk8s-plus-22.Deployment`](#cdk8s-plus-22.Deployment), [`cdk8s-plus-22.Job`](#cdk8s-plus-22.Job), [`cdk8s-plus-22.Pod`](#cdk8s-plus-22.Pod), [`cdk8s-plus-22.PodSpec`](#cdk8s-plus-22.PodSpec), [`cdk8s-plus-22.PodTemplate`](#cdk8s-plus-22.PodTemplate), [`cdk8s-plus-22.StatefulSet`](#cdk8s-plus-22.StatefulSet), [`cdk8s-plus-22.IPodSpec`](#cdk8s-plus-22.IPodSpec), [`cdk8s-plus-22.IPodTemplate`](#cdk8s-plus-22.IPodTemplate) Represents a resource that can be configured with a kuberenets pod spec. (e.g `Deployment`, `Job`, `Pod`, ...). @@ -8745,7 +9177,7 @@ The service account used to run this pod. - *Extends:* [`cdk8s-plus-22.IPodSpec`](#cdk8s-plus-22.IPodSpec) -- *Implemented By:* [`cdk8s-plus-22.Deployment`](#cdk8s-plus-22.Deployment), [`cdk8s-plus-22.Job`](#cdk8s-plus-22.Job), [`cdk8s-plus-22.PodTemplate`](#cdk8s-plus-22.PodTemplate), [`cdk8s-plus-22.StatefulSet`](#cdk8s-plus-22.StatefulSet), [`cdk8s-plus-22.IPodTemplate`](#cdk8s-plus-22.IPodTemplate) +- *Implemented By:* [`cdk8s-plus-22.DaemonSet`](#cdk8s-plus-22.DaemonSet), [`cdk8s-plus-22.Deployment`](#cdk8s-plus-22.Deployment), [`cdk8s-plus-22.Job`](#cdk8s-plus-22.Job), [`cdk8s-plus-22.PodTemplate`](#cdk8s-plus-22.PodTemplate), [`cdk8s-plus-22.StatefulSet`](#cdk8s-plus-22.StatefulSet), [`cdk8s-plus-22.IPodTemplate`](#cdk8s-plus-22.IPodTemplate) Represents a resource that can be configured with a kuberenets pod template. (e.g `Deployment`, `Job`, ...). @@ -8848,7 +9280,7 @@ Provides read/write access to the underlying pod metadata of the resource. ### IResource -- *Implemented By:* [`cdk8s-plus-22.AwsElasticBlockStorePersistentVolume`](#cdk8s-plus-22.AwsElasticBlockStorePersistentVolume), [`cdk8s-plus-22.AzureDiskPersistentVolume`](#cdk8s-plus-22.AzureDiskPersistentVolume), [`cdk8s-plus-22.BasicAuthSecret`](#cdk8s-plus-22.BasicAuthSecret), [`cdk8s-plus-22.ConfigMap`](#cdk8s-plus-22.ConfigMap), [`cdk8s-plus-22.Deployment`](#cdk8s-plus-22.Deployment), [`cdk8s-plus-22.DockerConfigSecret`](#cdk8s-plus-22.DockerConfigSecret), [`cdk8s-plus-22.GCEPersistentDiskPersistentVolume`](#cdk8s-plus-22.GCEPersistentDiskPersistentVolume), [`cdk8s-plus-22.Ingress`](#cdk8s-plus-22.Ingress), [`cdk8s-plus-22.Job`](#cdk8s-plus-22.Job), [`cdk8s-plus-22.PersistentVolume`](#cdk8s-plus-22.PersistentVolume), [`cdk8s-plus-22.PersistentVolumeClaim`](#cdk8s-plus-22.PersistentVolumeClaim), [`cdk8s-plus-22.Pod`](#cdk8s-plus-22.Pod), [`cdk8s-plus-22.Resource`](#cdk8s-plus-22.Resource), [`cdk8s-plus-22.Secret`](#cdk8s-plus-22.Secret), [`cdk8s-plus-22.Service`](#cdk8s-plus-22.Service), [`cdk8s-plus-22.ServiceAccount`](#cdk8s-plus-22.ServiceAccount), [`cdk8s-plus-22.ServiceAccountTokenSecret`](#cdk8s-plus-22.ServiceAccountTokenSecret), [`cdk8s-plus-22.SshAuthSecret`](#cdk8s-plus-22.SshAuthSecret), [`cdk8s-plus-22.StatefulSet`](#cdk8s-plus-22.StatefulSet), [`cdk8s-plus-22.TlsSecret`](#cdk8s-plus-22.TlsSecret), [`cdk8s-plus-22.IConfigMap`](#cdk8s-plus-22.IConfigMap), [`cdk8s-plus-22.IPersistentVolume`](#cdk8s-plus-22.IPersistentVolume), [`cdk8s-plus-22.IPersistentVolumeClaim`](#cdk8s-plus-22.IPersistentVolumeClaim), [`cdk8s-plus-22.IResource`](#cdk8s-plus-22.IResource), [`cdk8s-plus-22.ISecret`](#cdk8s-plus-22.ISecret), [`cdk8s-plus-22.IServiceAccount`](#cdk8s-plus-22.IServiceAccount) +- *Implemented By:* [`cdk8s-plus-22.AwsElasticBlockStorePersistentVolume`](#cdk8s-plus-22.AwsElasticBlockStorePersistentVolume), [`cdk8s-plus-22.AzureDiskPersistentVolume`](#cdk8s-plus-22.AzureDiskPersistentVolume), [`cdk8s-plus-22.BasicAuthSecret`](#cdk8s-plus-22.BasicAuthSecret), [`cdk8s-plus-22.ConfigMap`](#cdk8s-plus-22.ConfigMap), [`cdk8s-plus-22.DaemonSet`](#cdk8s-plus-22.DaemonSet), [`cdk8s-plus-22.Deployment`](#cdk8s-plus-22.Deployment), [`cdk8s-plus-22.DockerConfigSecret`](#cdk8s-plus-22.DockerConfigSecret), [`cdk8s-plus-22.GCEPersistentDiskPersistentVolume`](#cdk8s-plus-22.GCEPersistentDiskPersistentVolume), [`cdk8s-plus-22.Ingress`](#cdk8s-plus-22.Ingress), [`cdk8s-plus-22.Job`](#cdk8s-plus-22.Job), [`cdk8s-plus-22.PersistentVolume`](#cdk8s-plus-22.PersistentVolume), [`cdk8s-plus-22.PersistentVolumeClaim`](#cdk8s-plus-22.PersistentVolumeClaim), [`cdk8s-plus-22.Pod`](#cdk8s-plus-22.Pod), [`cdk8s-plus-22.Resource`](#cdk8s-plus-22.Resource), [`cdk8s-plus-22.Secret`](#cdk8s-plus-22.Secret), [`cdk8s-plus-22.Service`](#cdk8s-plus-22.Service), [`cdk8s-plus-22.ServiceAccount`](#cdk8s-plus-22.ServiceAccount), [`cdk8s-plus-22.ServiceAccountTokenSecret`](#cdk8s-plus-22.ServiceAccountTokenSecret), [`cdk8s-plus-22.SshAuthSecret`](#cdk8s-plus-22.SshAuthSecret), [`cdk8s-plus-22.StatefulSet`](#cdk8s-plus-22.StatefulSet), [`cdk8s-plus-22.TlsSecret`](#cdk8s-plus-22.TlsSecret), [`cdk8s-plus-22.IConfigMap`](#cdk8s-plus-22.IConfigMap), [`cdk8s-plus-22.IPersistentVolume`](#cdk8s-plus-22.IPersistentVolume), [`cdk8s-plus-22.IPersistentVolumeClaim`](#cdk8s-plus-22.IPersistentVolumeClaim), [`cdk8s-plus-22.IResource`](#cdk8s-plus-22.IResource), [`cdk8s-plus-22.ISecret`](#cdk8s-plus-22.ISecret), [`cdk8s-plus-22.IServiceAccount`](#cdk8s-plus-22.IServiceAccount) Represents a resource. diff --git a/src/daemon-set.ts b/src/daemon-set.ts new file mode 100644 index 000000000..d398aaeaf --- /dev/null +++ b/src/daemon-set.ts @@ -0,0 +1,162 @@ +import { ApiObject, ApiObjectMetadataDefinition, Lazy, Names } from 'cdk8s'; +import { Construct } from 'constructs'; +import { Resource, ResourceProps } from './base'; +import { Container, ContainerProps } from './container'; +import * as k8s from './imports/k8s'; +import { HostAlias, IPodTemplate, PodSecurityContext, PodTemplate, PodTemplateProps, RestartPolicy } from './pod'; +import { IServiceAccount } from './service-account'; +import { Volume } from './volume'; + +/** + * Properties for `DaemonSet`. + */ +export interface DaemonSetProps extends ResourceProps, PodTemplateProps { + + /** + * Minimum number of seconds for which a newly created pod should + * be ready without any of its container crashing, for it to be considered available. + * + * @default 0 + */ + readonly minReadySeconds?: number; + + /** + * Automatically allocates a pod selector for this daemon set. + * + * If this is set to `false` you must define your selector through + * `dset.podMetadata.addLabel()` and `dset.selectByLabel()`. + * + * @default true + */ + readonly defaultSelector?: boolean; + +} + +/** + * A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. + * As nodes are added to the cluster, Pods are added to them. + * As nodes are removed from the cluster, those Pods are garbage collected. + * Deleting a DaemonSet will clean up the Pods it created. + * + * Some typical uses of a DaemonSet are: + * + * - running a cluster storage daemon on every node + * - running a logs collection daemon on every node + * - running a node monitoring daemon on every node + * + * In a simple case, one DaemonSet, covering all nodes, would be used for each type of daemon. + * A more complex setup might use multiple DaemonSets for a single type of daemon, + * but with different flags and/or different memory and cpu requests for different hardware types. + */ +export class DaemonSet extends Resource implements IPodTemplate { + + private readonly _podTemplate: PodTemplate; + private readonly _labelSelector: Record; + + /** + * @see base.Resource.apiObject + */ + protected readonly apiObject: ApiObject; + + public readonly minReadySeconds: number; + + constructor(scope: Construct, id: string, props: DaemonSetProps = {}) { + super(scope, id); + + this.apiObject = new k8s.KubeDaemonSet(this, 'Resource', { + metadata: props.metadata, + spec: Lazy.any({ produce: () => this._toKube() }), + }); + + this.minReadySeconds = props.minReadySeconds ?? 0; + + this._podTemplate = new PodTemplate(props); + this._labelSelector = {}; + + if (props.defaultSelector ?? true) { + const selector = 'cdk8s.daemon-set'; + const matcher = Names.toLabelValue(this); + this.podMetadata.addLabel(selector, matcher); + this.selectByLabel(selector, matcher); + } + + } + + /** + * The labels this daemon set will match against in order to select pods. + * + * Returns a a copy. Use `selectByLabel()` to add labels. + */ + public get labelSelector(): Record { + return { ...this._labelSelector }; + } + + public get podMetadata(): ApiObjectMetadataDefinition { + return this._podTemplate.podMetadata; + } + + public get containers(): Container[] { + return this._podTemplate.containers; + } + + public get initContainers(): Container[] { + return this._podTemplate.initContainers; + } + + public get hostAliases(): HostAlias[] { + return this._podTemplate.hostAliases; + } + + public get volumes(): Volume[] { + return this._podTemplate.volumes; + } + + public get restartPolicy(): RestartPolicy | undefined { + return this._podTemplate.restartPolicy; + } + + public get serviceAccount(): IServiceAccount | undefined { + return this._podTemplate.serviceAccount; + } + + public get securityContext(): PodSecurityContext { + return this._podTemplate.securityContext; + } + + public addContainer(container: ContainerProps): Container { + return this._podTemplate.addContainer(container); + } + + public addInitContainer(container: ContainerProps): Container { + return this._podTemplate.addInitContainer(container); + } + + public addHostAlias(hostAlias: HostAlias): void { + return this._podTemplate.addHostAlias(hostAlias); + } + + public addVolume(volume: Volume): void { + return this._podTemplate.addVolume(volume); + } + + /** + * Configure a label selector to this daemon set. + */ + public selectByLabel(key: string, value: string) { + this._labelSelector[key] = value; + } + + /** + * @internal + */ + public _toKube(): k8s.DaemonSetSpec { + return { + minReadySeconds: this.minReadySeconds, + template: this._podTemplate._toPodTemplateSpec(), + selector: { + matchLabels: this._labelSelector, + }, + }; + } + +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 0e57d0233..e9ceb59ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,3 +14,4 @@ export * from './probe'; export * from './pvc'; export * from './pv'; export * from './handler'; +export * from './daemon-set'; diff --git a/test/__snapshots__/daemon-set.test.ts.snap b/test/__snapshots__/daemon-set.test.ts.snap new file mode 100644 index 000000000..a88f69288 --- /dev/null +++ b/test/__snapshots__/daemon-set.test.ts.snap @@ -0,0 +1,105 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`custom 1`] = ` +Array [ + Object { + "apiVersion": "apps/v1", + "kind": "DaemonSet", + "metadata": Object { + "name": "test-daemonset-c8482ea2", + }, + "spec": Object { + "minReadySeconds": 5, + "selector": Object { + "matchLabels": Object { + "cdk8s.daemon-set": "test-DaemonSet-c8f77186", + }, + }, + "template": Object { + "metadata": Object { + "labels": Object { + "cdk8s.daemon-set": "test-DaemonSet-c8f77186", + }, + }, + "spec": Object { + "containers": Array [ + Object { + "env": Array [], + "image": "image", + "imagePullPolicy": "Always", + "name": "main", + "ports": Array [], + "securityContext": Object { + "privileged": false, + "readOnlyRootFilesystem": false, + "runAsNonRoot": false, + }, + "volumeMounts": Array [], + }, + ], + "hostAliases": Array [], + "initContainers": Array [], + "securityContext": Object { + "fsGroupChangePolicy": "Always", + "runAsNonRoot": false, + "sysctls": Array [], + }, + "volumes": Array [], + }, + }, + }, + }, +] +`; + +exports[`defaults 1`] = ` +Array [ + Object { + "apiVersion": "apps/v1", + "kind": "DaemonSet", + "metadata": Object { + "name": "test-daemonset-c8482ea2", + }, + "spec": Object { + "minReadySeconds": 0, + "selector": Object { + "matchLabels": Object { + "cdk8s.daemon-set": "test-DaemonSet-c8f77186", + }, + }, + "template": Object { + "metadata": Object { + "labels": Object { + "cdk8s.daemon-set": "test-DaemonSet-c8f77186", + }, + }, + "spec": Object { + "containers": Array [ + Object { + "env": Array [], + "image": "image", + "imagePullPolicy": "Always", + "name": "main", + "ports": Array [], + "securityContext": Object { + "privileged": false, + "readOnlyRootFilesystem": false, + "runAsNonRoot": false, + }, + "volumeMounts": Array [], + }, + ], + "hostAliases": Array [], + "initContainers": Array [], + "securityContext": Object { + "fsGroupChangePolicy": "Always", + "runAsNonRoot": false, + "sysctls": Array [], + }, + "volumes": Array [], + }, + }, + }, + }, +] +`; diff --git a/test/daemon-set.test.ts b/test/daemon-set.test.ts new file mode 100644 index 000000000..53590163f --- /dev/null +++ b/test/daemon-set.test.ts @@ -0,0 +1,97 @@ +import { ApiObject, Testing } from 'cdk8s'; +import { Node } from 'constructs'; +import * as kplus from '../src'; + +test('default child', () => { + + const chart = Testing.chart(); + const ds = new kplus.DaemonSet(chart, 'DaemonSet'); + const defaultChild = Node.of(ds).defaultChild as ApiObject; + + expect(defaultChild.kind).toEqual('DaemonSet'); + +}); + +test('defaults', () => { + + const chart = Testing.chart(); + new kplus.DaemonSet(chart, 'DaemonSet', { + containers: [{ image: 'image' }], + }); + + expect(Testing.synth(chart)).toMatchSnapshot(); + +}); + +test('custom', () => { + + const chart = Testing.chart(); + new kplus.DaemonSet(chart, 'DaemonSet', { + containers: [{ image: 'image' }], + minReadySeconds: 5, + }); + + expect(Testing.synth(chart)).toMatchSnapshot(); + +}); + +test('a label selector is automatically allocated', () => { + + const chart = Testing.chart(); + + const ds = new kplus.DaemonSet(chart, 'DaemonSet'); + ds.addContainer({ image: 'foobar' }); + + const expectedValue = 'test-DaemonSet-c8f77186'; + const expectedSelector = { 'cdk8s.daemon-set': expectedValue }; + + // assert the k8s spec has it. + const spec = Testing.synth(chart)[0].spec; + expect(spec.selector.matchLabels).toEqual(expectedSelector); + expect(spec.template.metadata?.labels).toEqual(expectedSelector); + + // assert the deployment object has it. + expect(ds.labelSelector).toEqual(expectedSelector); + +}); + +test('no selector is generated if "defaultSelector" is false', () => { + + const chart = Testing.chart(); + + const ds = new kplus.DaemonSet(chart, 'DaemonSet', { + defaultSelector: false, + containers: [{ image: 'foobar' }], + }); + + // assert the k8s spec doesnt have it. + const spec = Testing.synth(chart)[0].spec; + expect(spec.selector.matchLabels).toEqual({}); + expect(spec.template.metadata?.labels).toEqual(undefined); + + // assert the deployment object doesnt have it. + expect(ds.labelSelector).toEqual({}); + +}); + +test('can select by label', () => { + + const chart = Testing.chart(); + + const ds = new kplus.DaemonSet(chart, 'DaemonSet', { + containers: [{ image: 'image' }], + defaultSelector: false, + }); + + const expectedSelector = { foo: 'bar' }; + + ds.selectByLabel('foo', expectedSelector.foo); + + // assert the k8s spec has it. + const spec = Testing.synth(chart)[0].spec; + expect(spec.selector.matchLabels).toEqual(expectedSelector); + + // assert the deployment object has it. + expect(ds.labelSelector).toEqual(expectedSelector); + +}); From b5cc026248f1a7f3ef96fd09fed8a6a8e8653754 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 4 Apr 2022 20:32:56 +0000 Subject: [PATCH 2/2] chore: self mutation Signed-off-by: github-actions --- docs/java.md | 24 ++++++++++++++++++++++++ docs/python.md | 24 ++++++++++++++++++++++++ docs/typescript.md | 13 +++++++++++++ 3 files changed, 61 insertions(+) diff --git a/docs/java.md b/docs/java.md index f195d5054..c6cdb28bf 100644 --- a/docs/java.md +++ b/docs/java.md @@ -816,6 +816,7 @@ import org.cdk8s.plus22.DaemonSet; DaemonSet.Builder.create(Construct scope, java.lang.String id) // .metadata(ApiObjectMetadata) // .containers(java.util.List) +// .dockerRegistryAuth(DockerConfigSecret) // .hostAliases(java.util.List) // .initContainers(java.util.List) // .restartPolicy(RestartPolicy) @@ -862,6 +863,15 @@ You can add additionnal containers using `podSpec.addContainer()` --- +##### `dockerRegistryAuth`Optional + +- *Type:* [`org.cdk8s.plus22.DockerConfigSecret`](#org.cdk8s.plus22.DockerConfigSecret) +- *Default:* No auth. Images are assumed to be publicly available. + +A secret containing docker credentials for authenticating to a registry. + +--- + ##### `hostAliases`Optional - *Type:* java.util.List<[`org.cdk8s.plus22.HostAlias`](#org.cdk8s.plus22.HostAlias)> @@ -6100,6 +6110,7 @@ import org.cdk8s.plus22.DaemonSetProps; DaemonSetProps.builder() // .metadata(ApiObjectMetadata) // .containers(java.util.List) +// .dockerRegistryAuth(DockerConfigSecret) // .hostAliases(java.util.List) // .initContainers(java.util.List) // .restartPolicy(RestartPolicy) @@ -6142,6 +6153,19 @@ You can add additionnal containers using `podSpec.addContainer()` --- +##### `dockerRegistryAuth`Optional + +```java +public DockerConfigSecret getDockerRegistryAuth(); +``` + +- *Type:* [`org.cdk8s.plus22.DockerConfigSecret`](#org.cdk8s.plus22.DockerConfigSecret) +- *Default:* No auth. Images are assumed to be publicly available. + +A secret containing docker credentials for authenticating to a registry. + +--- + ##### `hostAliases`Optional ```java diff --git a/docs/python.md b/docs/python.md index 4d94ec410..4b1516655 100644 --- a/docs/python.md +++ b/docs/python.md @@ -849,6 +849,7 @@ cdk8s_plus_22.DaemonSet( id: str, metadata: ApiObjectMetadata = None, containers: typing.List[ContainerProps] = None, + docker_registry_auth: DockerConfigSecret = None, host_aliases: typing.List[HostAlias] = None, init_containers: typing.List[ContainerProps] = None, restart_policy: RestartPolicy = None, @@ -895,6 +896,15 @@ You can add additionnal containers using `podSpec.addContainer()` --- +##### `docker_registry_auth`Optional + +- *Type:* [`cdk8s_plus_22.DockerConfigSecret`](#cdk8s_plus_22.DockerConfigSecret) +- *Default:* No auth. Images are assumed to be publicly available. + +A secret containing docker credentials for authenticating to a registry. + +--- + ##### `host_aliases`Optional - *Type:* typing.List[[`cdk8s_plus_22.HostAlias`](#cdk8s_plus_22.HostAlias)] @@ -8341,6 +8351,7 @@ import cdk8s_plus_22 cdk8s_plus_22.DaemonSetProps( metadata: ApiObjectMetadata = None, containers: typing.List[ContainerProps] = None, + docker_registry_auth: DockerConfigSecret = None, host_aliases: typing.List[HostAlias] = None, init_containers: typing.List[ContainerProps] = None, restart_policy: RestartPolicy = None, @@ -8383,6 +8394,19 @@ You can add additionnal containers using `podSpec.addContainer()` --- +##### `docker_registry_auth`Optional + +```python +docker_registry_auth: DockerConfigSecret +``` + +- *Type:* [`cdk8s_plus_22.DockerConfigSecret`](#cdk8s_plus_22.DockerConfigSecret) +- *Default:* No auth. Images are assumed to be publicly available. + +A secret containing docker credentials for authenticating to a registry. + +--- + ##### `host_aliases`Optional ```python diff --git a/docs/typescript.md b/docs/typescript.md index 67018b531..d546ff8ac 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -4301,6 +4301,19 @@ You can add additionnal containers using `podSpec.addContainer()` --- +##### `dockerRegistryAuth`Optional + +```typescript +public readonly dockerRegistryAuth: DockerConfigSecret; +``` + +- *Type:* [`cdk8s-plus-22.DockerConfigSecret`](#cdk8s-plus-22.DockerConfigSecret) +- *Default:* No auth. Images are assumed to be publicly available. + +A secret containing docker credentials for authenticating to a registry. + +--- + ##### `hostAliases`Optional ```typescript