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
142 changes: 100 additions & 42 deletions e2e/internal/kuberesource/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,25 @@ func OpenSSL() ([]any, error) {
return resources, nil
}

// Emojivoto returns resources for deploying EmojiVoto application.
func Emojivoto() ([]any, error) {
ns := "edg-default"
// GenerateEmojivoto returns resources for deploying EmojiVoto application with custom images.
func GenerateEmojivoto(ns string, emojiImage, initializerImage, portforwarderImage, votingImage, webImage string, generateCoordinatorService bool) ([]any, error) {
resources := make([]any, 0)
wirungu marked this conversation as resolved.
Show resolved Hide resolved

if ns == "" {
ns = "edg-default"
}

namespace := Namespace(ns)
coordinator := Coordinator(ns).DeploymentApplyConfiguration
coordinatorService := ServiceForDeployment(coordinator)
coordinatorForwarder := PortForwarder("coordinator", ns).
WithListenPort(1313).
WithForwardTarget("coordinator", 1313).
PodApplyConfiguration

if generateCoordinatorService {
coordinator := Coordinator(ns).DeploymentApplyConfiguration
coordinatorService := ServiceForDeployment(coordinator)
coordinatorForwarder := PortForwarder("coordinator", ns).
WithListenPort(1313).
WithForwardTarget("coordinator", 1313).
PodApplyConfiguration
resources = append(resources, namespace, coordinator, coordinatorService, coordinatorForwarder)
}

emoji := Deployment("emoji", ns).
WithLabels(map[string]string{
Expand All @@ -234,7 +243,7 @@ func Emojivoto() ([]any, error) {
WithContainers(
Container().
WithName("emoji-svc").
WithImage("ghcr.io/3u13r/emojivoto-emoji-svc:coco-1").
WithImage(emojiImage).
WithPorts(
ContainerPort().
WithName("grpc").
Expand All @@ -255,10 +264,11 @@ func Emojivoto() ([]any, error) {
),
),
)
emoji, err := AddInitializer(emoji, Initializer())
emoji, err := AddInitializer(emoji, Initializer().WithImage(initializerImage))
if err != nil {
return nil, err
}
resources = append(resources, emoji)

emojiService := ServiceForDeployment(emoji).
WithName("emoji-svc").
Expand All @@ -277,10 +287,12 @@ func Emojivoto() ([]any, error) {
WithTargetPort(intstr.FromInt(8801)),
),
)
resources = append(resources, emojiService)

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

voteBot := Deployment("vote-bot", ns).
WithLabels(map[string]string{
Expand All @@ -305,7 +317,7 @@ func Emojivoto() ([]any, error) {
WithContainers(
Container().
WithName("vote-bot").
WithImage("ghcr.io/3u13r/emojivoto-web:coco-1").
WithImage(webImage).
WithCommand("emojivoto-vote-bot").
WithEnv(EnvVar().WithName("WEB_HOST").WithValue("web-svc:443")).
WithResources(ResourceRequirements().
Expand All @@ -315,6 +327,7 @@ func Emojivoto() ([]any, error) {
),
),
)
resources = append(resources, voteBot)

voting := Deployment("voting", ns).
WithLabels(map[string]string{
Expand All @@ -341,7 +354,7 @@ func Emojivoto() ([]any, error) {
WithContainers(
Container().
WithName("voting-svc").
WithImage("ghcr.io/3u13r/emojivoto-voting-svc:coco-1").
WithImage(votingImage).
WithPorts(
ContainerPort().
WithName("grpc").
Expand All @@ -362,10 +375,11 @@ func Emojivoto() ([]any, error) {
),
),
)
voting, err = AddInitializer(voting, Initializer())
voting, err = AddInitializer(voting, Initializer().WithImage(initializerImage))
if err != nil {
return nil, err
}
resources = append(resources, voting)

votingService := ServiceForDeployment(voting).
WithName("voting-svc").
Expand All @@ -384,10 +398,12 @@ func Emojivoto() ([]any, error) {
WithTargetPort(intstr.FromInt(8801)),
),
)
resources = append(resources, votingService)

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

web := Deployment("web", ns).
WithLabels(map[string]string{
Expand All @@ -414,7 +430,7 @@ func Emojivoto() ([]any, error) {
WithContainers(
Container().
WithName("web-svc").
WithImage("ghcr.io/3u13r/emojivoto-web:coco-1").
WithImage(webImage).
WithPorts(
ContainerPort().
WithName("https").
Expand All @@ -435,10 +451,11 @@ func Emojivoto() ([]any, error) {
),
),
)
web, err = AddInitializer(web, Initializer())
web, err = AddInitializer(web, Initializer().WithImage(initializerImage))
if err != nil {
return nil, err
}
resources = append(resources, web)

webService := ServiceForDeployment(web).
WithName("web-svc").
Expand All @@ -454,39 +471,80 @@ func Emojivoto() ([]any, error) {
WithTargetPort(intstr.FromInt(8080)),
),
)
resources = append(resources, webService)

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

portforwarderCoordinator := PortForwarder("coordinator", ns).
WithListenPort(1313).
WithForwardTarget("coordinator", 1313).
PodApplyConfiguration
WithSpec(PodSpec().
WithContainers(
Container().
WithName("port-forwarder").
WithImage(portforwarderImage).
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),
),
),
)
wirungu marked this conversation as resolved.
Show resolved Hide resolved
resources = append(resources, portforwarderCoordinator)

portforwarderWeb := PortForwarder("emojivoto-web", ns).
WithSpec(PodSpec().
WithContainers(
Container().
WithName("port-forwarder").
WithImage(portforwarderImage).
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 = append(resources, portforwarderWeb)

portforwarderemojivotoWeb := PortForwarder("emojivoto-web", ns).
WithListenPort(8080).
WithForwardTarget("web-svc", 443).
PodApplyConfiguration
return resources, nil
}

resources := []any{
namespace,
coordinator,
coordinatorService,
coordinatorForwarder,
emoji,
emojiService,
emojiserviceAccount,
portforwarderCoordinator,
portforwarderemojivotoWeb,
voteBot,
voting,
votingService,
votingserviceAccount,
web,
webService,
webserviceAccount,
}
// Emojivoto returns resources for deploying EmojiVoto application.
func Emojivoto() ([]any, error) {
return GenerateEmojivoto(
"edg-default",
"ghcr.io/3u13r/emojivoto-emoji-svc:coco-1",
"ghcr.io/edgelesssys/contrast/initializer:latest",
"ghcr.io/edgelesssys/contrast/port-forwarder:latest",
"ghcr.io/3u13r/emojivoto-voting-svc:coco-1",
"ghcr.io/3u13r/emojivoto-web:coco-1",
true,
wirungu marked this conversation as resolved.
Show resolved Hide resolved
)
}

return resources, nil
// EmojivotoDemo returns resources for deploying a simple EmojiVoto demo.
func EmojivotoDemo() ([]any, error) {
return GenerateEmojivoto(
"default",
"ghcr.io/3u13r/emojivoto-emoji-svc:coco-1",
"ghcr.io/3u13r/contrast/initializer@sha256:3f0e76ffd1c62af460d2a7407ca0ab13cd49b3f07a00d5ef5bd636bcb6d8381f",
"ghcr.io/3u13r/contrast/port-forwarder@sha256:00b02378ceb33df7db46a0b6b56fd7fe1e7b2e7dade0404957f16235c01e80e0",
"ghcr.io/3u13r/emojivoto-voting-svc:coco-1",
"ghcr.io/3u13r/emojivoto-web:coco-1",
false,
)
wirungu marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
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