Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Disable Service Links by default #146

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Service Labels
| `k8ify.exposePlain.$port.type: ClusterIP\|LoadBalancer\|ExternalName\|NodePort` | Set the k8s Service type (default `LoadBalancer`) |
| `k8ify.exposePlain.$port.externalTrafficPolicy: Cluster\|Local` | Set the k8s Service traffic policy (default `Local`). `Local` makes the client IP visible to the application but may provide worse load balancing than `Cluster`. |
| `k8ify.exposePlain.$port.healthCheckNodePort: $port` | Set the k8s Service health check port number. |
| `k8ify.enableServiceLinks: $value` | Inject ENV variables for each K8s service in the namespace. |

Volume Labels

Expand Down
4 changes: 4 additions & 0 deletions docs/conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ spec:
# `services.$name.labels["k8ify.annotations"]` merged with `services.$name.labels["k8ify.Pod.annotations"]` (latter take priority)
foo: bar
spec:
# `services.$name.labels."k8ify.enableServiceLinks`, defaults to `false`
enableServiceLinks: false
# Anti-affinity is always configured to avoid running multiple replicas (instances) of the same deployment on the same node
affinity:
podAntiAffinity:
Expand Down Expand Up @@ -237,6 +239,8 @@ spec:
# timestamp to ensure restarts of all pods
k8ify.restart-trigger: "1675680748"
spec:
# `services.$name.labels."k8ify.enableServiceLinks`, defaults to `false`
enableServiceLinks: false
# Anti-affinity is always configured to avoid running multiple replicas (instances) of the same deployment on the same node
affinity:
podAntiAffinity:
Expand Down
3 changes: 3 additions & 0 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ func composeServiceToPodTemplate(
volumesArray = append(volumesArray, volumes[key])
}

enableServiceLinks := util.GetBoolean(workload.Labels(), "k8ify.enableServiceLinks")

podSpec := core.PodSpec{
EnableServiceLinks: &enableServiceLinks,
Containers: containers,
RestartPolicy: core.RestartPolicyAlways,
Volumes: volumesArray,
Expand Down
1 change: 1 addition & 0 deletions tests/golden/101/manifests/nginx-oasp-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ spec:
tcpSocket:
port: 80
timeoutSeconds: 60
enableServiceLinks: false
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ spec:
tcpSocket:
port: 80
timeoutSeconds: 60
enableServiceLinks: false
restartPolicy: Always
status: {}
1 change: 1 addition & 0 deletions tests/golden/defaults/manifests/nginx-oasp-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ spec:
tcpSocket:
port: 80
timeoutSeconds: 60
enableServiceLinks: false
restartPolicy: Always
status: {}
8 changes: 5 additions & 3 deletions tests/golden/demo/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
version: '3.4'
version: "3.4"
services:
mongo:
image: mongo:4.0
restart: always
ports:
- '127.0.0.1:27017:27017'
- "127.0.0.1:27017:27017"
volumes:
- mongodb_data:/data/db
portal:
labels:
k8ify.enableServiceLinks: "true"
image: vshn/portal:dev
build:
target: base
Expand All @@ -20,7 +22,7 @@ services:
- "8001:8000"
volumes:
- ./:/src
entrypoint:
entrypoint:
- echo
command:
- "Hello World"
Expand Down
1 change: 1 addition & 0 deletions tests/golden/demo/manifests/mongo-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ spec:
volumeMounts:
- mountPath: /data/db
name: mongodb-data
enableServiceLinks: false
restartPolicy: Always
updateStrategy: {}
volumeClaimTemplates:
Expand Down
1 change: 1 addition & 0 deletions tests/golden/demo/manifests/portal-oasp-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ spec:
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 60
enableServiceLinks: true
restartPolicy: Always
serviceAccountName: portalk8saccess
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ spec:
imagePullPolicy: Always
name: pinger-oasp
resources: {}
enableServiceLinks: false
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ spec:
imagePullPolicy: Always
name: pinger-oasp
resources: {}
enableServiceLinks: false
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ spec:
imagePullPolicy: Always
name: fooBar-oasp
resources: {}
enableServiceLinks: false
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ spec:
tcpSocket:
port: 8888
timeoutSeconds: 60
enableServiceLinks: false
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ spec:
tcpSocket:
port: 8888
timeoutSeconds: 60
enableServiceLinks: false
restartPolicy: Always
status: {}
1 change: 1 addition & 0 deletions tests/golden/noports/manifests/pinger-oasp-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ spec:
imagePullPolicy: Always
name: pinger-oasp
resources: {}
enableServiceLinks: false
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ spec:
tcpSocket:
port: 4480
timeoutSeconds: 60
enableServiceLinks: false
restartPolicy: Always
status: {}
1 change: 1 addition & 0 deletions tests/golden/parts/manifests/mongo-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ spec:
volumeMounts:
- mountPath: /data/db
name: mongodb-data
enableServiceLinks: false
restartPolicy: Always
updateStrategy: {}
volumeClaimTemplates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ spec:
name: sessions
- mountPath: /data/web
name: webdata
enableServiceLinks: false
restartPolicy: Always
volumes:
- name: sessions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ spec:
tcpSocket:
port: 80
timeoutSeconds: 60
enableServiceLinks: false
restartPolicy: Always
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ spec:
volumeMounts:
- mountPath: /data
name: default-data
enableServiceLinks: false
restartPolicy: Always
updateStrategy: {}
volumeClaimTemplates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
volumeMounts:
- mountPath: /data
name: default-shared-data
enableServiceLinks: false
restartPolicy: Always
volumes:
- name: default-shared-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
volumeMounts:
- mountPath: /data
name: shared-data
enableServiceLinks: false
restartPolicy: Always
volumes:
- name: shared-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
volumeMounts:
- mountPath: /data
name: shared-data
enableServiceLinks: false
restartPolicy: Always
volumes:
- name: shared-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:
volumeMounts:
- mountPath: /data
name: singleton-db-storage
enableServiceLinks: false
restartPolicy: Always
updateStrategy: {}
volumeClaimTemplates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ spec:
volumeMounts:
- mountPath: /data
name: default-data
enableServiceLinks: false
restartPolicy: Always
updateStrategy: {}
volumeClaimTemplates:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
volumeMounts:
- mountPath: /data
name: default-shared-data
enableServiceLinks: false
restartPolicy: Always
volumes:
- name: default-shared-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
volumeMounts:
- mountPath: /data
name: shared-data
enableServiceLinks: false
restartPolicy: Always
volumes:
- name: shared-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
volumeMounts:
- mountPath: /data
name: shared-data
enableServiceLinks: false
restartPolicy: Always
volumes:
- name: shared-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:
volumeMounts:
- mountPath: /data
name: singleton-db-storage
enableServiceLinks: false
restartPolicy: Always
updateStrategy: {}
volumeClaimTemplates:
Expand Down