feat(k8s): specify app protocol for worker and app services

Signed-off-by: Pascal Sthamer <10992664+P4sca1@users.noreply.github.com>
This commit is contained in:
Pascal Sthamer
2025-10-15 10:43:45 +02:00
parent 39c7b1e7d0
commit 68efb7111a
2 changed files with 27 additions and 31 deletions
+5 -3
View File
@@ -1395,6 +1395,7 @@ func deployK8sWorker(image string, identifier string, env []string) error {
return err return err
} }
svcAppProtocol := "http"
service := &corev1.Service{ service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: identifier, Name: identifier,
@@ -1404,9 +1405,10 @@ func deployK8sWorker(image string, identifier string, env []string) error {
Selector: matchLabels, Selector: matchLabels,
Ports: []corev1.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: "TCP", Protocol: "TCP",
Port: 33333, AppProtocol: &svcAppProtocol,
TargetPort: intstr.FromInt(33333), Port: 33333,
TargetPort: intstr.FromInt(33333),
}, },
}, },
Type: corev1.ServiceTypeClusterIP, Type: corev1.ServiceTypeClusterIP,
+22 -28
View File
@@ -2,7 +2,7 @@ package main
import ( import (
"github.com/shuffle/shuffle-shared" "github.com/shuffle/shuffle-shared"
"github.com/shuffle/singul/pkg" singul "github.com/shuffle/singul/pkg"
"bytes" "bytes"
"context" "context"
@@ -678,6 +678,7 @@ func deployk8sApp(image string, identifier string, env []string) error {
return err return err
} }
svcAppProtocol := "http"
service := &corev1.Service{ service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
@@ -687,9 +688,10 @@ func deployk8sApp(image string, identifier string, env []string) error {
Selector: matchLabels, Selector: matchLabels,
Ports: []corev1.ServicePort{ Ports: []corev1.ServicePort{
{ {
Protocol: "TCP", Protocol: "TCP",
Port: 80, AppProtocol: &svcAppProtocol,
TargetPort: intstr.FromInt(deployport), Port: 80,
TargetPort: intstr.FromInt(deployport),
}, },
}, },
Type: corev1.ServiceTypeClusterIP, Type: corev1.ServiceTypeClusterIP,
@@ -3233,8 +3235,6 @@ func deploySwarmService(dockercli *dockerclient.Client, name, image string, depl
log.Printf("[DEBUG] Deploying service for %s to swarm on port %d", name, deployport) log.Printf("[DEBUG] Deploying service for %s to swarm on port %d", name, deployport)
//containerName := fmt.Sprintf("shuffle-worker-%s", parsedUuid) //containerName := fmt.Sprintf("shuffle-worker-%s", parsedUuid)
// Check if the image exists or not - just in case // Check if the image exists or not - just in case
_, _, err := dockercli.ImageInspectWithRaw(context.Background(), image) _, _, err := dockercli.ImageInspectWithRaw(context.Background(), image)
if err != nil { if err != nil {
@@ -3247,8 +3247,8 @@ func deploySwarmService(dockercli *dockerclient.Client, name, image string, depl
} }
_, err := dockercli.ImagePull( _, err := dockercli.ImagePull(
context.Background(), context.Background(),
image, image,
dockerimage.PullOptions{}, dockerimage.PullOptions{},
) )
if err != nil { if err != nil {
@@ -3257,7 +3257,6 @@ func deploySwarmService(dockercli *dockerclient.Client, name, image string, depl
} }
} }
if len(baseimagename) == 0 || baseimagename == "/" { if len(baseimagename) == 0 || baseimagename == "/" {
baseimagename = "frikky/shuffle" baseimagename = "frikky/shuffle"
//var baseimagename = "frikky/shuffle" //var baseimagename = "frikky/shuffle"
@@ -3290,7 +3289,7 @@ func deploySwarmService(dockercli *dockerclient.Client, name, image string, depl
// Max scale as well // Max scale as well
nodeCount := uint64(1) nodeCount := uint64(1)
if inputReplicas > 0 && inputReplicas < 100 { if inputReplicas > 0 && inputReplicas < 100 {
if replicas != uint64(inputReplicas) { if replicas != uint64(inputReplicas) {
log.Printf("[DEBUG] Overwriting replicas to %d/node as inputReplicas is set to %d", inputReplicas, inputReplicas) log.Printf("[DEBUG] Overwriting replicas to %d/node as inputReplicas is set to %d", inputReplicas, inputReplicas)
} }
@@ -3310,7 +3309,6 @@ func deploySwarmService(dockercli *dockerclient.Client, name, image string, depl
nodeCount = 1 nodeCount = 1
} }
replicatedJobs := uint64(replicas * nodeCount) replicatedJobs := uint64(replicas * nodeCount)
log.Printf("[DEBUG] Deploying app with name %s with image %s", name, image) log.Printf("[DEBUG] Deploying app with name %s with image %s", name, image)
@@ -3440,12 +3438,12 @@ func deploySwarmService(dockercli *dockerclient.Client, name, image string, depl
} }
// Retry deploying the service (once) // Retry deploying the service (once)
if !retry { if !retry {
return deploySwarmService(dockercli, name, image, deployport, -1, true) return deploySwarmService(dockercli, name, image, deployport, -1, true)
} }
} }
// For port mapping. // For port mapping.
if strings.Contains(fmt.Sprintf("%s", err), "InvalidArgument") && strings.Contains(fmt.Sprintf("%s", err), "is already in use") { if strings.Contains(fmt.Sprintf("%s", err), "InvalidArgument") && strings.Contains(fmt.Sprintf("%s", err), "is already in use") {
//log.Printf("\n\n[WARNING] Port %d is already allocated. Trying to deploy on next port.\n\n", deployport) //log.Printf("\n\n[WARNING] Port %d is already allocated. Trying to deploy on next port.\n\n", deployport)
@@ -3472,7 +3470,6 @@ func findAppInfo(image, name string, redeploy bool) (int, error) {
// chance of being successful // chance of being successful
time.Sleep(time.Duration(rand.Intn(1500)) * time.Millisecond) time.Sleep(time.Duration(rand.Intn(1500)) * time.Millisecond)
highest := baseport highest := baseport
exposedPort := -1 exposedPort := -1
@@ -3576,10 +3573,10 @@ func findAppInfo(image, name string, redeploy bool) (int, error) {
time.Sleep(time.Duration(rand.Intn(4)+8) * time.Second) time.Sleep(time.Duration(rand.Intn(4)+8) * time.Second)
replicas := service.Spec.Mode.Replicated.Replicas replicas := service.Spec.Mode.Replicated.Replicas
err = deploySwarmService( err = deploySwarmService(
dockercli, dockercli,
name, name,
image, image,
exposedPort, exposedPort,
int64(*replicas), int64(*replicas),
false, false,
) )
@@ -3669,7 +3666,7 @@ func findAppInfoKubernetes(image, name string, env []string) error {
for _, deployment := range deployments.Items { for _, deployment := range deployments.Items {
if deployment.Name == name { if deployment.Name == name {
if debug { if debug {
log.Printf("[DEBUG] Found deployment %s - no need to deploy another", name) log.Printf("[DEBUG] Found deployment %s - no need to deploy another", name)
} }
@@ -3695,7 +3692,6 @@ func initSwarmNetwork() error {
mtu := 1500 mtu := 1500
options["com.docker.network.driver.mtu"] = fmt.Sprintf("%d", mtu) options["com.docker.network.driver.mtu"] = fmt.Sprintf("%d", mtu)
ingressOptions := network.CreateOptions{ ingressOptions := network.CreateOptions{
Driver: "overlay", Driver: "overlay",
Attachable: false, Attachable: false,
@@ -3779,11 +3775,9 @@ func initSwarmNetwork() error {
log.Printf("[WARNING] Swarm Executions network may already exist: %s", err) log.Printf("[WARNING] Swarm Executions network may already exist: %s", err)
} }
return nil return nil
} }
/*** ENDREMOVE ***/ /*** ENDREMOVE ***/
func sendAppRequest(ctx context.Context, incomingUrl, appName string, port int, action *shuffle.Action, workflowExecution *shuffle.WorkflowExecution, image string, attempts int64) error { func sendAppRequest(ctx context.Context, incomingUrl, appName string, port int, action *shuffle.Action, workflowExecution *shuffle.WorkflowExecution, image string, attempts int64) error {
@@ -3940,9 +3934,9 @@ func sendAppRequest(ctx context.Context, incomingUrl, appName string, port int,
} }
// Try redeployment // Try redeployment
attempts += 1 attempts += 1
if attempts < 2 { if attempts < 2 {
// Check the service and fix it. // Check the service and fix it.
if isKubernetes == "true" { if isKubernetes == "true" {
log.Printf("[WARNING] App Redeployment in K8s isn't fully supported yet, but should be done for app %s with image %s.", appName, image) log.Printf("[WARNING] App Redeployment in K8s isn't fully supported yet, but should be done for app %s with image %s.", appName, image)
} else { } else {
@@ -3951,7 +3945,7 @@ func sendAppRequest(ctx context.Context, incomingUrl, appName string, port int,
log.Printf("[ERROR][%s] Error re-deploying app %s: %s", workflowExecution.ExecutionId, appName, err) log.Printf("[ERROR][%s] Error re-deploying app %s: %s", workflowExecution.ExecutionId, appName, err)
} }
return sendAppRequest(ctx, incomingUrl, appName, port, action, workflowExecution, image, attempts) return sendAppRequest(ctx, incomingUrl, appName, port, action, workflowExecution, image, attempts)
} }
} }
@@ -4377,7 +4371,7 @@ func checkStandaloneRun() {
// Initial loop etc // Initial loop etc
func main() { func main() {
// Testing swarm auto-replacements. This also tests ports // Testing swarm auto-replacements. This also tests ports
// in rapid succession // in rapid succession
checkStandaloneRun() checkStandaloneRun()
@@ -4385,7 +4379,7 @@ func main() {
debug = true debug = true
log.Printf("[INFO] Disabled cleanup due to debug mode (DEBUG=true)") log.Printf("[INFO] Disabled cleanup due to debug mode (DEBUG=true)")
cleanupEnv = "false" cleanupEnv = "false"
} }
/*** STARTREMOVE ***/ /*** STARTREMOVE ***/