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

Added configuration for pulic-ip through node annotation #1948

Merged
merged 1 commit into from
Apr 22, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Documentation/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ If you want to deploy `flannel` securely in a shared namespace or want more fine
Other options include [Kyverno](https://kyverno.io/policies/pod-security/) and [OPA Gatekeeper](https://github.com/open-policy-agent/gatekeeper).
# Annotations

* `flannel.alpha.coreos.com/public-ip-overwrite`: Allows to overwrite the public IP of a node. Useful if the public IP can not determined from the node, e.G. because it is behind a NAT. It can be automatically set to a nodes `ExternalIP` using the [flannel-node-annotator](https://github.com/alvaroaleman/flannel-node-annotator)
* `flannel.alpha.coreos.com/public-ip`, `flannel.alpha.coreos.com/public-ipv6`: Define the used public IP of the node. If configured when Flannel starts it'll be used as the `public-ip` and `public-ipv6` flag.
* `flannel.alpha.coreos.com/public-ip-overwrite`, `flannel.alpha.coreos.com/public-ipv6-overwrite`: Allows to overwrite the public IP of a node. Useful if the public IP can not determined from the node, e.G. because it is behind a NAT. It can be automatically set to a nodes `ExternalIP` using the [flannel-node-annotator](https://github.com/alvaroaleman/flannel-node-annotator)

## Older versions of Kubernetes

Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ func main() {

// Work out which interface to use
var extIface *backend.ExternalInterface

annotatedPublicIP, annotatedPublicIPv6 := sm.GetStoredPublicIP(ctx)
if annotatedPublicIP != "" {
opts.publicIP = annotatedPublicIP
}
if annotatedPublicIPv6 != "" {
opts.publicIPv6 = annotatedPublicIPv6
}

optsPublicIP := ipmatch.PublicIPOpts{
PublicIP: opts.publicIP,
PublicIPv6: opts.publicIPv6,
Expand Down
4 changes: 4 additions & 0 deletions pkg/subnet/etcd/local_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (m *LocalManager) GetStoredMacAddresses(ctx context.Context) (string, strin
return "", ""
}

func (m *LocalManager) GetStoredPublicIP(ctx context.Context) (string, string) {
return "", ""
}

func (m *LocalManager) GetNetworkConfig(ctx context.Context) (*subnet.Config, error) {
cfg, err := m.registry.getNetworkConfig(ctx)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions pkg/subnet/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,22 @@ func (ksm *kubeSubnetManager) GetStoredMacAddresses(ctx context.Context) (string

return "", ""
}

// GetStoredPublicIP reads if there are any public IP configured as annotation when flannel starts
func (ksm *kubeSubnetManager) GetStoredPublicIP(ctx context.Context) (string, string) {
// get mac info from Name func.
node, err := ksm.client.CoreV1().Nodes().Get(ctx, ksm.nodeName, metav1.GetOptions{})
if err != nil {
log.Errorf("Failed to get node for backend data: %v", err)
return "", ""
}

if node != nil && node.Annotations != nil {
log.Infof("List of node(%s) annotations: %#+v", ksm.nodeName, node.Annotations)
publicIP := node.Annotations[ksm.annotations.BackendPublicIP]
publicIPv6 := node.Annotations[ksm.annotations.BackendPublicIPv6]
return publicIP, publicIPv6
}

return "", ""
}
1 change: 1 addition & 0 deletions pkg/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type Manager interface {
CompleteLease(ctx context.Context, lease *lease.Lease, wg *sync.WaitGroup) error

GetStoredMacAddresses(ctx context.Context) (string, string)
GetStoredPublicIP(ctx context.Context) (string, string)
Name() string
}

Expand Down
Loading