Skip to content

Commit

Permalink
fix: update node manager logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard committed Nov 2, 2023
1 parent ed70cec commit 11ca6b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
with:
platforms: linux/amd64,linux/arm64

- name: Set up Go
-
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '^1.13.1'
Expand Down
49 changes: 24 additions & 25 deletions pkg/controllers/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,10 @@ func (c *NodeManager) nodeAdd(obj interface{}) {
return
}

log.Printf("node %q is candidate", node.Name)
log.Printf("node %q has BMC annotations", node.Name)

bmcInfo := &bmc.BMCInfo{Endpoint: endpoint, User: user, Pass: pass}

if isIdle(node) {
log.Printf("node %q is idle", node.Name)
}

client, err := bmc.NewClient(bmcInfo)
if err != nil {
log.Printf("failed to create IPMI client: %v\n", err)
Expand All @@ -81,45 +77,44 @@ func (c *NodeManager) nodeAdd(obj interface{}) {
return
}

pod, err := podInQueueThatFits(c.clientset, index)
podIsInQueueThatFits, err := podInQueueThatFits(c.clientset, index)
if err != nil {
log.Printf("failed to determine if a pod is in the queue: %v", err)

return
}

if pod {
log.Printf("pod(s) in queue that can fit node")

// Ensure is powered on.
log.Printf("node %q is idle", node.Name)
} else {
// ?
}

isPoweredOn, err := client.IsPoweredOn()
if err != nil {
log.Printf("failed to determine current power status of %q: %v", node.Name, err)

return
}

// TODO: Make this configurable.
if index > 50 {
if podIsInQueueThatFits {
log.Printf("pod(s) in queue that can fit node")

if isPoweredOn {
// Nothing to do.
return
}

if !isPoweredOn {
log.Printf("index is %d%%, powering off %q", index, node.Name)

client.PowerOff()
} else {
log.Printf("node is in desired power state (off): %q", node.Name)
err = client.PowerOn()
if err != nil {
log.Printf("failed to power on node %q", node.Name)
}
}
} else {
if isPoweredOn {
log.Printf("node is in desired power state (on): %q", node.Name)
} else {
log.Printf("index is %d%%, powering on %q", index, node.Name)
if isIdle(node) {
log.Printf("node %q is idle, powering off", node.Name)

client.PowerOn()
err = client.PowerOff()
if err != nil {
log.Printf("failed to power off node %q", node.Name)
}
}
}
}
Expand Down Expand Up @@ -170,6 +165,10 @@ func podInQueueThatFits(clientset *kubernetes.Clientset, index int) (bool, error
}

for _, pod := range pods.Items {
if pod.Spec.SchedulerName != "kube-scheduler-siderolabs" {
continue
}

if pod.Status.Phase == v1.PodPending {
if pod.Spec.Priority != nil && *pod.Spec.Priority >= int32(index) {
return true, nil
Expand Down

0 comments on commit 11ca6b1

Please sign in to comment.