Skip to content

Commit

Permalink
Update to add interval opetion for migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Aug 9, 2024
1 parent 7b602a9 commit 4049615
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions migrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"time"

"github.com/cnrancher/rancher-flat-network/pkg/upgrade"
"github.com/cnrancher/rancher-flat-network/pkg/utils"
Expand All @@ -15,9 +16,11 @@ import (
var (
kubeConfigFile string
workloadKinds string
versionString string
interval time.Duration
version bool
debug bool

versionString string
)

func init() {
Expand All @@ -32,6 +35,7 @@ func main() {
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Kube-config file (optional)")
flag.StringVar(&workloadKinds, "workload",
"deployment,daemonset,statefulset,replicaset,cronjob,job", "Workload kinds, separated by comma")
flag.DurationVar(&interval, "interval", time.Second, "The interval between Kube API requests")
flag.BoolVar(&version, "v", false, "Output version")
flag.Parse()

Expand All @@ -50,7 +54,7 @@ func main() {
logrus.Fatalf("Error building kubeconfig: %v", err)
}

m := upgrade.NewResourceMigrator(cfg, workloadKinds)
m := upgrade.NewResourceMigrator(cfg, workloadKinds, interval)
if err := m.Run(ctx); err != nil {
logrus.Fatal(err)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/upgrade/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/cnrancher/rancher-flat-network/pkg/controller/wrangler"
"github.com/sirupsen/logrus"
Expand All @@ -19,11 +20,14 @@ type migrator struct {
wctx *wrangler.Context
dynamicClientSet *dynamic.DynamicClient
workloadKinds []string
interval time.Duration
}

var _ Migrator = &migrator{}

func NewResourceMigrator(cfg *rest.Config, workloadKinds string) Migrator {
func NewResourceMigrator(
cfg *rest.Config, workloadKinds string, interval time.Duration,
) Migrator {
wctx := wrangler.NewContextOrDie(cfg)
dc := dynamic.NewForConfigOrDie(cfg)
spec := strings.Split(strings.TrimSpace(workloadKinds), ",")
Expand All @@ -38,6 +42,7 @@ func NewResourceMigrator(cfg *rest.Config, workloadKinds string) Migrator {
wctx: wctx,
dynamicClientSet: dc,
workloadKinds: kinds,
interval: interval,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/upgrade/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (m *migrator) migrateSubnet(ctx context.Context) error {
} else {
logrus.Infof("created FlatNetworkSubnet [%v]", fs.Name)
}
time.Sleep(time.Millisecond * 500)
time.Sleep(m.interval)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/upgrade/workloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (m *migrator) processPodTemplateAnnotation(o metav1.Object) error {
return fmt.Errorf("failed to update workload %T [%v/%v]: %w",
o, o.GetNamespace(), o.GetName(), err)
}
time.Sleep(time.Millisecond * 500)
time.Sleep(m.interval)
return nil
}

Expand Down

0 comments on commit 4049615

Please sign in to comment.