Skip to content

Commit

Permalink
Merge pull request #132 from szy441687879/bug-fix-use-crane-agent-exa…
Browse files Browse the repository at this point in the history
…mples

fix bug when use crane-agent first
  • Loading branch information
mfanjie authored Feb 14, 2022
2 parents 55d8a29 + 7eccad8 commit 945b000
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cmd/crane-agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -144,5 +143,5 @@ func getHostName(override string) string {
if len(override) != 0 {
nodeName = override
}
return nodeName + "_" + string(uuid.NewUUID())
return nodeName
}
7 changes: 6 additions & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
coreinformers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -51,7 +52,7 @@ func NewAgent(ctx context.Context,

return &Agent{
ctx: ctx,
name: nodeName,
name: getAgentName(nodeName),
kubeClient: kubeClient,
craneClient: craneClient,
managers: managers,
Expand All @@ -68,3 +69,7 @@ func (a *Agent) Run() {
<-a.ctx.Done()

}

func getAgentName(nodeName string) string {
return nodeName + "_" + string(uuid.NewUUID())
}
2 changes: 1 addition & 1 deletion pkg/ensurance/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *StateCollector) UpdateCollectors() {
continue
}
nodeLocal = true
if _, exists := s.collectors.Load(types.NodeLocalCollectorType); exists {
if _, exists := s.collectors.Load(types.NodeLocalCollectorType); !exists {
nc := nodelocal.NewNodeLocal(s.podLister, s.ifaces)
s.collectors.Store(types.NodeLocalCollectorType, nc)
break
Expand Down

0 comments on commit 945b000

Please sign in to comment.