Skip to content

Commit

Permalink
fix: Inherit labels and annotations from experiment
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege committed Jan 6, 2020
1 parent c8cb2cb commit f5a7c9f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pkg/controller.v1alpha3/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
LabelExperimentName = "experiment"
// LabelSuggestionName is the label of suggestion name.
LabelSuggestionName = "suggestion"
// LabelDeploymentName is the label of deployment name.
LabelDeploymentName = "deployment"

// ContainerSuggestion is the container name in Suggestion.
ContainerSuggestion = "suggestion"
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller.v1alpha3/experiment/suggestion/suggestion.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ func (g *General) createSuggestion(instance *experimentsv1alpha3.Experiment, sug
logger := log.WithValues("experiment", types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace})
suggestion := &suggestionsv1alpha3.Suggestion{
ObjectMeta: metav1.ObjectMeta{
Name: instance.Name,
Namespace: instance.Namespace,
Name: instance.Name,
Namespace: instance.Namespace,
Labels: instance.Labels,
Annotations: instance.Annotations,
},
Spec: suggestionsv1alpha3.SuggestionSpec{
AlgorithmName: instance.Spec.Algorithm.AlgorithmName,
Expand Down
9 changes: 6 additions & 3 deletions pkg/controller.v1alpha3/suggestion/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ func (g *General) DesiredDeployment(s *suggestionsv1alpha3.Suggestion) (*appsv1.
}
d := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: util.GetAlgorithmDeploymentName(s),
Namespace: s.Namespace,
Name: util.GetAlgorithmDeploymentName(s),
Namespace: s.Namespace,
Labels: s.Labels,
Annotations: s.Annotations,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: util.SuggestionLabels(s),
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: util.SuggestionLabels(s),
Labels: util.SuggestionLabels(s),
Annotations: s.Annotations,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
Expand Down
22 changes: 16 additions & 6 deletions pkg/controller.v1alpha3/util/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ import (
"github.com/kubeflow/katib/pkg/controller.v1alpha3/consts"
)

// SuggestionLabels returns the expected suggestion labels.
func SuggestionLabels(instance *suggestionsv1alpha3.Suggestion) map[string]string {
return map[string]string{
"deployment": GetAlgorithmDeploymentName(instance),
consts.LabelExperimentName: instance.Name,
consts.LabelSuggestionName: instance.Name,
res := make(map[string]string)
for k, v := range instance.Labels {
res[k] = v
}
res[consts.LabelDeploymentName] = GetAlgorithmDeploymentName(instance)
res[consts.LabelExperimentName] = instance.Name
res[consts.LabelSuggestionName] = instance.Name

return res
}

// TrialLabels returns the expected trial labels.
func TrialLabels(instance *experimentsv1alpha3.Experiment) map[string]string {
return map[string]string{
consts.LabelExperimentName: instance.Name,
res := make(map[string]string)
for k, v := range instance.Labels {
res[k] = v
}
res[consts.LabelExperimentName] = instance.Name

return res
}

0 comments on commit f5a7c9f

Please sign in to comment.