Minor sdk fix

This commit is contained in:
Frikky
2024-06-11 16:05:15 +02:00
parent f2d99c6091
commit 26ee1d4da5
6 changed files with 82 additions and 16 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ go 1.22.0
toolchain go1.22.2
//replace github.com/shuffle/shuffle-shared => ../../../../shuffle-shared
replace github.com/shuffle/shuffle-shared => ../../../../shuffle-shared
require (
github.com/docker/docker v26.1.0+incompatible
+2
View File
@@ -393,6 +393,8 @@ github.com/shuffle/shuffle-shared v0.6.18 h1:mKc3vGuCz9ubdqMwaLocSbEUZyso620CY73
github.com/shuffle/shuffle-shared v0.6.18/go.mod h1:00QOcSPlUWMXzJj1D7pjcV9h6nVRWfSWqTM10+fhTd0=
github.com/shuffle/shuffle-shared v0.6.27 h1:q4qZD6bGZFIvZ5Y10unGr3N3rZ7OryWyvvaGgANZJZU=
github.com/shuffle/shuffle-shared v0.6.27/go.mod h1:rWkh1eWdIx7OqQzJ1+JzF3Hck1X/Ty1WkUtjLrp+CU4=
github.com/shuffle/shuffle-shared v0.6.37 h1:IB8tJqubJmJwwpLYbXNMVWck5jgVO9SKcKo/BBu+wTc=
github.com/shuffle/shuffle-shared v0.6.37/go.mod h1:rWkh1eWdIx7OqQzJ1+JzF3Hck1X/Ty1WkUtjLrp+CU4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
+51 -12
View File
@@ -683,6 +683,7 @@ func deployWorker(image string, identifier string, env []string, executionReques
return err
}
//env = append(env, fmt.Sprintf("KUBERNETES_CONFIG=%s", config.String()))
// FIXME: When a service account is used, the account is also mounted in the pod
@@ -697,6 +698,7 @@ func deployWorker(image string, identifier string, env []string, executionReques
// use k8s downward API to find it if we are in a pod
}
// Check if namespace exist as variable. If so, make it
if len(os.Getenv("KUBERNETES_NAMESPACE")) > 0 && !namespacemade {
kubernetesNamespace = os.Getenv("KUBERNETES_NAMESPACE")
@@ -720,6 +722,18 @@ func deployWorker(image string, identifier string, env []string, executionReques
}
}
if len(kubernetesNamespace) == 0 {
foundNamespace, err := shuffle.GetKubernetesNamespace()
if err != nil {
//log.Printf("[ERROR] Failed getting Kubernetes namespace: %s", err)
}
if len(foundNamespace) > 0 {
kubernetesNamespace = foundNamespace
os.Setenv("KUBERNETES_NAMESPACE", kubernetesNamespace)
}
}
if len(kubernetesNamespace) == 0 {
kubernetesNamespace = "default"
}
@@ -739,12 +753,40 @@ func deployWorker(image string, identifier string, env []string, executionReques
}
}
containerLabels := map[string]string{
"container": "shuffle-worker",
}
containerAttachment := corev1.Container{
Name: identifier,
Image: kubernetesImage,
Env: buildEnvVars(envMap),
//ImagePullPolicy: "Never",
ImagePullPolicy: corev1.PullIfNotPresent,
}
podname := shuffle.GetPodName()
ctx := context.Background()
if len(podname) > 0 {
currentPodStatus, err := shuffle.GetCurrentPodNetworkConfig(ctx, clientset, kubernetesNamespace, podname)
if err != nil {
log.Printf("[ERROR] Failed getting current pod network: %s", err)
} else {
log.Printf("[DEBUG] Current pod found!")
// currentPodStatus = k8s.io/api/core/v1.PodStatus
}
}
// While testing:
// kubectl delete pods --all --all-namespaces; kubectl delete services --all --all-namespaces
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: identifier,
Labels: map[string]string{"app": "shuffle-worker"},
Labels: containerLabels,
},
Spec: corev1.PodSpec{
RestartPolicy: "Never",
@@ -753,23 +795,20 @@ func deployWorker(image string, identifier string, env []string, executionReques
// "node": "master",
// },
Containers: []corev1.Container{
{
Name: identifier,
Image: kubernetesImage,
Env: buildEnvVars(envMap),
//ImagePullPolicy: "Never",
ImagePullPolicy: corev1.PullIfNotPresent,
//ImagePullPolicy: "Always",
},
containerAttachment,
},
},
}
// Check if running on ARM or x86 to download the correct image
// Add environment variables
// pod.Spec.Containers[0].Env = buildEnvVars(envMap)
// Get current pod's network so we can make the pod in it
networks, err := clientset.CoreV1().Pods(kubernetesNamespace).List(context.Background(), metav1.ListOptions{})
if err != nil {
log.Printf("[ERROR] Failed listing pods: %s", err)
}
createdPod, err := clientset.CoreV1().Pods(kubernetesNamespace).Create(context.Background(), pod, metav1.CreateOptions{})
if err != nil {