Skip to content

Commit 734c480

Browse files
committed
0.0.37 released
1 parent c8386a7 commit 734c480

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# kubernetes-dnsConfig-mutating-webhook
2-
This is a Kubernetes mutating webhook to manipulate dnsConfig and dnsPolicy fields dynamically.
2+
This is a Kubernetes mutating webhook to manipulate `dnsConfig` and `dnsPolicy` dynamically.
3+
4+
If dnsPolicy is not specified or is set as ClusterFirst, the pod creation request is intercepted and mutated as the following:
5+
6+
```
7+
dnsConfig:
8+
nameservers:
9+
- 169.254.25.10
10+
options:
11+
- name: timeout
12+
value: "1"
13+
- name: ndots
14+
value: "2"
15+
- name: attempts
16+
value: "1"
17+
searches:
18+
- svc.dev-team
19+
dnsPolicy: None
20+
```
21+
22+
`Ndots`, `attempts` and `timeout` values can be given as environment variables of the [backend container](kubernetes-manifests/webhook-mutation-deployment.yml). Since this architecture is designed for a cluster that uses `nodelocalDNS`, nodelocalDNS_IP should be set as an environment variable too. Backend reads clusterDomain which is assumed to be same as the cluster name from the [cluster-info configmap](kubernetes-manifests/cluster-info.yml).
23+
24+
Namespaces which is wanted to be excluded can be given in the [configmap](kubernetes-manifests/mutating-webhook-cm.yml)
25+
26+
![logs](resources/image01.png)

kubernetes-manifests/cluster-metadata.yml renamed to kubernetes-manifests/cluster-info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ data:
44
kind: ConfigMap
55
metadata:
66
name: cluster-info
7+
namespace: kube-system

kubernetes-manifests/webhook-mutation-deployment.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ spec:
2020
image: ugurozturk99/dnsmutationwebhook:${CI_PIPELINE_ID}
2121
ports:
2222
- containerPort: 443
23-
resources:
24-
requests:
25-
cpu: "1m"
2623
env:
2724
- name: LOG_LEVEL
2825
value: "info"

mutate.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
list = data.split("\n")
1616
properties.close()
1717

18-
#config.load_kube_config()
19-
#api_instance = client.CoreV1Api()
2018
api_instance = client.CoreV1Api(client.ApiClient(incluster_config.load_incluster_config()))
21-
#pretty="true"
22-
#namespace="kube-system"
2319

2420
try:
2521
api_response = api_instance.list_namespaced_config_map(namespace="kube-system",pretty="true")
@@ -74,7 +70,7 @@
7470
exit(1)
7571

7672

77-
patch = "[{\"op\": \"add\", \"path\": \"/spec/dnsConfig\", \"value\": {\"nameservers\": [\"NODELOCALDNS_IP_VALUE\"], \"options\": [{\"name\": \"timeout\", \"value\": \"TIMEOUT_VALUE\"}, {\"name\": \"ndots\", \"value\": \"NDOTS_VALUE\"}, {\"name\": \"attempts\", \"value\": \"ATTEMPTS_VALUE\"}], \"searches\": [\"svc.CLUSTERDOMAIN_VALUE\",\"ns.svc.CLUSTERDOMAIN_VALUE\"]}}, {\"op\": \"replace\", \"path\": \"/spec/dnsPolicy\", \"value\": \"None\"}]"
73+
patch = "[{\"op\": \"add\", \"path\": \"/spec/dnsConfig\", \"value\": {\"nameservers\": [\"NODELOCALDNS_IP_VALUE\"], \"options\": [{\"name\": \"timeout\", \"value\": \"TIMEOUT_VALUE\"}, {\"name\": \"ndots\", \"value\": \"NDOTS_VALUE\"}, {\"name\": \"attempts\", \"value\": \"ATTEMPTS_VALUE\"}], \"searches\": [\"svc.CLUSTERDOMAIN_VALUE\"]}}, {\"op\": \"replace\", \"path\": \"/spec/dnsPolicy\", \"value\": \"None\"}]"
7874

7975
char_to_replace = {'TIMEOUT_VALUE': timeout, 'NDOTS_VALUE': ndots, 'ATTEMPTS_VALUE': attempts, 'NODELOCALDNS_IP_VALUE': nodelocaldns_ip, 'CLUSTERDOMAIN_VALUE': cluster_name}
8076
for key, value in char_to_replace.items():

resources/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION 0.0.37-SNAPSHOT
1+
VERSION 0.0.37

resources/image01.png

431 KB
Loading

0 commit comments

Comments
 (0)