From 5d61a49d5f7635e0fe020078da6f17760d1d2950 Mon Sep 17 00:00:00 2001 From: Rashmi Chandrashekar Date: Mon, 12 Jul 2021 20:24:56 -0700 Subject: [PATCH 1/2] mdm-fix-for-node_ip --- kubernetes/windows/main.ps1 | 55 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/kubernetes/windows/main.ps1 b/kubernetes/windows/main.ps1 index bc053b0d6..1bb9a3468 100644 --- a/kubernetes/windows/main.ps1 +++ b/kubernetes/windows/main.ps1 @@ -140,7 +140,7 @@ function Set-EnvironmentVariables { if ($aiKeyURl) { $aiKeyFetched = "" # retry up to 5 times - for( $i = 1; $i -le 4; $i++) { + for ( $i = 1; $i -le 4; $i++) { try { $response = Invoke-WebRequest -uri $aiKeyURl -UseBasicParsing -TimeoutSec 5 -ErrorAction:Stop @@ -229,6 +229,24 @@ function Set-EnvironmentVariables { Write-Host "Failed to set environment variable HOSTNAME for target 'machine' since it is either null or empty" } + $nodeIp = [System.Environment]::GetEnvironmentVariable("NODE_IP", "process") + if (![string]::IsNullOrEmpty($nodeIp)) { + [System.Environment]::SetEnvironmentVariable("NODE_IP", $nodeIp, "machine") + Write-Host "Successfully set environment variable NODE_IP - $($nodeIp) for target 'machine'..." + } + else { + Write-Host "Failed to set environment variable NODE_IP for target 'machine' since it is either null or empty" + } + + $agentVersion = [System.Environment]::GetEnvironmentVariable("AGENT_VERSION", "process") + if (![string]::IsNullOrEmpty($agentVersion)) { + [System.Environment]::SetEnvironmentVariable("AGENT_VERSION", $agentVersion, "machine") + Write-Host "Successfully set environment variable AGENT_VERSION - $($agentVersion) for target 'machine'..." + } + else { + Write-Host "Failed to set environment variable AGENT_VERSION for target 'machine' since it is either null or empty" + } + # run config parser ruby /opt/omsagentwindows/scripts/ruby/tomlparser.rb .\setenv.ps1 @@ -364,13 +382,12 @@ function Start-Fluent-Telegraf { if (![string]::IsNullOrEmpty($containerRuntime) -and [string]$containerRuntime.StartsWith('docker') -eq $false) { # change parser from docker to cri if the container runtime is not docker Write-Host "changing parser from Docker to CRI since container runtime : $($containerRuntime) and which is non-docker" - (Get-Content -Path C:/etc/fluent/fluent.conf -Raw) -replace 'fluent-docker-parser.conf','fluent-cri-parser.conf' | Set-Content C:/etc/fluent/fluent.conf + (Get-Content -Path C:/etc/fluent/fluent.conf -Raw) -replace 'fluent-docker-parser.conf', 'fluent-cri-parser.conf' | Set-Content C:/etc/fluent/fluent.conf } # Start telegraf only in sidecar scraping mode $sidecarScrapingEnabled = [System.Environment]::GetEnvironmentVariable('SIDECAR_SCRAPING_ENABLED') - if (![string]::IsNullOrEmpty($sidecarScrapingEnabled) -and $sidecarScrapingEnabled.ToLower() -eq 'true') - { + if (![string]::IsNullOrEmpty($sidecarScrapingEnabled) -and $sidecarScrapingEnabled.ToLower() -eq 'true') { Write-Host "Starting telegraf..." Start-Telegraf } @@ -411,15 +428,6 @@ function Start-Telegraf { Write-Host "Failed to set environment variable KUBERNETES_SERVICE_PORT for target 'machine' since it is either null or empty" } - $nodeIp = [System.Environment]::GetEnvironmentVariable("NODE_IP", "process") - if (![string]::IsNullOrEmpty($nodeIp)) { - [System.Environment]::SetEnvironmentVariable("NODE_IP", $nodeIp, "machine") - Write-Host "Successfully set environment variable NODE_IP - $($nodeIp) for target 'machine'..." - } - else { - Write-Host "Failed to set environment variable NODE_IP for target 'machine' since it is either null or empty" - } - Write-Host "Installing telegraf service" C:\opt\telegraf\telegraf.exe --service install --config "C:\etc\telegraf\telegraf.conf" @@ -432,14 +440,15 @@ function Start-Telegraf { sc.exe \\$serverName config telegraf start= delayed-auto Write-Host "Successfully set delayed start for telegraf" - } else { + } + else { Write-Host "Failed to get environment variable PODNAME to set delayed telegraf start" } } catch { - $e = $_.Exception - Write-Host $e - Write-Host "exception occured in delayed telegraf start.. continuing without exiting" + $e = $_.Exception + Write-Host $e + Write-Host "exception occured in delayed telegraf start.. continuing without exiting" } Write-Host "Running telegraf service in test mode" C:\opt\telegraf\telegraf.exe --config "C:\etc\telegraf\telegraf.conf" --test @@ -448,8 +457,7 @@ function Start-Telegraf { # Trying to start telegraf again if it did not start due to fluent bit not being ready at startup Get-Service telegraf | findstr Running - if ($? -eq $false) - { + if ($? -eq $false) { Write-Host "trying to start telegraf in again in 30 seconds, since fluentbit might not have been ready..." Start-Sleep -s 30 C:\opt\telegraf\telegraf.exe --service start @@ -488,7 +496,7 @@ function Bootstrap-CACertificates { $certMountPath = "C:\ca" Get-ChildItem $certMountPath | Foreach-Object { - $absolutePath=$_.FullName + $absolutePath = $_.FullName Write-Host "cert path: $($absolutePath)" Import-Certificate -FilePath $absolutePath -CertStoreLocation 'Cert:\LocalMachine\Root' -Verbose } @@ -510,10 +518,9 @@ Start-FileSystemWatcher $aksResourceId = [System.Environment]::GetEnvironmentVariable("AKS_RESOURCE_ID") $requiresCertBootstrap = [System.Environment]::GetEnvironmentVariable("REQUIRES_CERT_BOOTSTRAP") if (![string]::IsNullOrEmpty($requiresCertBootstrap) -and ` - $requiresCertBootstrap.ToLower() -eq 'true' -and ` - ![string]::IsNullOrEmpty($aksResourceId) -and ` - $aksResourceId.ToLower().Contains("/microsoft.containerservice/managedclusters/")) -{ + $requiresCertBootstrap.ToLower() -eq 'true' -and ` + ![string]::IsNullOrEmpty($aksResourceId) -and ` + $aksResourceId.ToLower().Contains("/microsoft.containerservice/managedclusters/")) { Bootstrap-CACertificates } From a1dca54a581cc17528bdde9aefc8a696d99b8cdc Mon Sep 17 00:00:00 2001 From: Rashmi Chandrashekar Date: Tue, 13 Jul 2021 09:20:29 -0700 Subject: [PATCH 2/2] updating docker file with latest agent version --- kubernetes/windows/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/windows/Dockerfile b/kubernetes/windows/Dockerfile index 94be59644..0ba64cd75 100644 --- a/kubernetes/windows/Dockerfile +++ b/kubernetes/windows/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER OMSContainers@microsoft.com LABEL vendor=Microsoft\ Corp \ com.microsoft.product="Azure Monitor for containers" -ARG IMAGE_TAG=win-ciprod06112021 +ARG IMAGE_TAG=win-ciprod06112021-2 # Do not split this into multiple RUN! # Docker creates a layer for every RUN-Statement