Skip to content

Commit

Permalink
Restrict events to currently active DaemonSet
Browse files Browse the repository at this point in the history
  • Loading branch information
nfisher committed May 21, 2021
1 parent a230ff3 commit 7509c3e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cluster/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ func (q *KubernetesQuery) AllPods() ([]PodInfo, error) {
return podList, nil
}

// AgentEvent represents a single K8S event associated with the agent.
type AgentEvent struct {
EventTime time.Time
Reason string
Message string
}

// AgentInfo provides general information relating to the agent.
type AgentInfo struct {
Available int32
Desired int32
Expand All @@ -158,9 +160,16 @@ type AgentInfo struct {
Unavailable int32
}

// AgentInfo queries the api-server for details about the Instana agent.
func (q *KubernetesQuery) AgentInfo(namespace string, name string) (*AgentInfo, error) {
ds, err := q.apps.DaemonSets(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}

uid := string(ds.UID)
eventInterface := q.core.Events(namespace)
selector := eventInterface.GetFieldSelector(&name, &namespace, nil, nil)
selector := eventInterface.GetFieldSelector(&name, &namespace, nil, &uid)
opts := metav1.ListOptions{
FieldSelector: selector.String(),
}
Expand All @@ -179,11 +188,6 @@ func (q *KubernetesQuery) AgentInfo(namespace string, name string) (*AgentInfo,
events = append(events, event)
}

ds, err := q.apps.DaemonSets(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}

info := &AgentInfo{
Available: ds.Status.NumberAvailable,
Desired: ds.Status.DesiredNumberScheduled,
Expand Down

0 comments on commit 7509c3e

Please sign in to comment.