Skip to content

Commit 05a6ddf

Browse files
egeguneshors
andauthored
K8SPSMDB-938: Allow configuring hostAliases for pods (#1236) (#1251)
* K8SPSMDB-938: Allow configuring hostAliases for pods * fix k8s version Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent c3183e8 commit 05a6ddf

File tree

10 files changed

+217
-0
lines changed

10 files changed

+217
-0
lines changed

config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,17 @@ spec:
28742874
- votes
28752875
type: object
28762876
type: array
2877+
hostAliases:
2878+
items:
2879+
properties:
2880+
hostnames:
2881+
items:
2882+
type: string
2883+
type: array
2884+
ip:
2885+
type: string
2886+
type: object
2887+
type: array
28772888
labels:
28782889
additionalProperties:
28792890
type: string
@@ -9637,6 +9648,17 @@ spec:
96379648
- votes
96389649
type: object
96399650
type: array
9651+
hostAliases:
9652+
items:
9653+
properties:
9654+
hostnames:
9655+
items:
9656+
type: string
9657+
type: array
9658+
ip:
9659+
type: string
9660+
type: object
9661+
type: array
96409662
labels:
96419663
additionalProperties:
96429664
type: string
@@ -14417,6 +14439,17 @@ spec:
1441714439
servicePerPod:
1441814440
type: boolean
1441914441
type: object
14442+
hostAliases:
14443+
items:
14444+
properties:
14445+
hostnames:
14446+
items:
14447+
type: string
14448+
type: array
14449+
ip:
14450+
type: string
14451+
type: object
14452+
type: array
1442014453
hostPort:
1442114454
format: int32
1442214455
type: integer

deploy/bundle.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,17 @@ spec:
34773477
- votes
34783478
type: object
34793479
type: array
3480+
hostAliases:
3481+
items:
3482+
properties:
3483+
hostnames:
3484+
items:
3485+
type: string
3486+
type: array
3487+
ip:
3488+
type: string
3489+
type: object
3490+
type: array
34803491
labels:
34813492
additionalProperties:
34823493
type: string
@@ -10240,6 +10251,17 @@ spec:
1024010251
- votes
1024110252
type: object
1024210253
type: array
10254+
hostAliases:
10255+
items:
10256+
properties:
10257+
hostnames:
10258+
items:
10259+
type: string
10260+
type: array
10261+
ip:
10262+
type: string
10263+
type: object
10264+
type: array
1024310265
labels:
1024410266
additionalProperties:
1024510267
type: string
@@ -15020,6 +15042,17 @@ spec:
1502015042
servicePerPod:
1502115043
type: boolean
1502215044
type: object
15045+
hostAliases:
15046+
items:
15047+
properties:
15048+
hostnames:
15049+
items:
15050+
type: string
15051+
type: array
15052+
ip:
15053+
type: string
15054+
type: object
15055+
type: array
1502315056
hostPort:
1502415057
format: int32
1502515058
type: integer

deploy/cr.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,30 @@ spec:
279279
# rack: rack-22
280280
# nodeSelector:
281281
# disktype: ssd
282+
# schedulerName: "default"
283+
resources:
284+
limits:
285+
cpu: "300m"
286+
memory: "0.5G"
287+
requests:
288+
cpu: "300m"
289+
memory: "0.5G"
290+
volumeSpec:
291+
# emptyDir: {}
292+
# hostPath:
293+
# path: /data
294+
# type: Directory
295+
persistentVolumeClaim:
296+
# storageClassName: standard
297+
# accessModes: [ "ReadWriteOnce" ]
298+
resources:
299+
requests:
300+
storage: 3Gi
301+
# hostAliases:
302+
# - ip: "10.10.0.2"
303+
# hostnames:
304+
# - "host1"
305+
# - "host2"
282306

283307
sharding:
284308
enabled: true
@@ -374,6 +398,11 @@ spec:
374398
resources:
375399
requests:
376400
storage: 3Gi
401+
# hostAliases:
402+
# - ip: "10.10.0.2"
403+
# hostnames:
404+
# - "host1"
405+
# - "host2"
377406

378407
mongos:
379408
size: 3
@@ -442,6 +471,11 @@ spec:
442471
# service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
443472
# serviceLabels:
444473
# rack: rack-22
474+
# hostAliases:
475+
# - ip: "10.10.0.2"
476+
# hostnames:
477+
# - "host1"
478+
# - "host2"
445479

446480
backup:
447481
enabled: true

deploy/crd.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,17 @@ spec:
34773477
- votes
34783478
type: object
34793479
type: array
3480+
hostAliases:
3481+
items:
3482+
properties:
3483+
hostnames:
3484+
items:
3485+
type: string
3486+
type: array
3487+
ip:
3488+
type: string
3489+
type: object
3490+
type: array
34803491
labels:
34813492
additionalProperties:
34823493
type: string
@@ -10240,6 +10251,17 @@ spec:
1024010251
- votes
1024110252
type: object
1024210253
type: array
10254+
hostAliases:
10255+
items:
10256+
properties:
10257+
hostnames:
10258+
items:
10259+
type: string
10260+
type: array
10261+
ip:
10262+
type: string
10263+
type: object
10264+
type: array
1024310265
labels:
1024410266
additionalProperties:
1024510267
type: string
@@ -15020,6 +15042,17 @@ spec:
1502015042
servicePerPod:
1502115043
type: boolean
1502215044
type: object
15045+
hostAliases:
15046+
items:
15047+
properties:
15048+
hostnames:
15049+
items:
15050+
type: string
15051+
type: array
15052+
ip:
15053+
type: string
15054+
type: object
15055+
type: array
1502315056
hostPort:
1502415057
format: int32
1502515058
type: integer

deploy/cw-bundle.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,17 @@ spec:
34773477
- votes
34783478
type: object
34793479
type: array
3480+
hostAliases:
3481+
items:
3482+
properties:
3483+
hostnames:
3484+
items:
3485+
type: string
3486+
type: array
3487+
ip:
3488+
type: string
3489+
type: object
3490+
type: array
34803491
labels:
34813492
additionalProperties:
34823493
type: string
@@ -10240,6 +10251,17 @@ spec:
1024010251
- votes
1024110252
type: object
1024210253
type: array
10254+
hostAliases:
10255+
items:
10256+
properties:
10257+
hostnames:
10258+
items:
10259+
type: string
10260+
type: array
10261+
ip:
10262+
type: string
10263+
type: object
10264+
type: array
1024310265
labels:
1024410266
additionalProperties:
1024510267
type: string
@@ -15020,6 +15042,17 @@ spec:
1502015042
servicePerPod:
1502115043
type: boolean
1502215044
type: object
15045+
hostAliases:
15046+
items:
15047+
properties:
15048+
hostnames:
15049+
items:
15050+
type: string
15051+
type: array
15052+
ip:
15053+
type: string
15054+
type: object
15055+
type: array
1502315056
hostPort:
1502415057
format: int32
1502515058
type: integer

e2e-tests/version-service/conf/crd.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,17 @@ spec:
34773477
- votes
34783478
type: object
34793479
type: array
3480+
hostAliases:
3481+
items:
3482+
properties:
3483+
hostnames:
3484+
items:
3485+
type: string
3486+
type: array
3487+
ip:
3488+
type: string
3489+
type: object
3490+
type: array
34803491
labels:
34813492
additionalProperties:
34823493
type: string
@@ -10240,6 +10251,17 @@ spec:
1024010251
- votes
1024110252
type: object
1024210253
type: array
10254+
hostAliases:
10255+
items:
10256+
properties:
10257+
hostnames:
10258+
items:
10259+
type: string
10260+
type: array
10261+
ip:
10262+
type: string
10263+
type: object
10264+
type: array
1024310265
labels:
1024410266
additionalProperties:
1024510267
type: string
@@ -15020,6 +15042,17 @@ spec:
1502015042
servicePerPod:
1502115043
type: boolean
1502215044
type: object
15045+
hostAliases:
15046+
items:
15047+
properties:
15048+
hostnames:
15049+
items:
15050+
type: string
15051+
type: array
15052+
ip:
15053+
type: string
15054+
type: object
15055+
type: array
1502315056
hostPort:
1502415057
format: int32
1502515058
type: integer

pkg/apis/psmdb/v1/psmdb_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ type ReplsetSpec struct {
507507
Configuration MongoConfiguration `json:"configuration,omitempty"`
508508
ExternalNodes []*ExternalNode `json:"externalNodes,omitempty"`
509509
NonVoting NonVotingSpec `json:"nonvoting,omitempty"`
510+
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
510511
}
511512

512513
func (r *ReplsetSpec) ServiceName(cr *PerconaServerMongoDB) string {
@@ -586,6 +587,7 @@ type MongosSpec struct {
586587
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
587588
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
588589
Configuration MongoConfiguration `json:"configuration,omitempty"`
590+
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
589591
}
590592

591593
type MongosSpecSetParameter struct {

pkg/apis/psmdb/v1/zz_generated.deepcopy.go

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

pkg/psmdb/mongos.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func MongosTemplateSpec(cr *api.PerconaServerMongoDB, initImage string, log logr
122122
Annotations: annotations,
123123
},
124124
Spec: corev1.PodSpec{
125+
HostAliases: cr.Spec.Sharding.Mongos.HostAliases,
125126
SecurityContext: cr.Spec.Sharding.Mongos.PodSecurityContext,
126127
Affinity: PodAffinity(cr, cr.Spec.Sharding.Mongos.MultiAZ.Affinity, ls),
127128
NodeSelector: cr.Spec.Sharding.Mongos.MultiAZ.NodeSelector,

pkg/psmdb/statefulset.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func StatefulSpec(ctx context.Context, cr *api.PerconaServerMongoDB, replset *ap
141141
Annotations: annotations,
142142
},
143143
Spec: corev1.PodSpec{
144+
HostAliases: replset.HostAliases,
144145
SecurityContext: podSecurityContext,
145146
Affinity: PodAffinity(cr, multiAZ.Affinity, customLabels),
146147
NodeSelector: multiAZ.NodeSelector,

0 commit comments

Comments
 (0)