diff --git a/pkg/cloudscale_ccm/reconcile.go b/pkg/cloudscale_ccm/reconcile.go index ef7596a..8eb85de 100644 --- a/pkg/cloudscale_ccm/reconcile.go +++ b/pkg/cloudscale_ccm/reconcile.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" "slices" "strings" "time" @@ -749,9 +748,7 @@ func reconcileLbState( break } - // Wait between 5-7.5 seconds between state fetches - // #nosec G404 - wait := time.Duration(5000+rand.Intn(2500)) * time.Millisecond + wait := 500 * time.Millisecond select { case <-ctx.Done(): diff --git a/pkg/internal/actions/actions.go b/pkg/internal/actions/actions.go index 62ca4fb..02b1965 100644 --- a/pkg/internal/actions/actions.go +++ b/pkg/internal/actions/actions.go @@ -9,6 +9,7 @@ import ( "time" "github.com/cloudscale-ch/cloudscale-go-sdk/v6" + "k8s.io/klog/v2" ) type Action interface { @@ -50,6 +51,18 @@ func (a *CreateLbAction) Label() string { func (a *CreateLbAction) Run( ctx context.Context, client *cloudscale.Client) (Control, error) { + existing, err := client.LoadBalancers.List(ctx) + if err == nil { + for _, lb := range existing { + if lb.Name == a.lb.Name { + klog.InfoS("lb already exists, skipping create", + "name", a.lb.Name, "uuid", lb.UUID) + + return Refresh, nil + } + } + } + addrs := make([]cloudscale.VIPAddressRequest, 0, len(a.lb.VIPAddresses)) for _, addr := range a.lb.VIPAddresses { addrs = append(addrs, cloudscale.VIPAddressRequest{ @@ -58,7 +71,7 @@ func (a *CreateLbAction) Run( }) } - _, err := client.LoadBalancers.Create(ctx, &cloudscale.LoadBalancerRequest{ + _, err = client.LoadBalancers.Create(ctx, &cloudscale.LoadBalancerRequest{ Name: a.lb.Name, Flavor: a.lb.Flavor.Slug, VIPAddresses: &addrs,