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

feat(experiment-validator): Inject client #561

Merged
merged 2 commits into from
May 21, 2019
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
7 changes: 6 additions & 1 deletion pkg/controller/v1alpha2/experiment/manifest/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"text/template"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
apiv1alpha2 "github.com/kubeflow/katib/pkg/api/v1alpha2"
commonv1alpha2 "github.com/kubeflow/katib/pkg/common/v1alpha2"
"github.com/kubeflow/katib/pkg/util/v1alpha2/katibclient"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
Expand All @@ -22,6 +22,7 @@ const (

// Generator is the type for manifests Generator.
type Generator interface {
InjectClient(c client.Client)
GetRunSpec(e *experimentsv1alpha2.Experiment, experiment, trial, namespace string) (string, error)
GetRunSpecWithHyperParameters(e *experimentsv1alpha2.Experiment, experiment, trial, namespace string, hps []*apiv1alpha2.ParameterAssignment) (string, error)
GetMetricsCollectorManifest(experimentName string, trialName string, jobKind string, namespace string, metricNames []string, mcs *experimentsv1alpha2.MetricsCollectorSpec) (*bytes.Buffer, error)
Expand All @@ -40,6 +41,10 @@ func New(c client.Client) Generator {
}
}

func (g *DefaultGenerator) InjectClient(c client.Client) {
g.client.InjectClient(c)
}

func (g *DefaultGenerator) GetMetricsCollectorManifest(experimentName string, trialName string, jobKind string, namespace string, metricNames []string, mcs *experimentsv1alpha2.MetricsCollectorSpec) (*bytes.Buffer, error) {
var mtp *template.Template = nil
var err error
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/v1alpha2/experiment/validation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var _ inject.Client = &experimentValidator{}
// InjectClient injects the client.
func (v *experimentValidator) InjectClient(c client.Client) error {
v.client = c
v.Validator.InjectClient(c)
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/v1alpha2/experiment/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/client"

commonapiv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/common/v1alpha2"
experimentsv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/experiment/v1alpha2"
Expand All @@ -21,6 +22,7 @@ var log = logf.Log.WithName("experiment-controller")

type Validator interface {
ValidateExperiment(instance *experimentsv1alpha2.Experiment) error
InjectClient(c client.Client)
}

type DefaultValidator struct {
Expand All @@ -35,6 +37,10 @@ func New(generator manifest.Generator, managerClient managerclient.ManagerClient
}
}

func (g *DefaultValidator) InjectClient(c client.Client) {
g.Generator.InjectClient(c)
}

func (g *DefaultValidator) ValidateExperiment(instance *experimentsv1alpha2.Experiment) error {
if !instance.IsCreated() {
if err := g.validateForCreate(instance); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/mock/v1alpha2/experiment/manifest/producer.go

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

13 changes: 13 additions & 0 deletions pkg/mock/v1alpha2/util/katibclient/katibclient.go

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

5 changes: 5 additions & 0 deletions pkg/util/v1alpha2/katibclient/katib_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

type Client interface {
InjectClient(c client.Client)
GetExperimentList(namespace ...string) (*experimentsv1alpha2.ExperimentList, error)
CreateExperiment(experiment *experimentsv1alpha2.Experiment, namespace ...string) error
GetConfigMap(name string, namespace ...string) (map[string]string, error)
Expand Down Expand Up @@ -58,6 +59,10 @@ func NewClient(options client.Options) (Client, error) {
}, nil
}

func (k *KatibClient) InjectClient(c client.Client) {
k.client = c
}

func (k *KatibClient) GetExperimentList(namespace ...string) (*experimentsv1alpha2.ExperimentList, error) {
ns := getNamespace(namespace...)
expList := &experimentsv1alpha2.ExperimentList{}
Expand Down