feat(k8s): allow to change exposed app port

Signed-off-by: Pascal Sthamer <10992664+P4sca1@users.noreply.github.com>
This commit is contained in:
Pascal Sthamer
2025-04-16 11:34:41 +02:00
parent 319c939c1f
commit 3491ba6471
2 changed files with 32 additions and 23 deletions
+5 -2
View File
@@ -747,7 +747,7 @@ func handleBackendImageDownload(ctx context.Context, images string) error {
//log.Printf("[DEBUG] Removing existing image (s): %s", images) //log.Printf("[DEBUG] Removing existing image (s): %s", images)
newImages := []string{} newImages := []string{}
successful := []string{} successful := []string{}
for _, curimage := range strings.Split(images, ",") { for _, curimage := range strings.Split(images, ",") {
curimage = strings.TrimSpace(curimage) curimage = strings.TrimSpace(curimage)
if shuffle.ArrayContains(handled, curimage) { if shuffle.ArrayContains(handled, curimage) {
@@ -996,6 +996,10 @@ func deployK8sWorker(image string, identifier string, env []string) error {
env = append(env, fmt.Sprintf("SHUFFLE_USE_GHCR_OVERRIDE_FOR_AUTODEPLOY=%s", os.Getenv("SHUFFLE_USE_GHCR_OVERRIDE_FOR_AUTODEPLOY"))) env = append(env, fmt.Sprintf("SHUFFLE_USE_GHCR_OVERRIDE_FOR_AUTODEPLOY=%s", os.Getenv("SHUFFLE_USE_GHCR_OVERRIDE_FOR_AUTODEPLOY")))
} }
if len(os.Getenv("SHUFFLE_APP_EXPOSED_PORT")) > 0 {
env = append(env, fmt.Sprintf("SHUFFLE_APP_EXPOSED_PORT=%s", os.Getenv("SHUFFLE_APP_EXPOSED_PORT")))
}
if len(appServiceAccountName) > 0 { if len(appServiceAccountName) > 0 {
env = append(env, fmt.Sprintf("SHUFFLE_APP_SERVICE_ACCOUNT_NAME=%s", appServiceAccountName)) env = append(env, fmt.Sprintf("SHUFFLE_APP_SERVICE_ACCOUNT_NAME=%s", appServiceAccountName))
} }
@@ -1271,7 +1275,6 @@ func deployWorker(image string, identifier string, env []string, executionReques
Resources: container.Resources{}, Resources: container.Resources{},
} }
// This is just to test the mounting locally so // This is just to test the mounting locally so
// I can control from what source I'm mounting // I can control from what source I'm mounting
// the certs to. Default behaviour is: // the certs to. Default behaviour is:
+27 -21
View File
@@ -399,6 +399,11 @@ func deployk8sApp(image string, identifier string, env []string) error {
kubernetesNamespace = "default" kubernetesNamespace = "default"
} }
deployport, err := strconv.Atoi(os.Getenv("SHUFFLE_APP_EXPOSED_PORT"))
if err != nil {
deployport = 80
}
envMap := make(map[string]string) envMap := make(map[string]string)
for _, envStr := range env { for _, envStr := range env {
parts := strings.SplitN(envStr, "=", 2) parts := strings.SplitN(envStr, "=", 2)
@@ -408,9 +413,7 @@ func deployk8sApp(image string, identifier string, env []string) error {
} }
// add to env // add to env
// fmt.Sprintf("SHUFFLE_APP_EXPOSED_PORT=%d", deployport), envMap["SHUFFLE_APP_EXPOSED_PORT"] = strconv.Itoa(deployport)
// fmt.Sprintf("SHUFFLE_SWARM_CONFIG=%s", os.Getenv("SHUFFLE_SWARM_CONFIG")),
envMap["SHUFFLE_APP_EXPOSED_PORT"] = "80"
envMap["SHUFFLE_SWARM_CONFIG"] = os.Getenv("SHUFFLE_SWARM_CONFIG") envMap["SHUFFLE_SWARM_CONFIG"] = os.Getenv("SHUFFLE_SWARM_CONFIG")
envMap["BASE_URL"] = "http://shuffle-workers:33333" envMap["BASE_URL"] = "http://shuffle-workers:33333"
@@ -599,6 +602,12 @@ func deployk8sApp(image string, identifier string, env []string) error {
Name: value, Name: value,
Image: image, Image: image,
Env: buildEnvVars(envMap), Env: buildEnvVars(envMap),
Ports: []corev1.ContainerPort{
{
Protocol: "TCP",
ContainerPort: int32(deployport),
},
},
}, },
}, },
DNSPolicy: corev1.DNSClusterFirst, DNSPolicy: corev1.DNSClusterFirst,
@@ -614,7 +623,6 @@ func deployk8sApp(image string, identifier string, env []string) error {
return err return err
} }
// kubectl expose deployment {podName} --type=NodePort --port=80 --target-port=80
service := &corev1.Service{ service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: name, Name: name,
@@ -626,7 +634,7 @@ func deployk8sApp(image string, identifier string, env []string) error {
{ {
Protocol: "TCP", Protocol: "TCP",
Port: 80, Port: 80,
TargetPort: intstr.FromInt(80), TargetPort: intstr.FromInt(deployport),
}, },
}, },
Type: corev1.ServiceTypeNodePort, Type: corev1.ServiceTypeNodePort,
@@ -917,7 +925,7 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
// Add more volume binds if possible // Add more volume binds if possible
if len(volumeBinds) > 0 { if len(volumeBinds) > 0 {
// Only use mounts, not direct binds // Only use mounts, not direct binds
hostConfig.Binds = []string{} hostConfig.Binds = []string{}
hostConfig.Mounts = []mount.Mount{} hostConfig.Mounts = []mount.Mount{}
for _, bind := range volumeBinds { for _, bind := range volumeBinds {
@@ -931,7 +939,7 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
sourceFolder := bindSplit[0] sourceFolder := bindSplit[0]
destinationFolder := bindSplit[1] destinationFolder := bindSplit[1]
readOnly := false readOnly := false
if len(bindSplit) > 2 { if len(bindSplit) > 2 {
mode := bindSplit[2] mode := bindSplit[2]
if mode == "ro" { if mode == "ro" {
@@ -940,9 +948,9 @@ func deployApp(cli *dockerclient.Client, image string, identifier string, env []
} }
builtMount := mount.Mount{ builtMount := mount.Mount{
Type: mount.TypeBind, Type: mount.TypeBind,
Source: sourceFolder, Source: sourceFolder,
Target: destinationFolder, Target: destinationFolder,
ReadOnly: readOnly, ReadOnly: readOnly,
} }
@@ -1853,18 +1861,18 @@ func executionInit(workflowExecution shuffle.WorkflowExecution) error {
} }
} }
// Validates RERUN of single actions // Validates RERUN of single actions
// Identified by: // Identified by:
// 1. Predefined result from previous exec // 1. Predefined result from previous exec
// 2. Only ONE action // 2. Only ONE action
// 3. Every predefined result having result.Action.Category == "rerun" // 3. Every predefined result having result.Action.Category == "rerun"
/* /*
if len(workflowExecution.Workflow.Actions) == 1 && len(workflowExecution.Results) > 0 { if len(workflowExecution.Workflow.Actions) == 1 && len(workflowExecution.Results) > 0 {
finished := shuffle.ValidateFinished(ctx, extra, workflowExecution) finished := shuffle.ValidateFinished(ctx, extra, workflowExecution)
if finished { if finished {
return nil return nil
}
} }
}
*/ */
nextActions = append(nextActions, startAction) nextActions = append(nextActions, startAction)
@@ -1954,7 +1962,6 @@ func executionInit(workflowExecution shuffle.WorkflowExecution) error {
//log.Printf("Successfully downloaded and built %s", image) //log.Printf("Successfully downloaded and built %s", image)
} }
visited := []string{} visited := []string{}
executed := []string{} executed := []string{}
environments := []string{} environments := []string{}
@@ -3777,7 +3784,7 @@ func checkStandaloneRun() {
if !strings.Contains(backendUrl, "http") { if !strings.Contains(backendUrl, "http") {
log.Printf("[ERROR] Backend URL should start with http:// or https://") log.Printf("[ERROR] Backend URL should start with http:// or https://")
return return
} }
// Format: // Format:
@@ -3851,7 +3858,7 @@ func checkStandaloneRun() {
continue continue
} }
// This is to handle reruns of SINGLE actions // This is to handle reruns of SINGLE actions
if result.Action.Category == "rerun" { if result.Action.Category == "rerun" {
newResults = append(newResults, result) newResults = append(newResults, result)
continue continue
@@ -3905,7 +3912,6 @@ func checkStandaloneRun() {
log.Printf("\n\n\n[DEBUG] Finished resetting execution %s. Body: %s. Starting execution.\n\n\n", newresp.Status, string(body)) log.Printf("\n\n\n[DEBUG] Finished resetting execution %s. Body: %s. Starting execution.\n\n\n", newresp.Status, string(body))
} }
// Initial loop etc // Initial loop etc