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(apis): Add suggestion CRD API #740

Merged
merged 3 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: Add suggestion CRD
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege committed Sep 4, 2019
commit b3fd34bafde52aa3c65c30d40b602c3d9c01770e
2 changes: 2 additions & 0 deletions pkg/apis/controller/addtoscheme_katib_v1alpha3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package apis

import (
experiments "github.com/kubeflow/katib/pkg/apis/controller/experiments/v1alpha3"
suggestions "github.com/kubeflow/katib/pkg/apis/controller/suggestions/v1alpha3"
trials "github.com/kubeflow/katib/pkg/apis/controller/trials/v1alpha3"
)

Expand All @@ -25,5 +26,6 @@ func init() {
AddToSchemes = append(AddToSchemes,
experiments.SchemeBuilder.AddToScheme,
trials.SchemeBuilder.AddToScheme,
suggestions.SchemeBuilder.AddToScheme,
)
}
17 changes: 17 additions & 0 deletions pkg/apis/controller/common/v1alpha3/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ limitations under the License.

package v1alpha3

// +k8s:deepcopy-gen=true
type AlgorithmSpec struct {
AlgorithmName string `json:"algorithmName,omitempty"`
// Key-value pairs representing settings for suggestion algorithms.
AlgorithmSettings []AlgorithmSetting `json:"algorithmSettings"`
EarlyStopping *EarlyStoppingSpec `json:"earlyStopping,omitempty"`
}

type AlgorithmSetting struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}

type EarlyStoppingSpec struct {
// TODO
}

// +k8s:deepcopy-gen=true
type ObjectiveSpec struct {
Type ObjectiveType `json:"type,omitempty"`
Expand Down
18 changes: 1 addition & 17 deletions pkg/apis/controller/experiments/v1alpha3/experiment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ExperimentSpec struct {
Objective *common.ObjectiveSpec `json:"objective,omitempty"`

// Describes the suggestion algorithm.
Algorithm *AlgorithmSpec `json:"algorithm,omitempty"`
Algorithm *common.AlgorithmSpec `json:"algorithm,omitempty"`

// Template for each run of the trial.
TrialTemplate *TrialTemplate `json:"trialTemplate,omitempty"`
Expand Down Expand Up @@ -162,22 +162,6 @@ type FeasibleSpace struct {
Step string `json:"step,omitempty"`
}

type AlgorithmSpec struct {
AlgorithmName string `json:"algorithmName,omitempty"`
// Key-value pairs representing settings for suggestion algorithms.
AlgorithmSettings []AlgorithmSetting `json:"algorithmSettings"`
EarlyStopping *EarlyStoppingSpec `json:"earlyStopping,omitempty"`
}

type AlgorithmSetting struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}

type EarlyStoppingSpec struct {
// TODO
}

type TrialTemplate struct {
Retain bool `json:"retain,omitempty"`
GoTemplate *GoTemplate `json:"goTemplate,omitempty"`
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/controller/suggestions/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package suggestions contains suggestion API versions
package suggestions
24 changes: 24 additions & 0 deletions pkg/apis/controller/suggestions/v1alpha3/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha3 contains API Schema definitions for the suggestion v1alpha3 API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/kubeflow/katib/pkg/apis/controller/suggestions/v1alpha3
// +k8s:defaulter-gen=TypeMeta
// +kubebuilder:subresource:status
// +groupName=suggestion.kubeflow.org
package v1alpha3
43 changes: 43 additions & 0 deletions pkg/apis/controller/suggestions/v1alpha3/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha3 contains API Schema definitions for the suggestion v1alpha3 API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/kubeflow/katib/pkg/apis/controller/suggestions/v1alpha3
// +k8s:defaulter-gen=TypeMeta
// +kubebuilder:subresource:status
// +groupName=suggestion.kubeflow.org
package v1alpha3

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
)

const (
Group = "kubeflow.org"
Version = "v1alpha3"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
AddToScheme = SchemeBuilder.AddToScheme
)
119 changes: 119 additions & 0 deletions pkg/apis/controller/suggestions/v1alpha3/suggestion_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha3

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

common "github.com/kubeflow/katib/pkg/apis/controller/common/v1alpha3"
)

// SuggestionSpec defines the desired state of Suggestion
type SuggestionSpec struct {
// Number of suggestions requested
Suggestions int32 `json:"suggestions,omitempty"`

//Algorithm settings set by the user in the experiment config
AlgorithmSpec *common.AlgorithmSpec `json:"algorithm_settings,omitempty"`
}

// SuggestionStatus defines the observed state of Suggestion
type SuggestionStatus struct {
// Suggestion results
Assignments []TrialAssignment `json:"assignments,omitempty"`

// Represents time when the Suggestion was acknowledged by the Suggestion controller.
// It is not guaranteed to be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
StartTime *metav1.Time `json:"startTime,omitempty"`

// Represents time when the Suggestion was completed. It is not guaranteed to
// be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
CompletionTime *metav1.Time `json:"completionTime,omitempty"`

// Represents last time when the Suggestion was reconciled. It is not guaranteed to
// be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
LastReconcileTime *metav1.Time `json:"lastReconcileTime,omitempty"`

// List of observed runtime conditions for this Suggestion.
Conditions []SuggestionCondition `json:"conditions,omitempty"`
}

type TrialAssignment struct {
// Suggestion results
Assignments []common.ParameterAssignment `json:"assignments,omitempty"`
}

// SuggestionCondition describes the state of the Suggestion at a certain point.
// +k8s:deepcopy-gen=true
type SuggestionCondition struct {
// Type of Suggestion condition.
Type SuggestionConditionType `json:"type"`

// Status of the condition, one of True, False, Unknown.
Status v1.ConditionStatus `json:"status"`

// The reason for the condition's last transition.
Reason string `json:"reason,omitempty"`

// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`

// The last time this condition was updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`

// Last time the condition transitioned from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// SuggestionConditionType defines the state of a Suggestion.
type SuggestionConditionType string

const (
SuggestionCreated SuggestionConditionType = "Created"
SuggestionRunning SuggestionConditionType = "Running"
gaocegege marked this conversation as resolved.
Show resolved Hide resolved
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Suggestion represents the structure of a Suggestion resource.
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
type Suggestion struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SuggestionSpec `json:"spec,omitempty"`
Status SuggestionStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// SuggestionList contains a list of Suggestion
type SuggestionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Suggestion `json:"items"`
}

func init() {
SchemeBuilder.Register(&Suggestion{}, &SuggestionList{})
}
2 changes: 1 addition & 1 deletion pkg/webhook/v1alpha3/experiment/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (g *DefaultValidator) validateObjective(obj *commonapiv1alpha3.ObjectiveSpe
return nil
}

func (g *DefaultValidator) validateAlgorithm(ag *experimentsv1alpha3.AlgorithmSpec) error {
func (g *DefaultValidator) validateAlgorithm(ag *commonapiv1alpha3.AlgorithmSpec) error {
if ag == nil {
return fmt.Errorf("No spec.algorithm specified.")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/v1alpha3/experiment/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ func newFakeInstance() *experimentsv1alpha3.Experiment {
Goal: &goal,
ObjectiveMetricName: "testme",
},
Algorithm: &experimentsv1alpha3.AlgorithmSpec{
Algorithm: &commonv1alpha3.AlgorithmSpec{
AlgorithmName: "test",
AlgorithmSettings: []experimentsv1alpha3.AlgorithmSetting{
AlgorithmSettings: []commonv1alpha3.AlgorithmSetting{
{
Name: "test1",
Value: "value1",
Expand Down