Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Inherit labels and annotations from experiment #998

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}