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 3 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
8 changes: 2 additions & 6 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)
sperlingxx marked this conversation as resolved.
Show resolved Hide resolved
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
30 changes: 30 additions & 0 deletions pkg/ui/v1alpha3/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package v1alpha3

import (
"github.com/kubeflow/katib/pkg/util/v1alpha3/env"
"strings"
)

const (
// AvailableNameSpaceEnvName is the env name of available namespaces
AvailableNameSpaceEnvName = "KATIB_UI_AVAILABLE_NS"
// ClusterRoleKey is a key represents having access to cluster role
ClusterRoleKey = "KATIB_UI_CLUSTER_ROLE"
)

var (
availableNameSpaces []string
hasClusterRole bool
)

func init() {
ns := env.GetEnvOrDefault(AvailableNameSpaceEnvName, ClusterRoleKey)
Copy link
Member

Choose a reason for hiding this comment

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

Couple of questions here

  1. Is it right to get the namespaces during init function? What happens if env variable is changed later?
  2. GetEnvOrDefault has fallback value as the second argument. Did you mean to keep ClusterRoleKey as the default value?

Copy link
Member Author

Choose a reason for hiding this comment

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

@johnugeorge

  1. To me, this env variable should be set via manifest yaml file. I can't see any motivation to modify this env variable later.
  2. Yes.

if ns == ClusterRoleKey {
// no namespace restriction when working with kubernetes client
availableNameSpaces = []string{""}
hasClusterRole = true
} else {
availableNameSpaces = strings.Split(ns, " ")
hasClusterRole = false
}
}
4 changes: 2 additions & 2 deletions pkg/ui/v1alpha3/hp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ 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)
// Get HP-related experiments in all available namespaces.
jobs, err := k.getExperimentList(availableNameSpaces, JobTypeHP)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/v1alpha3/nas.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ 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)
// Get NAS-related experiments in all available namespaces.
jobs, err := k.getExperimentList(availableNameSpaces, JobTypeNAS)
Copy link
Member

Choose a reason for hiding this comment

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

What do you expect when you have multiple namespaces passed?

Copy link
Member

Choose a reason for hiding this comment

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

Currently, in Katib Client: https://github.com/kubeflow/katib/blob/master/pkg/util/v1alpha3/katibclient/katib_client.go#L210, we extract only first namespace from the list, so it will not give you all available namespaces.

Copy link
Member Author

Choose a reason for hiding this comment

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

@andreyvelich Yes, but value of namespace is fixed on "" (https://github.com/kubeflow/katib/blob/master/pkg/ui/v1alpha3/hp.go#L22) which leads to list experiments in cluster scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

@johnugeorge It seems only first namespace will be taken. It is a problem.

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
30 changes: 24 additions & 6 deletions pkg/ui/v1alpha3/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,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 +50,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)
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 +71,25 @@ func (k *KatibUIHandler) getTrialTemplatesViewList() ([]TrialTemplatesView, erro
}
return trialTemplatesViewList, nil
}

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

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

return namespaces, nil
}

func getTrialTemplatesView(templatesConfigMapList *apiv1.ConfigMapList) TrialTemplatesView {

trialTemplateView := TrialTemplatesView{
Expand Down