Skip to content

Commit

Permalink
Add hostAliases support for all pod templates (#398) (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocomic authored Jun 9, 2022
1 parent 6b770a2 commit aaf29e1
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 1 deletion.
12 changes: 12 additions & 0 deletions apis/flinkcluster/v1beta1/flinkcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ type JobManagerSpec struct {
// If omitted, a [default value](https://github.com/spotify/flink-on-k8s-operator/blob/a88ed2b/api/v1beta1/flinkcluster_default.go#L129-L139) will be used.
// [More info](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`

// _(Optional)_ Adding entries to JobManager pod /etc/hosts with HostAliases
// [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/)
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
}

// TaskManagerPorts defines ports of TaskManager.
Expand Down Expand Up @@ -394,6 +398,10 @@ type TaskManagerSpec struct {
// If omitted, a [default value](https://github.com/spotify/flink-on-k8s-operator/blob/a88ed2b/api/v1beta1/flinkcluster_default.go#L193-L203) will be used.
// [More info](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`

// _(Optional)_ Adding entries to TaskManager pod /etc/hosts with HostAliases
// [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/)
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
}

// CleanupAction defines the action to take after job finishes.
Expand Down Expand Up @@ -541,6 +549,10 @@ type JobSpec struct {
// [More info](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod)
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`

// _(Optional)_ Adding entries to Job pod /etc/hosts with HostAliases
// [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/)
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`

// Job running mode, `"Blocking", "Detached"`, default: `"Detached"`
Mode *JobMode `json:"mode,omitempty"`
}
Expand Down
21 changes: 21 additions & 0 deletions apis/flinkcluster/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions config/crd/bases/flinkoperator.k8s.io_flinkclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,17 @@ spec:
type: string
type: object
type: array
hostAliases:
items:
properties:
ip:
type: string
hostnames:
items:
type: string
type: array
type: object
type: array
volumeMounts:
items:
properties:
Expand Down Expand Up @@ -3055,6 +3066,17 @@ spec:
type: string
type: object
type: array
hostAliases:
items:
properties:
ip:
type: string
hostnames:
items:
type: string
type: array
type: object
type: array
volumeClaimTemplates:
items:
properties:
Expand Down Expand Up @@ -5342,6 +5364,17 @@ spec:
type: string
type: object
type: array
hostAliases:
items:
properties:
ip:
type: string
hostnames:
items:
type: string
type: array
type: object
type: array
volumeClaimTemplates:
items:
properties:
Expand Down
3 changes: 3 additions & 0 deletions controllers/flinkcluster/flinkcluster_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func newJobManagerPodSpec(mainContainer *corev1.Container, flinkCluster *v1beta1
Tolerations: jobManagerSpec.Tolerations,
ImagePullSecrets: imageSpec.PullSecrets,
SecurityContext: jobManagerSpec.SecurityContext,
HostAliases: jobManagerSpec.HostAliases,
ServiceAccountName: getServiceAccountName(serviceAccount),
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
}
Expand Down Expand Up @@ -485,6 +486,7 @@ func newTaskManagerPodSpec(mainContainer *corev1.Container, flinkCluster *v1beta
Tolerations: taskManagerSpec.Tolerations,
ImagePullSecrets: imageSpec.PullSecrets,
SecurityContext: taskManagerSpec.SecurityContext,
HostAliases: taskManagerSpec.HostAliases,
ServiceAccountName: getServiceAccountName(serviceAccount),
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
}
Expand Down Expand Up @@ -838,6 +840,7 @@ func newJobSubmitterPodSpec(flinkCluster *v1beta1.FlinkCluster) *corev1.PodSpec
Volumes: volumes,
ImagePullSecrets: imageSpec.PullSecrets,
SecurityContext: jobSpec.SecurityContext,
HostAliases: jobSpec.HostAliases,
ServiceAccountName: getServiceAccountName(serviceAccount),
NodeSelector: jobSpec.NodeSelector,
Tolerations: jobSpec.Tolerations,
Expand Down
16 changes: 16 additions & 0 deletions controllers/flinkcluster/flinkcluster_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ var (
Value: "toleration-value2",
},
}
hostAliases = []corev1.HostAlias{
{
IP: "127.0.0.1",
Hostnames: []string{
"test-localhost-alias1",
"test-localhost-alias2",
},
},
}
userAndGroupId int64 = 9999
securityContext = corev1.PodSecurityContext{
RunAsUser: &userAndGroupId,
Expand Down Expand Up @@ -184,6 +193,7 @@ func getObservedClusterState() *ObservedClusterState {
"example.com": "example",
},
SecurityContext: &securityContext,
HostAliases: hostAliases,
},
JobManager: &v1beta1.JobManagerSpec{
AccessScope: v1beta1.AccessScopeVPC,
Expand Down Expand Up @@ -215,6 +225,7 @@ func getObservedClusterState() *ObservedClusterState {
},
},
Tolerations: tolerations,
HostAliases: hostAliases,
MemoryOffHeapRatio: &memoryOffHeapRatio,
MemoryOffHeapMin: memoryOffHeapMin,
MemoryProcessRatio: &memoryProcessRatio,
Expand Down Expand Up @@ -284,6 +295,7 @@ func getObservedClusterState() *ObservedClusterState {
},
},
Tolerations: tolerations,
HostAliases: hostAliases,
PodAnnotations: map[string]string{
"example.com": "example",
},
Expand Down Expand Up @@ -442,6 +454,7 @@ func TestGetDesiredClusterState(t *testing.T) {
},
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Tolerations: tolerations,
HostAliases: hostAliases,
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &userAndGroupId,
RunAsGroup: &userAndGroupId,
Expand Down Expand Up @@ -787,6 +800,7 @@ func TestGetDesiredClusterState(t *testing.T) {
},
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Tolerations: tolerations,
HostAliases: hostAliases,
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &userAndGroupId,
RunAsGroup: &userAndGroupId,
Expand Down Expand Up @@ -974,6 +988,7 @@ func TestGetDesiredClusterState(t *testing.T) {
RunAsUser: &userAndGroupId,
RunAsGroup: &userAndGroupId,
},
HostAliases: hostAliases,
ServiceAccountName: serviceAccount,
},
},
Expand Down Expand Up @@ -1224,6 +1239,7 @@ func TestTmDeploymentTypeDeployment(t *testing.T) {
},
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Tolerations: tolerations,
HostAliases: hostAliases,
SecurityContext: &corev1.PodSecurityContext{
RunAsUser: &userAndGroupId,
RunAsGroup: &userAndGroupId,
Expand Down
3 changes: 3 additions & 0 deletions docs/crd.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ _Appears in:_
| `initContainers` _[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#container-v1-core) array_ | _(Optional)_ Init containers of the Job Manager pod. [More info](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) |
| `nodeSelector` _object (keys:string, values:string)_ | _(Optional)_ Selector which must match a node's labels for the JobManager pod to be scheduled on that node. [More info](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/) |
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#toleration-v1-core) array_ | _(Optional)_ Defines the node affinity of the pod [More info](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) |
| `hostAliases` _[HostAliases](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#hostalias-v1-core) array_ | _(Optional)_ Customize the /etc/hosts of the pod [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/) |
| `sidecars` _[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#container-v1-core) array_ | _(Optional)_ Sidecar containers running alongside with the JobManager container in the pod. [More info](https://kubernetes.io/docs/concepts/containers/) |
| `podAnnotations` _object (keys:string, values:string)_ | _(Optional)_ JobManager StatefulSet pod template annotations. [More info](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) |
| `securityContext` _[PodSecurityContext](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#podsecuritycontext-v1-core)_ | _(Optional)_ SecurityContext of the JobManager pod. [More info](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod) |
Expand Down Expand Up @@ -341,6 +342,7 @@ _Appears in:_
| `initContainers` _[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#container-v1-core) array_ | _(Optional)_ Init containers of the Job pod. A typical use case could be using an init container to download a remote job jar to a local path which is referenced by the `jarFile` property. [More info](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) |
| `nodeSelector` _object (keys:string, values:string)_ | _(Optional)_ Selector which must match a node's labels for the Job submitter pod to be scheduled on that node. [More info](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/) |
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#toleration-v1-core) array_ | _(Optional)_ Defines the node affinity of the Job submitter pod [More info](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) |
| `hostAliases` _[HostAliases](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#hostalias-v1-core) array_ | _(Optional)_ Customize the /etc/hosts of the pod [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/) |
| `restartPolicy` _JobRestartPolicy_ | Restart policy when the job fails, one of `Never, FromSavepointOnFailure`, default: `Never`. `Never` means the operator will never try to restart a failed job, manual cleanup and restart is required. `FromSavepointOnFailure` means the operator will try to restart the failed job from the savepoint recorded in the job status if available; otherwise, the job will stay in failed state. This option is usually used together with `autoSavepointSeconds` and `savepointsDir`. |
| `cleanupPolicy` _[CleanupPolicy](#cleanuppolicy)_ | The action to take after job finishes. |
| `cancelRequested` _boolean_ | Deprecated: _(Optional)_ Request the job to be cancelled. Only applies to running jobs. If `savePointsDir` is provided, a savepoint will be taken before stopping the job. |
Expand Down Expand Up @@ -472,6 +474,7 @@ _Appears in:_
| `initContainers` _[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#container-v1-core) array_ | _(Optional)_ Init containers of the Task Manager pod. [More info](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) |
| `nodeSelector` _object (keys:string, values:string)_ | _(Optional)_ Selector which must match a node's labels for the TaskManager pod to be scheduled on that node. [More info](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/) |
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#toleration-v1-core) array_ | _(Optional)_ Defines the node affinity of the pod [More info](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) |
| `hostAliases` _[HostAliases](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#hostalias-v1-core) array_ | _(Optional)_ Customize the /etc/hosts of the pod [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/) |
| `sidecars` _[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#container-v1-core) array_ | _(Optional)_ Sidecar containers running alongside with the TaskManager container in the pod. [More info](https://kubernetes.io/docs/concepts/containers/) |
| `podAnnotations` _object (keys:string, values:string)_ | _(Optional)_ TaskManager StatefulSet pod template annotations. [More info](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) |
| `securityContext` _[PodSecurityContext](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#podsecuritycontext-v1-core)_ | _(Optional)_ SecurityContext of the TaskManager pod. [More info](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod) |
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/flink-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
name: flink-operator
appVersion: "1.0"
description: A Helm chart for flink on Kubernetes operator
version: "0.2.1"
version: "0.2.2"
keywords:
- flink
home: https://github.com/spotify/flink-on-k8s-operator
33 changes: 33 additions & 0 deletions helm-chart/flink-operator/templates/flink-cluster-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,17 @@ spec:
type: string
type: object
type: array
hostAliases:
items:
properties:
ip:
type: string
hostnames:
items:
type: string
type: array
type: object
type: array
volumeMounts:
items:
properties:
Expand Down Expand Up @@ -3171,6 +3182,17 @@ spec:
type: string
type: object
type: array
hostAliases:
items:
properties:
ip:
type: string
hostnames:
items:
type: string
type: array
type: object
type: array
volumeClaimTemplates:
items:
properties:
Expand Down Expand Up @@ -5546,6 +5568,17 @@ spec:
type: string
type: object
type: array
hostAliases:
items:
properties:
ip:
type: string
hostnames:
items:
type: string
type: array
type: object
type: array
volumeClaimTemplates:
items:
properties:
Expand Down

0 comments on commit aaf29e1

Please sign in to comment.