Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"os"
"sync"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -266,6 +267,7 @@ func (a *Agent) Stop() {
defer a.stopLock.Unlock()

if a.stopC != nil {
a.clearOwnConfigStatus()
close(a.stopC)
<-a.doneC
a.stopC = nil
Expand Down Expand Up @@ -633,6 +635,31 @@ func (a *Agent) updateConfig(cfg metav1.Object) {
a.configure(cfg)
}

// clearOwnConfigStatus nulls this node's Status.nodes entry on the current
// config resource so a clean shutdown does not leave a permanent orphan.
func (a *Agent) clearOwnConfigStatus() {
if a.cfgIf == nil || a.nodeName == "" || a.hasLocalConfig() || a.currentCfg == nil {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

ns := a.namespace
name := a.currentCfg.GetName()
node := a.nodeName

data, pt, err := cfgapi.NodeStatusPatch(node, nil)
if err == nil {
err = a.cfgIf.PatchStatus(ctx, ns, name, pt, data, metav1.PatchOptions{})
}
if err != nil {
log.Errorf("failed to clear own config status on %s/%s: %v", ns, name, err)
return
}
log.Infof("cleared own config status on %s/%s", ns, name)
}

func (a *Agent) patchConfigStatus(prev, curr metav1.Object, errors error) {
if a.cfgIf == nil {
return
Expand Down
Loading