Skip to content

Commit

Permalink
Add Katib Client in v1alpha2 (#480)
Browse files Browse the repository at this point in the history
* Init commit

* Add Katib Client

* Add GetConfigMap func
Move templates const

* Change folder for Katib client

* Delete old client

* Change name for default templates
  • Loading branch information
andreyvelich authored and k8s-ci-robot committed May 1, 2019
1 parent fd4c21c commit 709d97c
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 147 deletions.
117 changes: 19 additions & 98 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pkg/api/operators/apis/experiment/v1alpha2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ const (
// Default value of Spec.ParallelTrialCount
DefaultTrialParallelCount = 3

// Default value of Spec.ConfigMapName
// Default value of Spec.ConfigMapName for Trial template
DefaultTrialConfigMapName = "trial-template"

// Default env name of katib namespace
DefaultKatibNamespaceEnvName = "KATIB_CORE_NAMESPACE"

// Default value of Spec.TemplatePath
DefaultTrialTemplatePath = "defaultTrialTemplate.yaml"

// Default value of Spec.ConfigMapName for Metrics Collector template
DefaultMetricsCollectorConfigMapName = "metrics-collector-template"
)
29 changes: 0 additions & 29 deletions pkg/controller/v1alpha2/experiment/util/client_util.go

This file was deleted.

25 changes: 8 additions & 17 deletions pkg/controller/v1alpha2/experiment/util/template_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ package util

import (
"bytes"
"context"
"errors"
"text/template"

apiv1alpha2 "github.com/kubeflow/katib/pkg/api/v1alpha2"
experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
apiv1 "k8s.io/api/core/v1"
apiv1alpha2 "github.com/kubeflow/katib/pkg/api/v1alpha2"
"github.com/kubeflow/katib/pkg/util/v1alpha2/katibclient"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -64,10 +62,15 @@ func getTrialTemplate(instance *experimentsv1alpha2.Experiment) (*template.Templ
configMapName := templateSpec.ConfigMapName
templatePath := templateSpec.TemplatePath

configMap, err := getConfigMap(configMapName, configMapNS)
katibClient, err := katibclient.NewClient(client.Options{})
if err != nil {
return nil, err
}
configMap, err := katibClient.GetConfigMap(configMapName, configMapNS)
if err != nil {
return nil, err
}

if configMapTemplate, ok := configMap[templatePath]; !ok {
err = errors.New(string(metav1.StatusReasonNotFound))
return nil, err
Expand All @@ -81,15 +84,3 @@ func getTrialTemplate(instance *experimentsv1alpha2.Experiment) (*template.Templ

return tpl, nil
}

func getConfigMap(name, namespace string) (map[string]string, error) {
client, err := NewClient(client.Options{})
if err != nil {
return map[string]string{}, err
}
configMap := &apiv1.ConfigMap{}
if err := client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: namespace}, configMap); err != nil {
return map[string]string{}, err
}
return configMap.Data, nil
}
4 changes: 2 additions & 2 deletions pkg/controller/v1alpha2/experiment/util/webhook_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ValidateExperiment(instance *ep_v1alpha2.Experiment) error {
return fmt.Errorf("Only one of spec.parameters and spec.nasConfig can be specified.")
}

if err := validateAlgorithmSettings(instance); err !=nil {
if err := validateAlgorithmSettings(instance); err != nil {
return err
}
return nil
Expand All @@ -66,7 +66,7 @@ func validateObjective(obj *ep_v1alpha2.ObjectiveSpec) error {
if obj == nil {
return fmt.Errorf("No spec.objective specified.")
}
if obj.Type != ep_v1alpha2.ObjectiveTypeMinimize && obj.Type != ep_v1alpha2.ObjectiveTypeMaximize {
if obj.Type != ep_v1alpha2.ObjectiveTypeMinimize && obj.Type != ep_v1alpha2.ObjectiveTypeMaximize {
return fmt.Errorf("spec.objective.type must be %s or %s.", ep_v1alpha2.ObjectiveTypeMinimize, ep_v1alpha2.ObjectiveTypeMaximize)
}
if obj.ObjectiveMetricName == "" {
Expand Down
Loading

0 comments on commit 709d97c

Please sign in to comment.