Skip to content

Commit

Permalink
* Made-so the new "local" command in NGINX_Gateway.star does not log …
Browse files Browse the repository at this point in the history
…its (long) output to the tiltfile's logs.

* Included an explanation of why type:LoadBalancer was chosen over type:NodePort. (since I just did some tests on the local and ovh k8s clusters, and both do in fact work, when the externalIPs field is provided for the k8s cluster)
* Renamed "nginx-gateway-node-port" to "entry-point-service". (old name was misleading since it said "node-port" when it was in fact a load-balancer)
* Fixed that for the local k8s cluster, the entry-point was being exposed at "localhost:80" rather than "localhost:5100". (to match with existing behavior and documentation; the reason port 80 is dis-preferred is partly because we want to reduce the chance of clashes with other projects and tests that like to use that port)
  • Loading branch information
Venryx committed Mar 12, 2024
1 parent dc2fcfb commit a57150a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 67 deletions.
37 changes: 37 additions & 0 deletions Packages/deploy/LoadBalancer/@Attempt7/entry_point_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: v1
kind: Service
metadata:
name: entry-point-service
namespace: default
labels:
app.kubernetes.io/name: nginx-gateway
app.kubernetes.io/instance: nginx-gateway
app.kubernetes.io/version: "1.0.0"
#app.kubernetes.io/name: "nginx-gateway-fabric"
#app.kubernetes.io/instance: "ngf"
# annotations:
# meta.helm.sh/release-name: "release-test-1"
# meta.helm.sh/release-namespace: "default"
spec:
# The below is a comparison between using type:NodePort and type:LoadBalancer. (since both have been confirmed to work both locally and in OVH)
# Advantages of NodePort:
# 1) Slightly simpler mechanics.
# 2) Ensures than an (unneeded) external load-balancer resource isn't provisioned by the cloud-provider. (although OVH *seems* to avoid this, when an external-ip is provided)
# Advantages of LoadBalancer:
# 1) Works for a dev's local k8s cluster. (without needing to create a port-forward)
# 2) Matches with the type of service that (normally) would get created by nginx-gateway-fabric.
# For now, we've chosen to go with "type:LoadBalancer". (mainly because of its advantage #1)
type: LoadBalancer
selector:
#app.kubernetes.io/name: nginx-gateway-fabric
app.kubernetes.io/instance: ngf
ports:
- name: http
protocol: TCP
port: TILT_PLACEHOLDER:port
targetPort: 80
"TILT_PLACEHOLDER:externalIPs":
- TILT_PLACEHOLDER:bind_to_address
## The externalTrafficPolicy of the service. The value Local preserves the client source IP.
externalTrafficPolicy: Local
#internalTrafficPolicy: Local
58 changes: 0 additions & 58 deletions Packages/deploy/LoadBalancer/@Attempt7/node_port_service.yaml

This file was deleted.

24 changes: 15 additions & 9 deletions Tilt/NGINX_Gateway.star
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ def Start_NGINXGateway(g):
])
#k8s_resource(workload='ngf', labels=["gateway"], port_forwards='80' if g["REMOTE"] else None)

bind_to_address = "127.0.0.1" # This will actually fail, but we always want a value
cluster_data = decode_yaml(local("kubectl get node -A -o yaml --context %s " % (g["CONTEXT"])))
for node in cluster_data['items']:
for address in node['status']['addresses']:
if address['type'] == "InternalIP":
bind_to_address = address["address"]
bind_to_address = ""
if g["REMOTE"]:
cluster_data = decode_yaml(local("kubectl get node -A -o yaml --context %s " % (g["CONTEXT"]), quiet = True))
for node in cluster_data['items']:
for address in node['status']['addresses']:
if address['type'] == "InternalIP":
bind_to_address = address["address"]
print("Assigning external-ip to nginx load-balancer: " + bind_to_address)

k8s_yaml(ReadFileWithReplacements('../Packages/deploy/LoadBalancer/@Attempt7/node_port_service.yaml', {"bind_to_address": bind_to_address}))
k8s_yaml(ReadFileWithReplacements('../Packages/deploy/LoadBalancer/@Attempt7/entry_point_service.yaml', {
"TILT_PLACEHOLDER:port": "80" if g["REMOTE"] else "5100",
"TILT_PLACEHOLDER:externalIPs": "externalIPs" if len(bind_to_address) > 0 else "externalIPs_disabled",
"TILT_PLACEHOLDER:bind_to_address": bind_to_address,
}))
NEXT_k8s_resource_batch(g, [
{
"new_name": "nginx-node-port-service-tilt", "labels": ["gateway"],
"new_name": "entry-point-service-tilt", "labels": ["gateway"],
"objects": [
"nginx-gateway-node-port",
"entry-point-service",
]
#"trigger_mode": TRIGGER_MODE_MANUAL,
#"port_forwards": '80' if g["REMOTE"] else '8000:80',
Expand Down

0 comments on commit a57150a

Please sign in to comment.