Skip to content

Commit

Permalink
Merge pull request #31 from rimolive/rmartine
Browse files Browse the repository at this point in the history
chore: Cherry-pick key commits for supporting v1 features in v2 API
  • Loading branch information
openshift-merge-bot[bot] authored Apr 1, 2024
2 parents 4244d12 + a49c696 commit 680e445
Show file tree
Hide file tree
Showing 30 changed files with 3,171 additions and 118 deletions.
100 changes: 99 additions & 1 deletion backend/src/v2/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kubeflow/pipelines/backend/src/v2/objectstore"
"path"
"strconv"
"strings"
"time"

"github.com/kubeflow/pipelines/backend/src/v2/objectstore"

"github.com/golang/glog"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/google/uuid"
Expand Down Expand Up @@ -488,11 +489,51 @@ func extendPodSpecPatch(
podSpec.Containers[0].VolumeMounts = append(podSpec.Containers[0].VolumeMounts, volumeMounts...)
}

// Get image pull policy
pullPolicy := kubernetesExecutorConfig.GetImagePullPolicy()
if pullPolicy != "" {
policies := []string{"Always", "Never", "IfNotPresent"}
found := false
for _, value := range policies {
if value == pullPolicy {
found = true
break
}
}
if !found {
return fmt.Errorf("unsupported value: %s. ImagePullPolicy should be one of 'Always', 'Never' or 'IfNotPresent'", pullPolicy)
}
// We assume that the user container always gets executed first within a pod.
podSpec.Containers[0].ImagePullPolicy = k8score.PullPolicy(pullPolicy)
}

// Get node selector information
if kubernetesExecutorConfig.GetNodeSelector() != nil {
podSpec.NodeSelector = kubernetesExecutorConfig.GetNodeSelector().GetLabels()
}

if tolerations := kubernetesExecutorConfig.GetTolerations(); tolerations != nil {
var k8sTolerations []k8score.Toleration

glog.Infof("Tolerations passed: %+v", tolerations)

for _, toleration := range tolerations {
if toleration != nil {
k8sToleration := k8score.Toleration{
Key: toleration.Key,
Operator: k8score.TolerationOperator(toleration.Operator),
Value: toleration.Value,
Effect: k8score.TaintEffect(toleration.Effect),
TolerationSeconds: toleration.TolerationSeconds,
}

k8sTolerations = append(k8sTolerations, k8sToleration)
}
}

podSpec.Tolerations = k8sTolerations
}

// Get secret mount information
for _, secretAsVolume := range kubernetesExecutorConfig.GetSecretAsVolume() {
secretVolume := k8score.Volume{
Expand Down Expand Up @@ -525,6 +566,63 @@ func extendPodSpecPatch(
}
}

// Get config map mount information
for _, configMapAsVolume := range kubernetesExecutorConfig.GetConfigMapAsVolume() {
configMapVolume := k8score.Volume{
Name: configMapAsVolume.GetConfigMapName(),
VolumeSource: k8score.VolumeSource{
ConfigMap: &k8score.ConfigMapVolumeSource{
LocalObjectReference: k8score.LocalObjectReference{Name: configMapAsVolume.GetConfigMapName()}},
},
}
configMapVolumeMount := k8score.VolumeMount{
Name: configMapAsVolume.GetConfigMapName(),
MountPath: configMapAsVolume.GetMountPath(),
}
podSpec.Volumes = append(podSpec.Volumes, configMapVolume)
podSpec.Containers[0].VolumeMounts = append(podSpec.Containers[0].VolumeMounts, configMapVolumeMount)
}

// Get config map env information
for _, configMapAsEnv := range kubernetesExecutorConfig.GetConfigMapAsEnv() {
for _, keyToEnv := range configMapAsEnv.GetKeyToEnv() {
configMapEnvVar := k8score.EnvVar{
Name: keyToEnv.GetEnvVar(),
ValueFrom: &k8score.EnvVarSource{
ConfigMapKeyRef: &k8score.ConfigMapKeySelector{
Key: keyToEnv.GetConfigMapKey(),
},
},
}
configMapEnvVar.ValueFrom.ConfigMapKeyRef.LocalObjectReference.Name = configMapAsEnv.GetConfigMapName()
podSpec.Containers[0].Env = append(podSpec.Containers[0].Env, configMapEnvVar)
}
}

// Get image pull secret information
for _, imagePullSecret := range kubernetesExecutorConfig.GetImagePullSecret() {
podSpec.ImagePullSecrets = append(podSpec.ImagePullSecrets, k8score.LocalObjectReference{Name: imagePullSecret.GetSecretName()})
}

// Get Kubernetes FieldPath Env information
for _, fieldPathAsEnv := range kubernetesExecutorConfig.GetFieldPathAsEnv() {
fieldPathEnvVar := k8score.EnvVar{
Name: fieldPathAsEnv.GetName(),
ValueFrom: &k8score.EnvVarSource{
FieldRef: &k8score.ObjectFieldSelector{
FieldPath: fieldPathAsEnv.GetFieldPath(),
},
},
}
podSpec.Containers[0].Env = append(podSpec.Containers[0].Env, fieldPathEnvVar)
}

// Get container timeout information
timeout := kubernetesExecutorConfig.GetActiveDeadlineSeconds()
if timeout > 0 {
podSpec.ActiveDeadlineSeconds = &timeout
}

return nil
}

Expand Down
Loading

0 comments on commit 680e445

Please sign in to comment.