diff --git a/examples/gcp/gke.tf b/examples/gcp/gke.tf index fbb9243..40276be 100644 --- a/examples/gcp/gke.tf +++ b/examples/gcp/gke.tf @@ -280,8 +280,9 @@ resource "kubernetes_daemonset" "kubeip_daemonset" { termination_grace_period_seconds = 30 priority_class_name = "system-node-critical" container { - name = "kubeip-agent" - image = "doitintl/kubeip-agent:${var.kubeip_version}" + name = "kubeip-agent" + image = "doitintl/kubeip-agent:${var.kubeip_version}" + image_pull_policy = "Always" env { name = "NODE_NAME" value_from { diff --git a/internal/address/gcp.go b/internal/address/gcp.go index 8927ee1..13afa99 100644 --- a/internal/address/gcp.go +++ b/internal/address/gcp.go @@ -3,6 +3,7 @@ package address import ( "context" "fmt" + "math/rand" "strings" "time" @@ -26,6 +27,7 @@ const ( accessConfigKind = "compute#accessConfig" defaultPrefixLength = 96 maxRetries = 10 // number of retries for assigning ephemeral public IP address + maxWaitListTime = 10 // max time to wait before listing addresses ) var ( @@ -221,6 +223,11 @@ func (a *gcpAssigner) Assign(ctx context.Context, instanceID, zone string, filte return errors.Wrapf(err, "check if static public IP is already assigned to instance %s", instanceID) } + // add random sleep to reduce the chance of multiple kubeip instances getting the same address list + waitTime := time.Duration(rand.Intn(maxWaitListTime)) * time.Second //nolint:gosec + a.logger.WithField("waitTime", waitTime).Debug("waiting before listing addresses") + time.Sleep(waitTime) + // get available reserved public IP addresses addresses, err := a.listAddresses(filter, orderBy, reservedStatus) if err != nil {