Skip to content

Commit

Permalink
e2e: add emojivoto to resourcegen
Browse files Browse the repository at this point in the history
e2e: added ServiceAccountConfig wrapper

e2e: added function generating emojivoto

e2e: added emojivoto to resourcegen main

justfile: added emojivoto target

e2e: fixed emojivoto services

justfile: added emojivoto target
  • Loading branch information
wirungu committed Apr 4, 2024
1 parent 1809d26 commit e697352
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 2 deletions.
2 changes: 2 additions & 0 deletions e2e/internal/kuberesource/resourcegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func main() {
resources, err = kuberesource.Simple()
case "openssl":
resources, err = kuberesource.OpenSSL()
case "emojivoto":
resources, err = kuberesource.Emojivoto()
default:
fmt.Printf("Error: unknown set: %s\n", set)
os.Exit(1)
Expand Down
293 changes: 293 additions & 0 deletions e2e/internal/kuberesource/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,296 @@ func OpenSSL() ([]any, error) {

return resources, nil
}

// Emojivoto returns resources for deploying EmojiVoto application.
func Emojivoto() ([]any, error) {
ns := "edg-default"
namespace := Namespace(ns)
coordinator := Coordinator(ns).DeploymentApplyConfiguration
coordinatorService := ServiceForDeployment(coordinator)
coordinatorForwarder := PortForwarder("coordinator", ns).
WithListenPort(1313).
WithForwardTarget("coordinator", 1313).
PodApplyConfiguration

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())
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())
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())
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).
WithListenPort(1313).
WithForwardTarget("coordinator", 1313).
PodApplyConfiguration

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

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

return resources, nil
}
10 changes: 10 additions & 0 deletions e2e/internal/kuberesource/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ func ServicePort() *ServicePortConfig {
return &ServicePortConfig{applycorev1.ServicePort()}
}

// ServiceAccountConfig wraps applycorev1.ServiceAccountApplyConfiguration.
type ServiceAccountConfig struct {
*applycorev1.ServiceAccountApplyConfiguration
}

// ServiceAccount creates a new ServiceAccountConfig.
func ServiceAccount(name, namespace string) *ServiceAccountConfig {
return &ServiceAccountConfig{applycorev1.ServiceAccount(name, namespace)}
}

// NamespaceConfig wraps applycorev1.NamespaceApplyConfiguration.
type NamespaceConfig struct {
*applycorev1.NamespaceApplyConfiguration
Expand Down
4 changes: 2 additions & 2 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")
"simple" | "openssl" | "emojivoto")
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")
"simple" | "openssl" | "emojivoto")
:
;;
*)
Expand Down

0 comments on commit e697352

Please sign in to comment.