Skip to content

Commit d143514

Browse files
committed
[nodeconfig] adds retries to hns endpoint creation
solves ENDPOINT_IP: error running command with output New-HnsEndpoint sets timeout to a little over 3 minutes, out of an abundance of caution
1 parent 0039f78 commit d143514

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

pkg/nodeconfig/payload/payload.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ param(
110110
}
111111
}
112112
113+
# This retries getting the HNS-network until it succeeds
114+
function Retry-GetHnsNetwork {
115+
$retryCount = 20
116+
$retryDelaySeconds = 1
117+
118+
$attempt = 1
119+
120+
while ($attempt -le $retryCount) {
121+
try {
122+
$hns_network = Get-HnsNetwork | Where-Object { $_.Name -eq 'HNS_NETWORK' }
123+
124+
# Check if hns_network is null
125+
if ($null -eq $hns_network) {
126+
Write-Host "Attempt $attempt returned null. Retrying in $retryDelaySeconds seconds..."
127+
} else {
128+
Write-Host "Found HNS_NETWORK on attempt $attempt"
129+
return $hns_network
130+
}
131+
} catch {
132+
Write-Host "Attempt $attempt failed: $_"
133+
}
134+
Start-Sleep -Seconds $retryDelaySeconds
135+
$attempt++
136+
}
137+
Write-Host "Max retry attempts reached."
138+
return $null
139+
}
140+
113141
$ErrorActionPreference = "Stop"
114142
Import-Module -DisableNameChecking HNS_MODULE_PATH
115143
@@ -165,8 +193,13 @@ $cni_template=@'
165193
}
166194
'@
167195
196+
$hns_network = Retry-GetHnsNetwork
197+
# If the HNS network is never found, quit.
198+
if ($null -eq $hns_network) {
199+
throw "cannot find HNS network with name HNS_NETWORK"
200+
}
201+
168202
# Generate CNI Config
169-
$hns_network=Get-HnsNetwork | where { $_.Name -eq 'HNS_NETWORK'}
170203
$subnet=$hns_network.Subnets.AddressPrefix
171204
$cni_template=$cni_template.Replace("ovn_host_subnet",$subnet)
172205
$provider_address=$hns_network.ManagementIP

pkg/nodeconfig/payload/payload_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ param(
3838
}
3939
}
4040
41+
# This retries getting the HNS-network until it succeeds
42+
function Retry-GetHnsNetwork {
43+
$retryCount = 20
44+
$retryDelaySeconds = 1
45+
46+
$attempt = 1
47+
48+
while ($attempt -le $retryCount) {
49+
try {
50+
$hns_network = Get-HnsNetwork | Where-Object { $_.Name -eq 'OVNKubernetesHNSNetwork' }
51+
52+
# Check if hns_network is null
53+
if ($null -eq $hns_network) {
54+
Write-Host "Attempt $attempt returned null. Retrying in $retryDelaySeconds seconds..."
55+
} else {
56+
Write-Host "Found OVNKubernetesHNSNetwork on attempt $attempt"
57+
return $hns_network
58+
}
59+
} catch {
60+
Write-Host "Attempt $attempt failed: $_"
61+
}
62+
Start-Sleep -Seconds $retryDelaySeconds
63+
$attempt++
64+
}
65+
Write-Host "Max retry attempts reached."
66+
return $null
67+
}
68+
4169
$ErrorActionPreference = "Stop"
4270
Import-Module -DisableNameChecking c:\k\hns.psm1
4371
@@ -93,8 +121,13 @@ $cni_template=@'
93121
}
94122
'@
95123
124+
$hns_network = Retry-GetHnsNetwork
125+
# If the HNS network is never found, quit.
126+
if ($null -eq $hns_network) {
127+
throw "cannot find HNS network with name OVNKubernetesHNSNetwork"
128+
}
129+
96130
# Generate CNI Config
97-
$hns_network=Get-HnsNetwork | where { $_.Name -eq 'OVNKubernetesHNSNetwork'}
98131
$subnet=$hns_network.Subnets.AddressPrefix
99132
$cni_template=$cni_template.Replace("ovn_host_subnet",$subnet)
100133
$provider_address=$hns_network.ManagementIP

0 commit comments

Comments
 (0)