Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy of annotations into CiliumNode #25307

Merged
merged 1 commit into from May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 18 additions & 13 deletions pkg/node/types/node.go
Expand Up @@ -84,14 +84,30 @@ func ParseCiliumNode(n *ciliumv2.CiliumNode) (node Node) {
return
}

// GetCiliumAnnotations returns the node annotations that should be set on the CiliumNode
func (n *Node) GetCiliumAnnotations() map[string]string {
annotations := map[string]string{}
if n.WireguardPubKey != "" {
annotations[annotation.WireguardPubKey] = n.WireguardPubKey
}

// if we use a cilium node instead of a node, we also need the BGP Control Plane annotations in the cilium node instead of the main node
for k, a := range n.Annotations {
if strings.HasPrefix(k, annotation.BGPVRouterAnnoPrefix) {
annotations[k] = a
}
}

return annotations
}

// ToCiliumNode converts the node to a CiliumNode
func (n *Node) ToCiliumNode() *ciliumv2.CiliumNode {
var (
podCIDRs []string
ipAddrs []ciliumv2.NodeAddress
healthIPv4, healthIPv6 string
ingressIPv4, ingressIPv6 string
annotations = map[string]string{}
)

if n.IPv4AllocCIDR != nil {
Expand Down Expand Up @@ -126,22 +142,11 @@ func (n *Node) ToCiliumNode() *ciliumv2.CiliumNode {
})
}

if n.WireguardPubKey != "" {
annotations[annotation.WireguardPubKey] = n.WireguardPubKey
}

// if we use a cilium node instead of a node, we also need the BGP Control Plane annotations in the cilium node instead of the main node
for k, a := range n.Annotations {
if strings.HasPrefix(k, annotation.BGPVRouterAnnoPrefix) {
annotations[k] = a
}
}

return &ciliumv2.CiliumNode{
ObjectMeta: v1.ObjectMeta{
Name: n.Name,
Labels: n.Labels,
Annotations: annotations,
Annotations: n.GetCiliumAnnotations(),
},
Spec: ciliumv2.NodeSpec{
Addresses: ipAddrs,
Expand Down
8 changes: 4 additions & 4 deletions pkg/nodediscovery/nodediscovery.go
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/cilium/cilium/pkg/node/addressing"
nodemanager "github.com/cilium/cilium/pkg/node/manager"
nodestore "github.com/cilium/cilium/pkg/node/store"
"github.com/cilium/cilium/pkg/node/types"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/source"
Expand Down Expand Up @@ -328,7 +327,7 @@ func (n *NodeDiscovery) UpdateLocalNode() {

// LocalNode syncs the localNode object with the information stored in the node
// package and then returns a copy of the localNode object
func (n *NodeDiscovery) LocalNode() *types.Node {
func (n *NodeDiscovery) LocalNode() *nodeTypes.Node {
n.localNodeLock.Lock()
defer n.localNodeLock.Unlock()

Expand Down Expand Up @@ -454,8 +453,9 @@ func (n *NodeDiscovery) mutateNodeResource(nodeResource *ciliumv2.CiliumNode) er

nodeResource.ObjectMeta.Labels = k8sNodeParsed.Labels

localCN := n.localNode.ToCiliumNode()
nodeResource.ObjectMeta.Annotations = localCN.Annotations
// This is for syncing relevant node annotations from the k8s node to the
// CiliumNode object
nodeResource.ObjectMeta.Annotations = k8sNodeParsed.GetCiliumAnnotations()

for _, k8sAddress := range k8sNodeAddresses {
// Do not add CiliumNodeInternalIP from the k8sNodeAddress. The source
Expand Down