diff --git a/demo/handlers.go b/demo/handlers.go index b1a0b25..949fbc6 100644 --- a/demo/handlers.go +++ b/demo/handlers.go @@ -19,9 +19,9 @@ func registerPodHTTPHandler(mux *http.ServeMux, db *statedb.DB, pods statedb.Tab txn := db.ReadTxn() iter, _ := pods.Get(txn, PodPhaseIndex.Query(v1.PodRunning)) t := tabwriter.NewWriter(w, 10, 4, 2, ' ', 0) - fmt.Fprintf(t, "NAME\tSTARTED\tPOD IP\tSTATUS\n") + fmt.Fprintf(t, "NAME\tSTARTED\tSTATUS\n") for pod, _, ok := iter.Next(); ok; pod, _, ok = iter.Next() { - fmt.Fprintf(t, "%s/%s\t%s ago\t%s\t%s\n", pod.Namespace, pod.Name, time.Since(pod.Status.StartTime.Time), pod.Status.PodIP, pod.ReconciliationStatus()) + fmt.Fprintf(t, "%s/%s\t%s ago\t\t%s\n", pod.Namespace, pod.Name, time.Since(pod.StartTime), pod.ReconciliationStatus()) } t.Flush() }) diff --git a/demo/main.go b/demo/main.go index 4b93408..ac809ce 100644 --- a/demo/main.go +++ b/demo/main.go @@ -86,7 +86,7 @@ func podReflectorConfig(client *kubernetes.Clientset, pods statedb.RWTable[*Pod] Transform: func(obj any) (*Pod, bool) { pod, ok := obj.(*v1.Pod) if ok { - return &Pod{Pod: pod, reconciliationStatus: reconciler.StatusPending()}, true + return fromV1Pod(pod), true } return nil, false }, diff --git a/demo/reconciler.go b/demo/reconciler.go index 1fcb023..e08c0ed 100644 --- a/demo/reconciler.go +++ b/demo/reconciler.go @@ -26,7 +26,7 @@ func (o *podOps) Prune(context.Context, statedb.ReadTxn, statedb.Iterator[*Pod]) // Update implements reconciler.Operations. func (o *podOps) Update(ctx context.Context, txn statedb.ReadTxn, pod *Pod, changed *bool) error { - o.log.Info("Pod updated", "name", pod.Namespace+"/"+pod.Name, "phase", pod.Status.Phase) + o.log.Info("Pod updated", "name", pod.Namespace+"/"+pod.Name, "phase", pod.Phase) return nil } diff --git a/demo/tables.go b/demo/tables.go index a2d9397..4b39dbe 100644 --- a/demo/tables.go +++ b/demo/tables.go @@ -1,6 +1,8 @@ package main import ( + "time" + v1 "k8s.io/api/core/v1" "github.com/cilium/statedb" @@ -9,17 +11,31 @@ import ( ) type Pod struct { - *v1.Pod + Name, Namespace string + Phase v1.PodPhase + StartTime time.Time reconciliationStatus reconciler.Status } +func fromV1Pod(p *v1.Pod) *Pod { + return &Pod{ + Name: p.Name, + Namespace: p.Namespace, + Phase: p.Status.Phase, + StartTime: p.Status.StartTime.Time, + reconciliationStatus: reconciler.StatusPending(), + } +} + func (p *Pod) ReconciliationStatus() reconciler.Status { return p.reconciliationStatus } func (p *Pod) WithReconciliationStatus(s reconciler.Status) *Pod { - return &Pod{Pod: p.Pod, reconciliationStatus: s} + p2 := *p + p2.reconciliationStatus = s + return &p2 } const PodTableName = "pods" @@ -36,7 +52,7 @@ var ( PodPhaseIndex = statedb.Index[*Pod, v1.PodPhase]{ Name: "phase", FromObject: func(pod *Pod) index.KeySet { - return index.NewKeySet(index.String(string(pod.Status.Phase))) + return index.NewKeySet(index.String(string(pod.Phase))) }, FromKey: func(key v1.PodPhase) index.Key { return index.String(string(key))