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
Merged
Show file tree
Hide file tree
Changes from 6 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
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
9 changes: 5 additions & 4 deletions pkg/ui/v1alpha3/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@material-ui/icons": "^3.0.2",
"@material-ui/styles": "^3.0.0-alpha.10",
"@svgr/webpack": "4.1.0",
"ace-builds": "^1.4.8",
"antd": "^3.13.6",
"axios": "^0.18.0",
"babel-core": "7.0.0-bridge.0",
Expand Down Expand Up @@ -42,6 +43,7 @@
"jest-resolve": "23.6.0",
"jest-watch-typeahead": "^0.2.1",
"mini-css-extract-plugin": "0.5.0",
"monaco-editor": "^0.17.1",
"optimize-css-assets-webpack-plugin": "5.0.1",
"plotly.js": "^1.45.0",
"pnp-webpack-plugin": "1.2.1",
Expand All @@ -50,11 +52,12 @@
"postcss-preset-env": "6.5.0",
"postcss-safe-parser": "4.0.1",
"react": "^16.8.3",
"react-ace": "^6.4.0",
"react-ace": "^8.0.0",
"react-app-polyfill": "^0.2.2",
"react-dev-utils": "^8.0.0",
"react-dom": "^16.8.3",
"react-html-parser": "^2.0.2",
"react-monaco-editor": "^0.28.0",
"react-plotly.js": "^2.3.0",
"react-redux": "^6.0.1",
"react-router": "^4.3.1",
Expand All @@ -71,9 +74,7 @@
"webpack": "4.28.3",
"webpack-dev-server": "3.1.14",
"webpack-manifest-plugin": "2.0.4",
"workbox-webpack-plugin": "3.6.3",
"monaco-editor": "^0.17.1",
"react-monaco-editor": "^0.28.0"
"workbox-webpack-plugin": "3.6.3"
},
"scripts": {
"start": "node --max-old-space-size=4096 scripts/start.js",
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 @@ -74,3 +74,18 @@ export const CLOSE_DIALOG_EXPERIMENT = 'CLOSE_DIALOG_EXPERIMENT';
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,
});
Loading