Skip to content

Commit

Permalink
Increment tunnel ID before startup
Browse files Browse the repository at this point in the history
Signed-off-by: Toby Cabot <[email protected]>
  • Loading branch information
caboteria committed Nov 24, 2023
1 parent f224731 commit 4e5e7e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/v1/epic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"net"
"os"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"github.com/go-logr/logr"
"github.com/vishvananda/netlink"
"github.com/vishvananda/netlink/nl"
Expand Down Expand Up @@ -172,7 +174,14 @@ func addrFamily(lbIP net.IP) (lbIPFamily int) {
// this call succeeds (i.e., error is nil) then the returned ID will
// be unique.
func AllocateTunnelID(ctx context.Context, l logr.Logger, cl client.Client) (tunnelID uint32, err error) {
return tunnelID, retry.RetryOnConflict(retry.DefaultRetry, func() error {
var Retry = wait.Backoff{
Steps: 5,
Duration: 2 * time.Second,
Factor: 1.0,
Jitter: 0.1,
}

return tunnelID, retry.RetryOnConflict(Retry, func() error {
var epic EPIC

// Fetch the resource here; you need to refetch it on every try,
Expand Down
15 changes: 15 additions & 0 deletions cmd/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"fmt"

marin3r "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1"
marin3roperator "github.com/3scale-ops/marin3r/apis/operator.marin3r/v1alpha1"
Expand Down Expand Up @@ -182,6 +183,20 @@ func prebootCleanup(ctx context.Context, log logr.Logger) error {
return err
}

// Allocate a tunnel ID so we start at 1 (yes, we will waste
// some but they're plentiful).
var epic epicv1.EPIC
err = fmt.Errorf("Placeholder")
for err != nil {
err = cl.Get(ctx, client.ObjectKey{Namespace: epicv1.ConfigNamespace, Name: epicv1.ConfigName}, &epic)
if err != nil {
log.Info("can't find EPIC singleton", "message", err)
}
}
if _, err := epicv1.AllocateTunnelID(ctx, log, cl); err != nil {
log.Error(err, "incrementing tunnel ID")
}

// "Nudge" the proxy pods to trigger the python daemon to
// re-populate the ifindex and ifname annotations
proxies, err := listProxyPods(ctx, cl)
Expand Down

0 comments on commit 4e5e7e9

Please sign in to comment.