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

UI: Support Trial Templates in all namespaces and all configMaps #1083

Merged
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ jobs:
language: node_js
node_js: "10.13.0"
install:
- npm install --global prettier
- npm install --global prettier@1.19.1
script:
- make prettier-check
5 changes: 3 additions & 2 deletions cmd/ui/v1alpha3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ func main() {
http.HandleFunc("/katib/fetch_nas_job_info/", kuh.FetchNASJobInfo)

http.HandleFunc("/katib/fetch_trial_templates/", kuh.FetchTrialTemplates)
http.HandleFunc("/katib/update_template/", kuh.AddEditDeleteTemplate)

http.HandleFunc("/katib/add_template/", kuh.AddTemplate)
http.HandleFunc("/katib/edit_template/", kuh.EditTemplate)
http.HandleFunc("/katib/delete_template/", kuh.DeleteTemplate)
http.HandleFunc("/katib/fetch_namespaces", kuh.FetchNamespaces)

log.Printf("Serving at %s:%s", *host, *port)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
apiVersion: v1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reluctant to have them in v1alpha3 itself as this would confuse users. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will not affect old trail template and controller.
User just can't see old Trial Templates and Submit Experiment by Parameters from the UI, using not labeled trial templates.
Other functionality in the UI will work, so they can submit Experiment using yaml file and monitor Experiments

You think that it is better not include this trial template to manifests in v1alpha3?

kind: ConfigMap
metadata:
name: trial-template-labeled
namespace: kubeflow
labels:
app: katib-trial-templates
data:
defaultTrialTemplate.yaml: |-
apiVersion: batch/v1
kind: Job
metadata:
name: {{.Trial}}
namespace: {{.NameSpace}}
spec:
template:
spec:
containers:
- name: {{.Trial}}
image: docker.io/kubeflowkatib/mxnet-mnist
command:
- "python3"
- "/opt/mxnet-mnist/mnist.py"
- "--batch-size=64"
{{- with .HyperParameters}}
{{- range .}}
- "{{.Name}}={{.Value}}"
{{- end}}
{{- end}}
restartPolicy: Never
nasRLCPUTemplate: |-
apiVersion: batch/v1
kind: Job
metadata:
name: {{.Trial}}
namespace: {{.NameSpace}}
spec:
template:
spec:
containers:
- name: {{.Trial}}
image: docker.io/kubeflowkatib/nasrl-cifar10-cpu
command:
- "python3.5"
- "-u"
- "RunTrial.py"
{{- with .HyperParameters}}
{{- range .}}
- "--{{.Name}}=\"{{.Value}}\""
{{- end}}
{{- end}}
- "--num_epochs=1"
restartPolicy: Never
pytorchJobTemplate: |-
apiVersion: "kubeflow.org/v1"
kind: PyTorchJob
metadata:
name: {{.Trial}}
namespace: {{.NameSpace}}
spec:
pytorchReplicaSpecs:
Master:
replicas: 1
restartPolicy: OnFailure
template:
spec:
containers:
- name: pytorch
image: gcr.io/kubeflow-ci/pytorch-dist-mnist-test:v1.0
imagePullPolicy: Always
command:
- "python"
- "/var/mnist.py"
{{- with .HyperParameters}}
{{- range .}}
- "{{.Name}}={{.Value}}"
{{- end}}
{{- end}}
Worker:
replicas: 2
restartPolicy: OnFailure
template:
spec:
containers:
- name: pytorch
image: gcr.io/kubeflow-ci/pytorch-dist-mnist-test:v1.0
imagePullPolicy: Always
command:
- "python"
- "/var/mnist.py"
{{- with .HyperParameters}}
{{- range .}}
- "{{.Name}}={{.Value}}"
{{- end}}
{{- end}}
3 changes: 3 additions & 0 deletions pkg/controller.v1alpha3/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ const (

// AnnotationIstioSidecarInjectValue is the value of Istio Sidecar annotation
AnnotationIstioSidecarInjectValue = "false"

LabelTrialTemplateConfigMapName = "app"
LabelTrialTemplateConfigMapValue = "katib-trial-templates"
)

var (
Expand Down
33 changes: 14 additions & 19 deletions pkg/mock/v1alpha3/util/katibclient/katibclient.go

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

106 changes: 83 additions & 23 deletions pkg/ui/v1alpha3/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
experimentv1alpha3 "github.com/kubeflow/katib/pkg/apis/controller/experiments/v1alpha3"
api_pb_v1alpha3 "github.com/kubeflow/katib/pkg/apis/manager/v1alpha3"
common_v1alpha3 "github.com/kubeflow/katib/pkg/common/v1alpha3"
"github.com/kubeflow/katib/pkg/controller.v1alpha3/consts"
"github.com/kubeflow/katib/pkg/util/v1alpha3/katibclient"
)

Expand Down Expand Up @@ -116,21 +115,20 @@ func (k *KatibUIHandler) DeleteExperiment(w http.ResponseWriter, r *http.Request
}
}

// FetchTrialTemplates gets the trial templates for the given namespace.
// FetchTrialTemplates gets all trial templates in all namespaces
func (k *KatibUIHandler) FetchTrialTemplates(w http.ResponseWriter, r *http.Request) {
//enableCors(&w)
namespace := r.URL.Query()["namespace"][0]
if namespace == "" {
namespace = consts.DefaultKatibNamespace
}
trialTemplates, err := k.katibClient.GetTrialTemplates(namespace)

trialTemplatesViewList, err := k.getTrialTemplatesViewList()
if err != nil {
log.Printf("GetTrialTemplate failed: %v", err)
log.Printf("getTrialTemplatesViewList failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

response, err := json.Marshal(getTemplatesView(trialTemplates))
TrialTemplatesResponse := TrialTemplatesResponse{
Data: trialTemplatesViewList,
}
response, err := json.Marshal(TrialTemplatesResponse)
if err != nil {
log.Printf("Marshal templates failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -139,29 +137,91 @@ func (k *KatibUIHandler) FetchTrialTemplates(w http.ResponseWriter, r *http.Requ
w.Write(response)
}

func (k *KatibUIHandler) AddEditDeleteTemplate(w http.ResponseWriter, r *http.Request) {
//enableCors(&w)
//TODO: need to delete?
if r.Method == "OPTIONS" {
//AddTemplate adds template to ConfigMap
//TODO: Add functionality to create new ConfigMap
func (k *KatibUIHandler) AddTemplate(w http.ResponseWriter, r *http.Request) {
var data map[string]interface{}
json.NewDecoder(r.Body).Decode(&data)

edittedNamespace := data["edittedNamespace"].(string)
edittedConfigMapName := data["edittedConfigMapName"].(string)
edittedName := data["edittedName"].(string)
edittedYaml := data["edittedYaml"].(string)

newTemplates, err := k.updateTrialTemplates(edittedNamespace, edittedConfigMapName, edittedName, edittedYaml, "", ActionTypeAdd)
if err != nil {
log.Printf("updateTrialTemplates failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var data map[string]interface{}
var err error
var templateResponse TemplateResponse

TrialTemplatesResponse := TrialTemplatesResponse{
Data: newTemplates,
}
response, err := json.Marshal(TrialTemplatesResponse)
if err != nil {
log.Printf("Marhal failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(response)

}

// EditTemplate edits template in ConfigMap
func (k *KatibUIHandler) EditTemplate(w http.ResponseWriter, r *http.Request) {

var data map[string]interface{}
json.NewDecoder(r.Body).Decode(&data)
if data["action"].(string) == "delete" {
templateResponse, err = k.updateTemplates(data, true)
} else {
templateResponse, err = k.updateTemplates(data, false)

edittedNamespace := data["edittedNamespace"].(string)
edittedConfigMapName := data["edittedConfigMapName"].(string)
edittedName := data["edittedName"].(string)
edittedYaml := data["edittedYaml"].(string)
currentName := data["currentName"].(string)

newTemplates, err := k.updateTrialTemplates(edittedNamespace, edittedConfigMapName, edittedName, edittedYaml, currentName, ActionTypeEdit)
if err != nil {
log.Printf("updateTrialTemplates failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

TrialTemplatesResponse := TrialTemplatesResponse{
Data: newTemplates,
}
response, err := json.Marshal(TrialTemplatesResponse)
if err != nil {
log.Printf("updateTemplates failed: %v", err)
log.Printf("Marhal failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(response)
}

// DeleteTemplate delete template in ConfigMap
// TODO: Add functionality to delete configMap if there is no templates
func (k *KatibUIHandler) DeleteTemplate(w http.ResponseWriter, r *http.Request) {

var data map[string]interface{}
json.NewDecoder(r.Body).Decode(&data)

edittedNamespace := data["edittedNamespace"].(string)
edittedConfigMapName := data["edittedConfigMapName"].(string)
edittedName := data["edittedName"].(string)

newTemplates, err := k.updateTrialTemplates(edittedNamespace, edittedConfigMapName, edittedName, "", "", ActionTypeDelete)
if err != nil {
log.Printf("updateTrialTemplates failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

TrialTemplatesResponse := TrialTemplatesResponse{
Data: newTemplates,
}

response, err := json.Marshal(templateResponse)
response, err := json.Marshal(TrialTemplatesResponse)
if err != nil {
log.Printf("Marhal failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
15 changes: 15 additions & 0 deletions pkg/ui/v1alpha3/frontend/src/actions/generalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ export const closeDialogExperiment = () => ({
type: CLOSE_DIALOG_EXPERIMENT,
});

export const FILTER_TEMPLATES_EXPERIMENT = 'FILTER_TEMPLATES_EXPERIMENT';

export const filterTemplatesExperiment = (trialNamespace, trialConfigMapName) => ({
type: FILTER_TEMPLATES_EXPERIMENT,
trialNamespace,
trialConfigMapName,
});

export const CHANGE_TEMPLATE_NAME = 'CHANGE_TEMPLATE_NAME';

export const changeTemplateName = templateName => ({
type: CHANGE_TEMPLATE_NAME,
templateName,
});

export const VALIDATION_ERROR = 'VALIDATION_ERROR';

export const validationError = message => ({
Expand Down
14 changes: 0 additions & 14 deletions pkg/ui/v1alpha3/frontend/src/actions/hpCreateActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,6 @@ export const deleteListParameter = (paramIndex, index) => ({
index,
});

export const CHANGE_TRIAL_HP = 'CHANGE_TRIAL_HP';

export const changeTrial = trial => ({
type: CHANGE_TRIAL_HP,
trial,
});

export const CHANGE_TRIAL_NAMESPACE_HP = 'CHANGE_TRIAL_NAMESPACE_HP';

export const changeTrialNamespace = namespace => ({
type: CHANGE_TRIAL_NAMESPACE_HP,
namespace,
});

export const SUBMIT_HP_JOB_REQUEST = 'SUBMIT_HP_JOB_REQUEST';
export const SUBMIT_HP_JOB_SUCCESS = 'SUBMIT_HP_JOB_SUCCESS';
export const SUBMIT_HP_JOB_FAILURE = 'SUBMIT_HP_JOB_FAILURE';
Expand Down
Loading