Skip to content

Commit aaf29e1

Browse files
authored
Add hostAliases support for all pod templates (#398) (#415)
1 parent 6b770a2 commit aaf29e1

File tree

8 files changed

+122
-1
lines changed

8 files changed

+122
-1
lines changed

apis/flinkcluster/v1beta1/flinkcluster_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ type JobManagerSpec struct {
279279
// 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.
280280
// [More info](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
281281
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`
282+
283+
// _(Optional)_ Adding entries to JobManager pod /etc/hosts with HostAliases
284+
// [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/)
285+
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
282286
}
283287

284288
// TaskManagerPorts defines ports of TaskManager.
@@ -394,6 +398,10 @@ type TaskManagerSpec struct {
394398
// 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.
395399
// [More info](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
396400
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`
401+
402+
// _(Optional)_ Adding entries to TaskManager pod /etc/hosts with HostAliases
403+
// [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/)
404+
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
397405
}
398406

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

552+
// _(Optional)_ Adding entries to Job pod /etc/hosts with HostAliases
553+
// [More info](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/)
554+
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
555+
544556
// Job running mode, `"Blocking", "Detached"`, default: `"Detached"`
545557
Mode *JobMode `json:"mode,omitempty"`
546558
}

apis/flinkcluster/v1beta1/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/flinkoperator.k8s.io_flinkclusters.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,17 @@ spec:
899899
type: string
900900
type: object
901901
type: array
902+
hostAliases:
903+
items:
904+
properties:
905+
ip:
906+
type: string
907+
hostnames:
908+
items:
909+
type: string
910+
type: array
911+
type: object
912+
type: array
902913
volumeMounts:
903914
items:
904915
properties:
@@ -3055,6 +3066,17 @@ spec:
30553066
type: string
30563067
type: object
30573068
type: array
3069+
hostAliases:
3070+
items:
3071+
properties:
3072+
ip:
3073+
type: string
3074+
hostnames:
3075+
items:
3076+
type: string
3077+
type: array
3078+
type: object
3079+
type: array
30583080
volumeClaimTemplates:
30593081
items:
30603082
properties:
@@ -5342,6 +5364,17 @@ spec:
53425364
type: string
53435365
type: object
53445366
type: array
5367+
hostAliases:
5368+
items:
5369+
properties:
5370+
ip:
5371+
type: string
5372+
hostnames:
5373+
items:
5374+
type: string
5375+
type: array
5376+
type: object
5377+
type: array
53455378
volumeClaimTemplates:
53465379
items:
53475380
properties:

controllers/flinkcluster/flinkcluster_converter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func newJobManagerPodSpec(mainContainer *corev1.Container, flinkCluster *v1beta1
213213
Tolerations: jobManagerSpec.Tolerations,
214214
ImagePullSecrets: imageSpec.PullSecrets,
215215
SecurityContext: jobManagerSpec.SecurityContext,
216+
HostAliases: jobManagerSpec.HostAliases,
216217
ServiceAccountName: getServiceAccountName(serviceAccount),
217218
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
218219
}
@@ -485,6 +486,7 @@ func newTaskManagerPodSpec(mainContainer *corev1.Container, flinkCluster *v1beta
485486
Tolerations: taskManagerSpec.Tolerations,
486487
ImagePullSecrets: imageSpec.PullSecrets,
487488
SecurityContext: taskManagerSpec.SecurityContext,
489+
HostAliases: taskManagerSpec.HostAliases,
488490
ServiceAccountName: getServiceAccountName(serviceAccount),
489491
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
490492
}
@@ -838,6 +840,7 @@ func newJobSubmitterPodSpec(flinkCluster *v1beta1.FlinkCluster) *corev1.PodSpec
838840
Volumes: volumes,
839841
ImagePullSecrets: imageSpec.PullSecrets,
840842
SecurityContext: jobSpec.SecurityContext,
843+
HostAliases: jobSpec.HostAliases,
841844
ServiceAccountName: getServiceAccountName(serviceAccount),
842845
NodeSelector: jobSpec.NodeSelector,
843846
Tolerations: jobSpec.Tolerations,

controllers/flinkcluster/flinkcluster_converter_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ var (
120120
Value: "toleration-value2",
121121
},
122122
}
123+
hostAliases = []corev1.HostAlias{
124+
{
125+
IP: "127.0.0.1",
126+
Hostnames: []string{
127+
"test-localhost-alias1",
128+
"test-localhost-alias2",
129+
},
130+
},
131+
}
123132
userAndGroupId int64 = 9999
124133
securityContext = corev1.PodSecurityContext{
125134
RunAsUser: &userAndGroupId,
@@ -184,6 +193,7 @@ func getObservedClusterState() *ObservedClusterState {
184193
"example.com": "example",
185194
},
186195
SecurityContext: &securityContext,
196+
HostAliases: hostAliases,
187197
},
188198
JobManager: &v1beta1.JobManagerSpec{
189199
AccessScope: v1beta1.AccessScopeVPC,
@@ -215,6 +225,7 @@ func getObservedClusterState() *ObservedClusterState {
215225
},
216226
},
217227
Tolerations: tolerations,
228+
HostAliases: hostAliases,
218229
MemoryOffHeapRatio: &memoryOffHeapRatio,
219230
MemoryOffHeapMin: memoryOffHeapMin,
220231
MemoryProcessRatio: &memoryProcessRatio,
@@ -284,6 +295,7 @@ func getObservedClusterState() *ObservedClusterState {
284295
},
285296
},
286297
Tolerations: tolerations,
298+
HostAliases: hostAliases,
287299
PodAnnotations: map[string]string{
288300
"example.com": "example",
289301
},
@@ -442,6 +454,7 @@ func TestGetDesiredClusterState(t *testing.T) {
442454
},
443455
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
444456
Tolerations: tolerations,
457+
HostAliases: hostAliases,
445458
SecurityContext: &corev1.PodSecurityContext{
446459
RunAsUser: &userAndGroupId,
447460
RunAsGroup: &userAndGroupId,
@@ -787,6 +800,7 @@ func TestGetDesiredClusterState(t *testing.T) {
787800
},
788801
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
789802
Tolerations: tolerations,
803+
HostAliases: hostAliases,
790804
SecurityContext: &corev1.PodSecurityContext{
791805
RunAsUser: &userAndGroupId,
792806
RunAsGroup: &userAndGroupId,
@@ -974,6 +988,7 @@ func TestGetDesiredClusterState(t *testing.T) {
974988
RunAsUser: &userAndGroupId,
975989
RunAsGroup: &userAndGroupId,
976990
},
991+
HostAliases: hostAliases,
977992
ServiceAccountName: serviceAccount,
978993
},
979994
},
@@ -1224,6 +1239,7 @@ func TestTmDeploymentTypeDeployment(t *testing.T) {
12241239
},
12251240
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
12261241
Tolerations: tolerations,
1242+
HostAliases: hostAliases,
12271243
SecurityContext: &corev1.PodSecurityContext{
12281244
RunAsUser: &userAndGroupId,
12291245
RunAsGroup: &userAndGroupId,

docs/crd.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ _Appears in:_
301301
| `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/) |
302302
| `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/) |
303303
| `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/) |
304+
| `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/) |
304305
| `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/) |
305306
| `podAnnotations` _object (keys:string, values:string)_ | _(Optional)_ JobManager StatefulSet pod template annotations. [More info](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) |
306307
| `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) |
@@ -341,6 +342,7 @@ _Appears in:_
341342
| `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/) |
342343
| `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/) |
343344
| `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/) |
345+
| `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/) |
344346
| `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`. |
345347
| `cleanupPolicy` _[CleanupPolicy](#cleanuppolicy)_ | The action to take after job finishes. |
346348
| `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. |
@@ -472,6 +474,7 @@ _Appears in:_
472474
| `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/) |
473475
| `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/) |
474476
| `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/) |
477+
| `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/) |
475478
| `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/) |
476479
| `podAnnotations` _object (keys:string, values:string)_ | _(Optional)_ TaskManager StatefulSet pod template annotations. [More info](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) |
477480
| `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) |

helm-chart/flink-operator/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
name: flink-operator
33
appVersion: "1.0"
44
description: A Helm chart for flink on Kubernetes operator
5-
version: "0.2.1"
5+
version: "0.2.2"
66
keywords:
77
- flink
88
home: https://github.com/spotify/flink-on-k8s-operator

helm-chart/flink-operator/templates/flink-cluster-crd.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,17 @@ spec:
935935
type: string
936936
type: object
937937
type: array
938+
hostAliases:
939+
items:
940+
properties:
941+
ip:
942+
type: string
943+
hostnames:
944+
items:
945+
type: string
946+
type: array
947+
type: object
948+
type: array
938949
volumeMounts:
939950
items:
940951
properties:
@@ -3171,6 +3182,17 @@ spec:
31713182
type: string
31723183
type: object
31733184
type: array
3185+
hostAliases:
3186+
items:
3187+
properties:
3188+
ip:
3189+
type: string
3190+
hostnames:
3191+
items:
3192+
type: string
3193+
type: array
3194+
type: object
3195+
type: array
31743196
volumeClaimTemplates:
31753197
items:
31763198
properties:
@@ -5546,6 +5568,17 @@ spec:
55465568
type: string
55475569
type: object
55485570
type: array
5571+
hostAliases:
5572+
items:
5573+
properties:
5574+
ip:
5575+
type: string
5576+
hostnames:
5577+
items:
5578+
type: string
5579+
type: array
5580+
type: object
5581+
type: array
55495582
volumeClaimTemplates:
55505583
items:
55515584
properties:

0 commit comments

Comments
 (0)