-
Notifications
You must be signed in to change notification settings - Fork 209
/
bgp.go
61 lines (51 loc) · 1.48 KB
/
bgp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package bgp
import (
"context"
"fmt"
"io"
"time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/cilium/cilium-cli/k8s"
)
// Parameters contains options for CLI
type Parameters struct {
CiliumNamespace string
AgentPodSelector string
NodeName string
Writer io.Writer
WaitDuration time.Duration
Output string
}
// Status is used to get bgp state from cilium agents
type Status struct {
client *k8s.Client
params Parameters
ciliumPods []*corev1.Pod
}
// NewStatus returns new bgp.Status struct
func NewStatus(client *k8s.Client, p Parameters) *Status {
return &Status{
client: client,
params: p,
}
}
// initTargetCiliumPods stores cilium agent pods in the status.ciliumPods.
// If node selector option is specified then only that nodes' cilium-agent
// pod is stored else all cilium-agents in the cluster are stored.
func (s *Status) initTargetCiliumPods(ctx context.Context) error {
opts := metav1.ListOptions{LabelSelector: s.params.AgentPodSelector}
if s.params.NodeName != "" {
opts.FieldSelector = fmt.Sprintf("spec.nodeName=%s", s.params.NodeName)
}
ciliumPods, err := s.client.ListPods(ctx, s.params.CiliumNamespace, opts)
if err != nil {
return fmt.Errorf("unable to list Cilium pods: %w", err)
}
for _, ciliumPod := range ciliumPods.Items {
s.ciliumPods = append(s.ciliumPods, ciliumPod.DeepCopy())
}
return nil
}