Skip to content

Commit

Permalink
Displays status for components on homescreen
Browse files Browse the repository at this point in the history
Queried using K8s API
  • Loading branch information
liamrathke committed Jul 19, 2021
1 parent 6250187 commit 60392a1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
4 changes: 2 additions & 2 deletions pkg/kubeflow/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetDashboardPod(cc utilities.ClientContext) (PodInfo, error) {
}

func GetPodInfo(cc utilities.ClientContext, podSpec PodSpec) (PodInfo, error) {
pods, err := GetPodsInNamespace(cc, podSpec.Namespace)
pods, err := getPodsInNamespace(cc, podSpec.Namespace)
if err != nil {
return PodInfo{}, nil
}
Expand All @@ -68,7 +68,7 @@ func GetPodInfo(cc utilities.ClientContext, podSpec PodSpec) (PodInfo, error) {
return PodInfo{}, nil
}

func GetPodsInNamespace(cc utilities.ClientContext, namespace string) ([]corev1.Pod, error) {
func getPodsInNamespace(cc utilities.ClientContext, namespace string) ([]corev1.Pod, error) {
unstructuredPods, err := cc.List(store.Key{
APIVersion: "v1",
Kind: "Pod",
Expand Down
41 changes: 27 additions & 14 deletions pkg/kubeflow/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ package kubeflow // import "github.com/liamrathke/octant-kubeflow/pkg/kubeflow"

import (
"github.com/liamrathke/octant-kubeflow/pkg/plugin/utilities"
corev1 "k8s.io/api/core/v1"
)

type KubeflowStatus struct {
ServiceName string
OK bool
}

type ComponentStatus struct {
Name string
Namespace string
Expand All @@ -40,18 +36,35 @@ var COMPONENTS = []ComponentStatus{
{Name: "Knative (Eventing)", Namespace: "knative-eventing"},
{Name: "Knative (Serving)", Namespace: "knative-serving"},
{Name: "Kubeflow", Namespace: "kubeflow"},
{Name: "Kubeflow Example", Namespace: "kubeflow-user-example-com"},
}

func GetStatus(cc utilities.ClientContext) []KubeflowStatus {
return []KubeflowStatus{
{ServiceName: "Test1", OK: true},
{ServiceName: "Test2", OK: true},
{ServiceName: "Test3", OK: true},
{ServiceName: "Test4", OK: true},
func GetStatus(cc utilities.ClientContext) []ComponentStatus {
statuses := make([]ComponentStatus, len(COMPONENTS))

for c := range COMPONENTS {
statuses[c], _ = getStatusForComponent(cc, COMPONENTS[c])
}

return statuses
}

func statusForComponent(cc utilities.ClientContext, component ComponentStatus) ComponentStatus {
return ComponentStatus{}
func getStatusForComponent(cc utilities.ClientContext, component ComponentStatus) (ComponentStatus, error) {
pods, err := getPodsInNamespace(cc, component.Namespace)
if err != nil {
return ComponentStatus{}, err
}

for _, pod := range pods {
component.TotalPods++

if true { // fix!
component.ReadyPods++
}

if pod.Status.Phase == corev1.PodRunning {
component.RunningPods++
}
}

return component, err
}
23 changes: 15 additions & 8 deletions pkg/plugin/views/root/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,35 @@ limitations under the License.
package root // import "github.com/liamrathke/octant-kubeflow/pkg/plugin/views/root"

import (
"fmt"

"github.com/vmware-tanzu/octant/pkg/view/component"

"github.com/liamrathke/octant-kubeflow/pkg/kubeflow"
"github.com/liamrathke/octant-kubeflow/pkg/plugin/utilities"
)

const (
COMPONENT = "Kubeflow Component"
READY = "Ready Pods"
RUNNING = "Running Pods"
TOTAL = "Total Pods"
)

func BuildStatusTable(cc utilities.ClientContext) *component.Table {
table := component.NewTableWithRows(
"Status", "No Kubeflow services found!",
component.NewTableCols("Service", "Status"),
component.NewTableCols(COMPONENT, READY, RUNNING, TOTAL),
[]component.TableRow{})

for _, s := range kubeflow.GetStatus(cc) {
for _, status := range kubeflow.GetStatus(cc) {
tr := component.TableRow{
"Service": component.NewText(s.ServiceName),
COMPONENT: component.NewText(status.Name),
READY: component.NewText(fmt.Sprint(status.ReadyPods)),
RUNNING: component.NewText(fmt.Sprint(status.RunningPods)),
TOTAL: component.NewText(fmt.Sprint(status.TotalPods)),
}

if s.OK {
tr["Status"] = component.NewIcon("success-standard")
} else {
tr["Status"] = component.NewIcon("error-standard")
}
table.Add(tr)
}

Expand Down

0 comments on commit 60392a1

Please sign in to comment.