-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6687 from Incanta/feat/port-forwarding-api
API: add post/delete commands for port forwarding
- Loading branch information
Showing
4 changed files
with
259 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
load '../helpers/load' | ||
|
||
@test 'start k8s' { | ||
factory_reset | ||
start_kubernetes | ||
wait_for_kubelet | ||
} | ||
|
||
@test 'deploy sample app' { | ||
kubectl apply --filename - <<EOF | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: webapp-configmap | ||
data: | ||
index: "Hello World!" | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: webapp | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: webapp | ||
template: | ||
metadata: | ||
labels: | ||
app: webapp | ||
spec: | ||
volumes: | ||
- name: webapp-config-volume | ||
configMap: | ||
name: webapp-configmap | ||
items: | ||
- key: index | ||
path: index.html | ||
containers: | ||
- name: webapp | ||
image: nginx | ||
volumeMounts: | ||
- name: webapp-config-volume | ||
mountPath: /usr/share/nginx/html | ||
EOF | ||
} | ||
|
||
@test 'deploy ingress' { | ||
kubectl apply --filename - <<EOF | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: webapp | ||
spec: | ||
type: ClusterIP | ||
selector: | ||
app: webapp | ||
ports: | ||
- port: 80 | ||
--- | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: webapp | ||
annotations: | ||
traefik.ingress.kubernetes.io/router.entrypoints: web | ||
spec: | ||
rules: | ||
- host: localhost | ||
http: | ||
paths: | ||
- path: / | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: webapp | ||
port: | ||
number: 80 | ||
EOF | ||
} | ||
|
||
@test 'fail to connect to the service on localhost without port forwarding' { | ||
run try --max 5 curl --silent --fail "http://localhost:8080" | ||
assert_failure | ||
} | ||
|
||
@test 'connect to the service on localhost with port forwarding' { | ||
rdctl api -X POST -b '{ "namespace": "default", "service": "webapp", "k8sPort": 80, "hostPort": 8080 }' port_forwarding | ||
run try curl --silent --fail "http://localhost:8080" | ||
assert_success | ||
assert_output "Hello World!" | ||
} | ||
|
||
@test 'fail to connect to the service on localhost after removing port forwarding' { | ||
rdctl api -X DELETE "port_forwarding?namespace=default&service=webapp&k8sPort=80" | ||
run try --max 5 curl --silent --fail "http://localhost:8080" | ||
assert_failure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters