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

katib ui: adapt environment in which cluster role is unavailable #1141

Merged
merged 6 commits into from
Apr 16, 2020
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
10 changes: 3 additions & 7 deletions pkg/ui/v1alpha3/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,13 @@ func (k *KatibUIHandler) DeleteTemplate(w http.ResponseWriter, r *http.Request)

func (k *KatibUIHandler) FetchNamespaces(w http.ResponseWriter, r *http.Request) {

namespaceList, err := k.katibClient.GetNamespaceList()
// Get all available namespaces
namespaces, err := k.getAvailableNamespaces()
if err != nil {
log.Printf("GetNamespaceList failed: %v", err)
log.Printf("GetAvailableNamespaces failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var namespaces []string

for _, namespace := range namespaceList.Items {
namespaces = append(namespaces, namespace.ObjectMeta.Name)
}

response, err := json.Marshal(namespaces)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/ui/v1alpha3/hp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import (

// FetchAllHPJobs gets experiments in all namespaces.
func (k *KatibUIHandler) FetchAllHPJobs(w http.ResponseWriter, r *http.Request) {
// Use "" to get experiments in all namespaces.
jobs, err := k.getExperimentList("", JobTypeHP)
// At first, try to list experiments in cluster scope
jobs, err := k.getExperimentList([]string{""}, JobTypeHP)
if err != nil {
// If failed, just try to list experiments from own namespace
jobs, err = k.getExperimentList([]string{}, JobTypeHP)
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
9 changes: 6 additions & 3 deletions pkg/ui/v1alpha3/nas.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (
)

func (k *KatibUIHandler) FetchAllNASJobs(w http.ResponseWriter, r *http.Request) {
//enableCors(&w)
// Use "" to get experiments in all namespaces.
jobs, err := k.getExperimentList("", JobTypeNAS)
// At first, try to list experiments in cluster scope
jobs, err := k.getExperimentList([]string{""}, JobTypeHP)
if err != nil {
// If failed, just try to list experiments from own namespace
jobs, err = k.getExperimentList([]string{}, JobTypeHP)
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
30 changes: 23 additions & 7 deletions pkg/ui/v1alpha3/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha3

import (
"encoding/json"
"github.com/kubeflow/katib/pkg/controller.v1alpha3/consts"
"log"
"net/http"
"strconv"
Expand All @@ -12,10 +13,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (k *KatibUIHandler) getExperimentList(namespace string, typ JobType) ([]JobView, error) {
func (k *KatibUIHandler) getExperimentList(namespace []string, typ JobType) ([]JobView, error) {
jobs := make([]JobView, 0)

el, err := k.katibClient.GetExperimentList(namespace)
el, err := k.katibClient.GetExperimentList(namespace...)
if err != nil {
log.Printf("GetExperimentList failed: %v", err)
return nil, err
Expand Down Expand Up @@ -50,16 +51,15 @@ func enableCors(w *http.ResponseWriter) {
func (k *KatibUIHandler) getTrialTemplatesViewList() ([]TrialTemplatesView, error) {
trialTemplatesViewList := make([]TrialTemplatesView, 0)

// Get all namespaces
namespaceList, err := k.katibClient.GetNamespaceList()
// Get all available namespaces
namespaces, err := k.getAvailableNamespaces()
if err != nil {
log.Printf("GetNamespaceList failed: %v", err)
log.Printf("GetAvailableNamespaces failed: %v", err)
return nil, err
}

// Get Trial Template ConfigMap for each namespace
for _, namespace := range namespaceList.Items {
ns := namespace.ObjectMeta.Name
for _, ns := range namespaces {
trialTemplatesConfigMapList, err := k.katibClient.GetTrialTemplates(ns)
if err != nil {
log.Printf("GetTrialTemplates failed: %v", err)
Expand All @@ -72,6 +72,22 @@ func (k *KatibUIHandler) getTrialTemplatesViewList() ([]TrialTemplatesView, erro
}
return trialTemplatesViewList, nil
}

func (k *KatibUIHandler) getAvailableNamespaces() ([]string, error) {
var namespaces []string

namespaceList, err := k.katibClient.GetNamespaceList()
if err != nil {
namespaces = append(namespaces, consts.DefaultKatibNamespace)
return namespaces, nil
}
for _, ns := range namespaceList.Items {
namespaces = append(namespaces, ns.ObjectMeta.Name)
}

return namespaces, nil
}

func getTrialTemplatesView(templatesConfigMapList *apiv1.ConfigMapList) TrialTemplatesView {

trialTemplateView := TrialTemplatesView{
Expand Down