Skip to content

Commit

Permalink
Added configuration for pulic-ip through node annotation
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Bonafiglia <roberto.bonafiglia@suse.com>
  • Loading branch information
rbrtbnfgl committed Apr 17, 2024
1 parent f0215be commit db4f771
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
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) GetStoredMacAddress(ctx context.Context) string {
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 @@ -631,3 +631,22 @@ func (ksm *kubeSubnetManager) GetStoredMacAddress(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

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

Expand Down

0 comments on commit db4f771

Please sign in to comment.