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

node: Add WireguardPubKey to ToCiliumNode #16420

Merged
merged 2 commits into from
Jun 8, 2021
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
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Jenkinsfile.nightly @cilium/ci-structure
/pkg/mountinfo @cilium/bpf
/pkg/mtu @cilium/bpf
/pkg/multicast @cilium/bpf
/pkg/node @cilium/agent
/pkg/option @cilium/agent @cilium/cli
/pkg/pidfile @cilium/agent
/pkg/policy @cilium/policy
Expand Down
11 changes: 9 additions & 2 deletions pkg/node/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (n *Node) ToCiliumNode() *ciliumv2.CiliumNode {
podCIDRs []string
ipAddrs []ciliumv2.NodeAddress
healthIPv4, healthIPv6 string
annotations = map[string]string{}
)

if n.IPv4AllocCIDR != nil {
Expand All @@ -114,10 +115,15 @@ func (n *Node) ToCiliumNode() *ciliumv2.CiliumNode {
})
}

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

return &ciliumv2.CiliumNode{
ObjectMeta: v1.ObjectMeta{
Name: n.Name,
Labels: n.Labels,
Name: n.Name,
Labels: n.Labels,
Annotations: annotations,
},
Spec: ciliumv2.NodeSpec{
Addresses: ipAddrs,
Expand Down Expand Up @@ -196,6 +202,7 @@ type Node struct {
// NodeIdentity is the numeric identity allocated for the node
NodeIdentity uint32

// WireguardPubKey is the WireGuard public key of this node
WireguardPubKey string
}

Expand Down
22 changes: 15 additions & 7 deletions pkg/node/types/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net"
"testing"

"github.com/cilium/cilium/pkg/annotation"
"github.com/cilium/cilium/pkg/checker"
"github.com/cilium/cilium/pkg/cidr"
ipamTypes "github.com/cilium/cilium/pkg/ipam/types"
Expand Down Expand Up @@ -188,17 +189,24 @@ func (s *NodeSuite) TestNode_ToCiliumNode(c *C) {
{Type: addressing.NodeInternalIP, IP: net.ParseIP("c0de::1")},
{Type: addressing.NodeExternalIP, IP: net.ParseIP("c0de::2")},
},
EncryptionKey: uint8(10),
IPv4AllocCIDR: cidr.MustParseCIDR("10.10.0.0/16"),
IPv6AllocCIDR: cidr.MustParseCIDR("c0de::/96"),
IPv4HealthIP: net.ParseIP("1.1.1.1"),
IPv6HealthIP: net.ParseIP("c0de::1"),
NodeIdentity: uint32(12345),
EncryptionKey: uint8(10),
IPv4AllocCIDR: cidr.MustParseCIDR("10.10.0.0/16"),
IPv6AllocCIDR: cidr.MustParseCIDR("c0de::/96"),
IPv4HealthIP: net.ParseIP("1.1.1.1"),
IPv6HealthIP: net.ParseIP("c0de::1"),
NodeIdentity: uint32(12345),
WireguardPubKey: "6kiIGGPvMiadJ1brWTVfSGXheE3e3k5GjDTxfjMLYx8=",
}

n := nodeResource.ToCiliumNode()
c.Assert(n, checker.DeepEquals, &ciliumv2.CiliumNode{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ""},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "",
Annotations: map[string]string{
annotation.WireguardPubKey: "6kiIGGPvMiadJ1brWTVfSGXheE3e3k5GjDTxfjMLYx8=",
},
},
Spec: ciliumv2.NodeSpec{
Addresses: []ciliumv2.NodeAddress{
{Type: addressing.NodeInternalIP, IP: "2.2.2.2"},
Expand Down