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

e2e: add emojivotodemo #301

Closed
wants to merge 12 commits into from
2 changes: 2 additions & 0 deletions e2e/internal/kuberesource/resourcegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func main() {
resources, err = kuberesource.OpenSSL()
case "emojivoto":
resources, err = kuberesource.Emojivoto()
case "emojivotodemo":
resources, err = kuberesource.EmojivotoDemo()
default:
fmt.Printf("Error: unknown set: %s\n", set)
os.Exit(1)
Expand Down
311 changes: 311 additions & 0 deletions e2e/internal/kuberesource/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,314 @@ func Emojivoto() ([]any, error) {

return resources, nil
}

// EmojivotoDemo is a simplified version of Emojivoto returning resources for deploying a demo.
func EmojivotoDemo() ([]any, error) {
wirungu marked this conversation as resolved.
Show resolved Hide resolved
ns := "default"
emoji := Deployment("emoji", ns).
WithLabels(map[string]string{
"app.kubernetes.io/name": "emoji",
"app.kubernetes.io/part-of": "emojivoto",
"app.kubernetes.io/version": "v11",
}).
WithSpec(DeploymentSpec().
WithReplicas(1).
WithSelector(LabelSelector().
WithMatchLabels(map[string]string{
"app.kubernetes.io/name": "emoji-svc",
"version": "v11",
}),
).
WithTemplate(PodTemplateSpec().
WithLabels(map[string]string{
"app.kubernetes.io/name": "emoji-svc",
"version": "v11",
}).
WithSpec(PodSpec().
WithRuntimeClassName("kata-cc-isolation").
WithServiceAccountName("emoji").
WithContainers(
Container().
WithName("emoji-svc").
WithImage("ghcr.io/3u13r/emojivoto-emoji-svc:coco-1").
WithPorts(
ContainerPort().
WithName("grpc").
WithContainerPort(8080),
ContainerPort().
WithName("prom").
WithContainerPort(8801),
).
WithEnv(EnvVar().WithName("GRPC_PORT").WithValue("8080")).
WithEnv(EnvVar().WithName("PROM_PORT").WithValue("8801")).
WithEnv(EnvVar().WithName("EDG_CERT_PATH").WithValue("/tls-config/certChain.pem")).
WithEnv(EnvVar().WithName("EDG_CA_PATH").WithValue("/tls-config/MeshCACert.pem")).
WithEnv(EnvVar().WithName("EDG_KEY_PATH").WithValue("/tls-config/key.pem")).
WithResources(ResourceRequirements().
WithMemoryLimitAndRequest(50),
),
),
),
),
)
emoji, err := AddInitializer(emoji, Initializer().WithImage("ghcr.io/3u13r/contrast/initializer@sha256:3f0e76ffd1c62af460d2a7407ca0ab13cd49b3f07a00d5ef5bd636bcb6d8381f"))
if err != nil {
return nil, err
}

emojiService := ServiceForDeployment(emoji).
WithName("emoji-svc").
WithSpec(ServiceSpec().
WithSelector(
map[string]string{"app.kubernetes.io/name": "emoji-svc"},
).
WithPorts(
ServicePort().
WithName("grpc").
WithPort(8080).
WithTargetPort(intstr.FromInt(8080)),
ServicePort().
WithName("prom").
WithPort(8801).
WithTargetPort(intstr.FromInt(8801)),
),
)

emojiserviceAccount := ServiceAccount("emoji", ns).
WithAPIVersion("v1").
WithKind("ServiceAccount")

voteBot := Deployment("vote-bot", ns).
WithLabels(map[string]string{
"app.kubernetes.io/name": "vote-bot",
"app.kubernetes.io/part-of": "emojivoto",
"app.kubernetes.io/version": "v11",
}).
WithSpec(DeploymentSpec().
WithReplicas(1).
WithSelector(LabelSelector().
WithMatchLabels(map[string]string{
"app.kubernetes.io/name": "vote-bot",
"version": "v11",
}),
).
WithTemplate(PodTemplateSpec().
WithLabels(map[string]string{
"app.kubernetes.io/name": "vote-bot",
"version": "v11",
}).
WithSpec(PodSpec().
WithContainers(
Container().
WithName("vote-bot").
WithImage("ghcr.io/3u13r/emojivoto-web:coco-1").
WithCommand("emojivoto-vote-bot").
WithEnv(EnvVar().WithName("WEB_HOST").WithValue("web-svc:443")).
WithResources(ResourceRequirements().
WithMemoryLimitAndRequest(25),
),
),
),
),
)

voting := Deployment("voting", ns).
WithLabels(map[string]string{
"app.kubernetes.io/name": "voting",
"app.kubernetes.io/part-of": "emojivoto",
"app.kubernetes.io/version": "v11",
}).
WithSpec(DeploymentSpec().
WithReplicas(1).
WithSelector(LabelSelector().
WithMatchLabels(map[string]string{
"app.kubernetes.io/name": "voting-svc",
"version": "v11",
}),
).
WithTemplate(PodTemplateSpec().
WithLabels(map[string]string{
"app.kubernetes.io/name": "voting-svc",
"version": "v11",
}).
WithSpec(PodSpec().
WithRuntimeClassName("kata-cc-isolation").
WithServiceAccountName("voting").
WithContainers(
Container().
WithName("voting-svc").
WithImage("ghcr.io/3u13r/emojivoto-voting-svc:coco-1").
WithPorts(
ContainerPort().
WithName("grpc").
WithContainerPort(8080),
ContainerPort().
WithName("prom").
WithContainerPort(8801),
).
WithEnv(EnvVar().WithName("GRPC_PORT").WithValue("8080")).
WithEnv(EnvVar().WithName("PROM_PORT").WithValue("8801")).
WithEnv(EnvVar().WithName("EDG_CERT_PATH").WithValue("/tls-config/certChain.pem")).
WithEnv(EnvVar().WithName("EDG_CA_PATH").WithValue("/tls-config/MeshCACert.pem")).
WithEnv(EnvVar().WithName("EDG_KEY_PATH").WithValue("/tls-config/key.pem")).
WithResources(ResourceRequirements().
WithMemoryLimitAndRequest(50),
),
),
),
),
)
voting, err = AddInitializer(voting, Initializer().WithImage("ghcr.io/3u13r/contrast/initializer@sha256:3f0e76ffd1c62af460d2a7407ca0ab13cd49b3f07a00d5ef5bd636bcb6d8381f"))
if err != nil {
return nil, err
}

votingService := ServiceForDeployment(voting).
WithName("voting-svc").
WithSpec(ServiceSpec().
WithSelector(
map[string]string{"app.kubernetes.io/name": "voting-svc"},
).
WithPorts(
ServicePort().
WithName("grpc").
WithPort(8080).
WithTargetPort(intstr.FromInt(8080)),
ServicePort().
WithName("prom").
WithPort(8801).
WithTargetPort(intstr.FromInt(8801)),
),
)

votingserviceAccount := ServiceAccount("voting", ns).
WithAPIVersion("v1").
WithKind("ServiceAccount")

web := Deployment("web", ns).
WithLabels(map[string]string{
"app.kubernetes.io/name": "web",
"app.kubernetes.io/part-of": "emojivoto",
"app.kubernetes.io/version": "v11",
}).
WithSpec(DeploymentSpec().
WithReplicas(1).
WithSelector(LabelSelector().
WithMatchLabels(map[string]string{
"app.kubernetes.io/name": "web-svc",
"version": "v11",
}),
).
WithTemplate(PodTemplateSpec().
WithLabels(map[string]string{
"app.kubernetes.io/name": "web-svc",
"version": "v11",
}).
WithSpec(PodSpec().
WithRuntimeClassName("kata-cc-isolation").
WithServiceAccountName("web").
WithContainers(
Container().
WithName("web-svc").
WithImage("ghcr.io/3u13r/emojivoto-web:coco-1").
WithPorts(
ContainerPort().
WithName("https").
WithContainerPort(8080),
).
WithEnv(EnvVar().WithName("WEB_PORT").WithValue("8080")).
WithEnv(EnvVar().WithName("EMOJISVC_HOST").WithValue("emoji-svc:8080")).
WithEnv(EnvVar().WithName("VOTINGSVC_HOST").WithValue("voting-svc:8080")).
WithEnv(EnvVar().WithName("INDEX_BUNDLE").WithValue("dist/index_bundle.js")).
WithEnv(EnvVar().WithName("EDG_CERT_PATH").WithValue("/tls-config/certChain.pem")).
WithEnv(EnvVar().WithName("EDG_CA_PATH").WithValue("/tls-config/MeshCACert.pem")).
WithEnv(EnvVar().WithName("EDG_KEY_PATH").WithValue("/tls-config/key.pem")).
WithEnv(EnvVar().WithName("EDG_DISABLE_CLIENT_AUTH").WithValue("true")).
WithResources(ResourceRequirements().
WithMemoryLimitAndRequest(50),
),
),
),
),
)
web, err = AddInitializer(web, Initializer().WithImage("ghcr.io/3u13r/contrast/initializer@sha256:3f0e76ffd1c62af460d2a7407ca0ab13cd49b3f07a00d5ef5bd636bcb6d8381f"))
if err != nil {
return nil, err
}

webService := ServiceForDeployment(web).
WithName("web-svc").
WithSpec(ServiceSpec().
WithSelector(
map[string]string{"app.kubernetes.io/name": "web-svc"},
).
WithType("ClusterIP").
WithPorts(
ServicePort().
WithName("https").
WithPort(443).
WithTargetPort(intstr.FromInt(8080)),
),
)

webserviceAccount := ServiceAccount("web", ns).
WithAPIVersion("v1").
WithKind("ServiceAccount")

portforwarderCoordinator := PortForwarder("coordinator", ns).
WithSpec(PodSpec().
WithContainers(
Container().
WithName("port-forwarder").
WithImage("ghcr.io/3u13r/contrast/port-forwarder@sha256:00b02378ceb33df7db46a0b6b56fd7fe1e7b2e7dade0404957f16235c01e80e0").
WithEnv(EnvVar().WithName("LISTEN_PORT").WithValue("1313")).
WithEnv(EnvVar().WithName("FORWARD_HOST").WithValue("coordinator")).
WithEnv(EnvVar().WithName("FORWARD_PORT").WithValue("1313")).
WithCommand("/bin/bash", "-c", "echo Starting port-forward with socat; exec socat -d -d TCP-LISTEN:${LISTEN_PORT},fork TCP:${FORWARD_HOST}:${FORWARD_PORT}").
WithPorts(
ContainerPort().
WithContainerPort(1313),
).
WithResources(ResourceRequirements().
WithMemoryLimitAndRequest(50),
),
),
)

portforwarderemojivotoWeb := PortForwarder("emojivoto-web", ns).
WithSpec(PodSpec().
WithContainers(
Container().
WithName("port-forwarder").
WithImage("ghcr.io/3u13r/contrast/port-forwarder@sha256:00b02378ceb33df7db46a0b6b56fd7fe1e7b2e7dade0404957f16235c01e80e0").
WithEnv(EnvVar().WithName("LISTEN_PORT").WithValue("8080")).
WithEnv(EnvVar().WithName("FORWARD_HOST").WithValue("web-svc")).
WithEnv(EnvVar().WithName("FORWARD_PORT").WithValue("443")).
WithCommand("/bin/bash", "-c", "echo Starting port-forward with socat; exec socat -d -d TCP-LISTEN:${LISTEN_PORT},fork TCP:${FORWARD_HOST}:${FORWARD_PORT}").
WithPorts(
ContainerPort().
WithContainerPort(8080),
).
WithResources(ResourceRequirements().
WithMemoryLimitAndRequest(50),
),
),
)

resources := []any{
emoji,
emojiService,
emojiserviceAccount,
portforwarderCoordinator,
portforwarderemojivotoWeb,
voteBot,
voting,
votingService,
votingserviceAccount,
web,
webService,
webserviceAccount,
}

return resources, nil
}
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ populate target=default_deploy_target:
set -euo pipefail
mkdir -p ./{{ workspace_dir }}
case {{ target }} in
"simple" | "openssl" | "emojivoto")
"simple" | "openssl" | "emojivoto" | "emojivotodemo")
wirungu marked this conversation as resolved.
Show resolved Hide resolved
nix shell .#contrast --command resourcegen {{ target }} ./{{ workspace_dir }}/deployment/deployment.yml
;;
*)
Expand Down Expand Up @@ -67,7 +67,7 @@ generate cli=default_cli:
apply target=default_deploy_target:
#!/usr/bin/env bash
case {{ target }} in
"simple" | "openssl" | "emojivoto")
"simple" | "openssl" | "emojivoto" | "emojivotodemo")
:
;;
*)
Expand Down Expand Up @@ -157,7 +157,7 @@ wait-for-workload target=default_deploy_target:
nix run .#scripts.kubectl-wait-ready -- $ns openssl-client
nix run .#scripts.kubectl-wait-ready -- $ns openssl-frontend
;;
"emojivoto" | "emojivoto-sm-egress")
"emojivoto" | "emojivoto-sm-egress" | "emojivotodemo")
nix run .#scripts.kubectl-wait-ready -- $ns emoji-svc
nix run .#scripts.kubectl-wait-ready -- $ns vote-bot
nix run .#scripts.kubectl-wait-ready -- $ns voting-svc
Expand Down
Loading