Skip to content

Commit

Permalink
chore(webhook): add KATIB_EXPERIMENT_NAME to pod env.
Browse files Browse the repository at this point in the history
Signed-off-by: Electronic-Waste <[email protected]>
  • Loading branch information
Electronic-Waste committed Jan 15, 2025
1 parent 93bee4d commit fcd5174
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/controller.v1beta1/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (

// EnvTrialName is the env variable of Trial name
EnvTrialName = "KATIB_TRIAL_NAME"
// EnvExperimentName is the env variable of Experiment name
EnvExperimentName = "KATIB_EXPERIMENT_NAME"

// LabelExperimentName is the label of experiment name.
LabelExperimentName = "katib.kubeflow.org/experiment"
Expand Down
12 changes: 10 additions & 2 deletions pkg/webhook/v1beta1/pod/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func mutatePodEnv(pod *v1.Pod, trial *trialsv1beta1.Trial) error {
pod.Spec.Containers[index].Env = []v1.EnvVar{}
}

// Pass env variable KATIB_TRIAL_NAME to the primary container using fieldPath
// Pass env variable KATIB_TRIAL_NAME and KATIB_EXPERIMENT_NAME to the primary container using fieldPath
pod.Spec.Containers[index].Env = append(
pod.Spec.Containers[index].Env,
v1.EnvVar{
Expand All @@ -302,10 +302,18 @@ func mutatePodEnv(pod *v1.Pod, trial *trialsv1beta1.Trial) error {
},
},
},
v1.EnvVar{
Name: consts.EnvExperimentName,
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
FieldPath: fmt.Sprintf("metadata.labels['%s']", consts.LabelExperimentName),
},
},
},
)
return nil
} else {
return fmt.Errorf("Unable to find primary container %v in mutated pod containers %v",
return fmt.Errorf("unable to find primary container %v in mutated pod containers %v",
trial.Spec.PrimaryContainerName, pod.Spec.Containers)
}
}
Expand Down

0 comments on commit fcd5174

Please sign in to comment.