[skip ci] k3s add ingress tp apple service

This commit is contained in:
az 2021-11-29 14:43:54 +01:00
parent 403c442a96
commit 85dd64c0d3

View file

@ -4,23 +4,37 @@ import org.domaindrivenarchitecture.provs.core.Prov
import org.domaindrivenarchitecture.provs.core.ProvResult import org.domaindrivenarchitecture.provs.core.ProvResult
fun Prov.checkAppleService(kubeCtlCmd: String = "kubectl") = task { fun Prov.checkAppleService(host: String = "127.0.0.1") = task {
val ip = cmd(kubeCtlCmd + " get svc apple-service -o jsonpath=\"{.spec.clusterIP}\"\n").out val apple = cmd("curl -m 30 $host/apple").out
val port = cmd(kubeCtlCmd + " get svc apple-service -o jsonpath=\"{.spec.ports[0].port}\"\n").out if ("apple" == apple?.trim()) {
if (ip == null || port == null) { addResultToEval(ProvResult(true))
return@task ProvResult(false)
}
val apple = cmd("curl -m 30 $ip:$port").out
if ("apple" == apple) {
ProvResult(true)
} else { } else {
ProvResult(false, err = "Apple service did not return \"apple\" but instead: " + apple) addResultToEval(ProvResult(false, err = "Apple service did not return \"apple\" but instead: " + apple))
} }
} }
fun appleConfig() = fun appleConfig() =
""" """
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: apple-ingress
annotations:
kubernetes.io/ingress.class: "traefik"
spec:
rules:
- http:
paths:
- path: /apple
pathType: Prefix
backend:
service:
name: apple-service
port:
number: 5678
---
kind: Pod kind: Pod
apiVersion: v1 apiVersion: v1
metadata: metadata:
@ -33,7 +47,6 @@ spec:
image: hashicorp/http-echo image: hashicorp/http-echo
args: args:
- "-text=apple" - "-text=apple"
--- ---
kind: Service kind: Service