Skip to content

Commit

Permalink
fix: log in every 15 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard committed Oct 30, 2023
1 parent 0077d6b commit 40b34d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
8 changes: 0 additions & 8 deletions pkg/controllers/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ func (c *NodeManager) nodeAdd(obj interface{}) {
}
defer client.Close()

// TODO: Login every 30 minutes
err = c.wattTimeClient.Login()
if err != nil {
log.Printf("failed to login: %v\n", err)

return
}

index, err := c.wattTimeClient.Index()
if err != nil {
log.Printf("failed to get index: %v\n", err)
Expand Down
7 changes: 0 additions & 7 deletions pkg/controllers/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ func (c *PodManager) podAdd(obj interface{}) {
return
}

// TODO: Login every 30 minutes
err := c.wattTimeClient.Login()
if err != nil {
log.Printf("failed to login: %v\n", err)
return
}

index, err := c.wattTimeClient.Index()
if err != nil {
log.Printf("failed to get index: %v\n", err)
Expand Down
20 changes: 20 additions & 0 deletions pkg/plugins/emissions/emissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package emissions
import (
"context"
"fmt"
"log"
"time"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -54,6 +55,12 @@ func New(obj runtime.Object, h framework.Handle) (framework.Plugin, error) {
}

wattTimeClient := watttime.NewClient(args.WattTimeUsername, args.WattTimePassword, args.WattTimeBA)
err = wattTimeClient.Login()
if err != nil {
log.Printf("failed to login to WattTime: %v\n", err)
}

go wattTimeLoginLoop(wattTimeClient)

nodeFactory := informers.NewSharedInformerFactory(clientset, 5*time.Minute)
nodeManager, err := node.NewNodeManager(nodeFactory, clientset, wattTimeClient)
Expand Down Expand Up @@ -110,3 +117,16 @@ func (e *Emissions) PreFilter(ctx context.Context, state *framework.CycleState,
func (e *Emissions) PreFilterExtensions() framework.PreFilterExtensions {
return nil
}

func wattTimeLoginLoop(wattTimeClient *watttime.Client) {
tick := time.Tick(15 * time.Minute)

for {
<-tick

err := wattTimeClient.Login()
if err != nil {
log.Printf("failed to login to WattTime: %v\n", err)
}
}
}

0 comments on commit 40b34d2

Please sign in to comment.