Skip to content

Commit

Permalink
Merge pull request #88 from flatcar-linux/invidian/agent-improvements
Browse files Browse the repository at this point in the history
pkg/agent: improvements
  • Loading branch information
invidian authored Jan 6, 2022
2 parents 64b7f88 + c20a6f2 commit c180704
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 115 deletions.
37 changes: 32 additions & 5 deletions cmd/update-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import (
"os"
"time"

"github.com/coreos/go-systemd/v22/login1"
"github.com/coreos/pkg/flagutil"
"k8s.io/klog/v2"

"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/agent"
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/dbus"
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/k8sutil"
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/updateengine"
"github.com/flatcar-linux/flatcar-linux-update-operator/pkg/version"
)

Expand Down Expand Up @@ -39,13 +43,36 @@ func main() {
os.Exit(0)
}

if *node == "" {
klog.Fatal("-node is required")
clientset, err := k8sutil.GetClient("")
if err != nil {
klog.Fatalf("Failed creating Kubernetes client: %v", err)
}

rt := time.Duration(*reapTimeout) * time.Second
updateEngineClient, err := updateengine.New(dbus.SystemPrivateConnector)
if err != nil {
klog.Fatalf("Failed establishing connection to update_engine dbus: %v", err)
}

defer func() {
if err := updateEngineClient.Close(); err != nil {
klog.Warningf("Failed gracefully closing update_engine client: %v", err)
}
}()

rebooter, err := login1.New()
if err != nil {
klog.Fatalf("Failed establishing connection to logind dbus: %v", err)
}

config := &agent.Config{
NodeName: *node,
PodDeletionGracePeriod: time.Duration(*reapTimeout) * time.Second,
Clientset: clientset,
StatusReceiver: updateEngineClient,
Rebooter: rebooter,
}

a, err := agent.New(*node, rt)
agent, err := agent.New(config)
if err != nil {
klog.Fatalf("Failed to initialize %s: %v", os.Args[0], err)
}
Expand All @@ -55,5 +82,5 @@ func main() {
// Run agent until the stop channel is closed
stop := make(chan struct{})
defer close(stop)
a.Run(stop)
agent.Run(stop)
}
Loading

0 comments on commit c180704

Please sign in to comment.