Skip to content

Commit 2f26f08

Browse files
committed
Create NPD kubeconfig conditionally if the installation mode is standalone
1 parent ec93d3b commit 2f26f08

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

cluster/gce/upgrade.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ function prepare-node-upgrade() {
258258
KUBE_PROXY_TOKEN=$(get-env-val "${node_env}" "KUBE_PROXY_TOKEN")
259259
export KUBE_PROXY_TOKEN
260260
NODE_PROBLEM_DETECTOR_TOKEN=$(get-env-val "${node_env}" "NODE_PROBLEM_DETECTOR_TOKEN")
261+
export NODE_PROBLEM_DETECTOR_TOKEN
261262
CA_CERT_BASE64=$(get-env-val "${node_env}" "CA_CERT")
262263
export CA_CERT_BASE64
263264
EXTRA_DOCKER_OPTS=$(get-env-val "${node_env}" "EXTRA_DOCKER_OPTS")

cluster/gce/windows/k8s-node-setup.psm1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,25 +1130,25 @@ function Verify-WorkerServices {
11301130
$timeout = 12
11311131
$retries = 0
11321132
$retryDelayInSeconds = 5
1133-
1133+
11341134
Log-Output ("Testing node connection to API server...")
11351135
do {
11361136
$retries++
11371137
$nodes_list = & "${env:NODE_DIR}\kubectl.exe" get nodes -o=custom-columns=:.metadata.name -A | Out-String
11381138
$host_status = & "${env:NODE_DIR}\kubectl.exe" get nodes (hostname) -o=custom-columns=:.status.conditions[4].type | Out-String
11391139
Start-Sleep $retryDelayInSeconds
11401140
} while (((-Not $nodes_list) -or (-Not $nodes_list.contains((hostname))) -or (-Not $host_status.contains("Ready")))-and ($retries -le $timeout))
1141-
1141+
11421142
If (-Not $nodes_list){
11431143
Throw ("Node: '$(hostname)' failed to connect to API server")
1144-
1144+
11451145
}ElseIf (-Not $nodes_list.contains((hostname))) {
11461146
Throw ("Node: '$(hostname)' failed to join the cluster; NODES: '`n $($nodes_list)'")
11471147

11481148
}ELseIf (-Not $host_status.contains("Ready")) {
11491149
Throw ("Node: '$(hostname)' is not in Ready state")
11501150
}
1151-
1151+
11521152
Log-Output ("Node: $(hostname) successfully joined cluster `n NODES: `n $($nodes_list)")
11531153
Verify_GceMetadataServerRouteIsPresent
11541154

@@ -1543,10 +1543,21 @@ function DownloadAndInstall-NodeProblemDetector {
15431543
# CA_CERT
15441544
# NODE_PROBLEM_DETECTOR_TOKEN
15451545
function Create-NodeProblemDetectorKubeConfig {
1546-
if (-not [string]::IsNullOrEmpty(${env:NODEPROBLEMDETECTOR_KUBECONFIG_FILE})) {
1547-
Create-Kubeconfig -Name 'node-problem-detector' `
1548-
-Path ${env:NODEPROBLEMDETECTOR_KUBECONFIG_FILE} `
1549-
-Token ${kube_env}['NODE_PROBLEM_DETECTOR_TOKEN']
1546+
if ("${env:ENABLE_NODE_PROBLEM_DETECTOR}" -eq "standalone") {
1547+
if (-not [string]::IsNullOrEmpty(${kube_env]['NODE_PROBLEM_DETECTOR_TOKEN']})) {
1548+
Log-Output "Create-NodeProblemDetectorKubeConfig using Node Problem Detector token"
1549+
Create-Kubeconfig -Name 'node-problem-detector' `
1550+
-Path ${env:NODEPROBLEMDETECTOR_KUBECONFIG_FILE} `
1551+
-Token ${kube_env}['NODE_PROBLEM_DETECTOR_TOKEN']
1552+
} elseif (Test-Path ${env:BOOTSTRAP_KUBECONFIG}) {
1553+
Log-Output "Create-NodeProblemDetectorKubeConfig creating kubeconfig from kubelet kubeconfig"
1554+
Copy-Item ${env:BOOTSTRAP_KUBECONFIG} -Destination ${env:NODEPROBLEMDETECTOR_KUBECONFIG_FILE}
1555+
Log-Output ("node-problem-detector bootstrap kubeconfig:`n" +
1556+
"$(Get-Content -Raw ${env:NODEPROBLEMDETECTOR_KUBECONFIG_FILE})")
1557+
} else {
1558+
Log-Output "Either NODE_PROBLEM_DETECTOR_TOKEN or ${env:BOOTSTRAP_KUBECONFIG} must be set"
1559+
exit 1
1560+
}
15501561
}
15511562
}
15521563

0 commit comments

Comments
 (0)