-
Notifications
You must be signed in to change notification settings - Fork 4
/
poddefaults.go
64 lines (52 loc) · 1.39 KB
/
poddefaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"log"
"net/http"
"reflect"
v1alpha1 "github.com/StatCan/kubeflow-apis/apis/kubeflow/v1alpha1"
"github.com/gorilla/mux"
"k8s.io/apimachinery/pkg/labels"
)
type poddefaultresponse struct {
v1alpha1.PodDefault
Label string `json:"label"`
Description string `json:"desc"`
}
type poddefaultsresponse struct {
APIResponseBase
PodDefaults []poddefaultresponse `json:"poddefaults"`
}
// GetPodDefaults returns PodDefaults for the given namespace.
func (s *server) GetPodDefaults(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
namespace := vars["namespace"]
log.Printf("loading poddefaults for %q", namespace)
pds, err := s.listers.podDefaults.PodDefaults(namespace).List(labels.Everything())
if err != nil {
s.error(w, r, err)
return
}
resp := &poddefaultsresponse{
APIResponseBase: APIResponseBase{
Success: true,
Status: http.StatusOK,
},
PodDefaults: make([]poddefaultresponse, 0),
}
for _, pd := range pds {
desc := pd.Spec.Desc
if desc == "" {
desc = pd.Name
}
// Ignore the protected-b poddefault
labelMapped := reflect.ValueOf(pd.Spec.Selector.MatchLabels).MapKeys()[0].String()
if labelMapped != "notebook.statcan.gc.ca/protected-b" {
resp.PodDefaults = append(resp.PodDefaults, poddefaultresponse{
PodDefault: *pd,
Label: labelMapped,
Description: desc,
})
}
}
s.respond(w, r, resp)
}