Skip to content

Commit

Permalink
Merge pull request #1571 from phillipsj/bugfix/switching-to-curl-in-w…
Browse files Browse the repository at this point in the history
…indows-scripts

Switching to only using curl for windows scripts.
  • Loading branch information
phillipsj committed Aug 8, 2021
2 parents 8d17937 + a0e1077 commit b25c1f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
13 changes: 6 additions & 7 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function Get-Checksums() {
}

Write-Host "downloading checksums at $checksumsUrl"
Invoke-RestMethod -Uri $checksumsUrl -OutFile $TempChecksums
curl.exe -sfL $checksumsUrl -o $TempChecksums
return Find-Checksum -ChecksumFilePath $TempChecksums -Pattern "rke2.$suffix.tar.gz"
}

Expand Down Expand Up @@ -245,7 +245,7 @@ function Get-Tarball() {
}

Write-InfoLog "downloading tarball at $tarballUrl"
Invoke-RestMethod -Uri $tarballUrl -OutFile $TempTarball
curl.exe -sfL $tarballUrl -o $TempTarball
}

# stage_local_checksums stages the local checksum hash for validation.
Expand Down Expand Up @@ -389,8 +389,8 @@ function Test-Download {
$Url
)

try {
Invoke-WebRequest -Uri $Url -Method Head
try {
curl.exe --head -sfL $Url
return $true
}
catch {
Expand Down Expand Up @@ -430,7 +430,7 @@ function Get-AirgapChecksums() {
$AirgapChecksumsUrl = "$StorageUrl/rke2-images.$suffix$CommitHash.tar.gz.sha256sum"
}
Write-InfoLog "downloading airgap checksums at $AirgapChecksumsUrl"
Invoke-RestMethod -Uri $AirgapChecksumsUrl -OutFile $TempAirgapChecksums
curl.exe -sfL $AirgapChecksumsUrl -o $TempAirgapChecksums
return Find-Checksum -Path $TempAirgapChecksums -Pattern "rke2-images.$suffix.tar"
}

Expand Down Expand Up @@ -466,7 +466,7 @@ function Get-AirgapTarball() {
$AirgapTarballUrl = "$StorageUrl/rke2-images.$suffix$CommitHash.tar.gz"
}
Write-InfoLog "downloading airgap tarball at $AirgapTarballUrl"
Invoke-RestMethod -Uri $AirgapTarballUrl -OutFile $TempAirgapTarball
curl.exe -sfL $AirgapTarballUrl -o $TempAirgapTarball
}

# verify_airgap_tarball compares the airgap image tarball checksum to the value
Expand Down Expand Up @@ -601,4 +601,3 @@ switch ($Method) {
Write-FatalLog "Invalid installation method. $Method not supported."
}
}
exit 0
39 changes: 21 additions & 18 deletions windows/rke2-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function Rke2-Installer
}
else {
Write-LogInfo "Downloading RKE2 installer from $($env:CATTLE_AGENT_BINARY_URL)"
Invoke-Webrequest -Uri $env:CATTLE_AGENT_BINARY_URL -OutFile "$($localLocation)\install.ps1"
curl.exe -sfL $env:CATTLE_AGENT_BINARY_URL -o "$($localLocation)\install.ps1"
}
}

Expand All @@ -307,7 +307,7 @@ function Rke2-Installer
return
}

curl.exe --insecure -fL $env:CATTLE_SERVER/$caCertsPath -o $env:RANCHER_CERT
curl.exe --insecure -sfL $env:CATTLE_SERVER/$caCertsPath -o $env:RANCHER_CERT
if (-Not(Test-Path -Path $env:RANCHER_CERT))
{
Write-Error "The environment variable CATTLE_CA_CHECKSUM is set but there is no CA certificate configured at $( $env:CATTLE_SERVER )/$( $caCertsPath )) "
Expand All @@ -323,7 +323,7 @@ function Rke2-Installer
}
else
{
info "Value from $( $env:CATTLE_SERVER )/$( $caCertsPath ) is an x509 certificate"
Write-LogInfo "Value from $( $env:CATTLE_SERVER )/$( $caCertsPath ) is an x509 certificate"
}
$env:CATTLE_SERVER_CHECKSUM = (Get-FileHash -Path $env:RANCHER_CERT -Algorithm SHA256).Hash.ToLower()
if ($env:CATTLE_SERVER_CHECKSUM -ne $env:CATTLE_CA_CHECKSUM)
Expand All @@ -343,28 +343,24 @@ function Rke2-Installer
New-Item -Path $path -ItemType Directory
}

if (-Not(Test-Path "$path\$file"))
$configFile = Join-Path -Path $path -ChildPath $file
if (-Not(Test-Path $configFile))
{
$Uri = "$($env:CATTLE_SERVER)/v3/connect/config-yaml"
$OutFile = "$path\$file"
$headers = @{
'Content-Type' = "application/json"
'Authorization' = "Bearer $($env:CATTLE_TOKEN)"
'X-Cattle-Id' = "$env:CATTLE_ID"
'X-Cattle-Role-Worker' = "$env:CATTLE_ROLE_WORKER"
'X-Cattle-Labels' = "$env:CATTLE_LABELS"
'X-Cattle-Taints' = "$env:CATTLE_TAINTS"
}

Write-LogInfo "Pulling rke2 config.yaml from $Uri"
if (-Not $env:CATTLE_CA_CHECKSUM)
{
Invoke-RestMethod -Uri $Uri -Outfile $Outfile -Headers $headers
curl.exe -sfL $Uri -o $configFile -H "Authorization: Bearer $($env:CATTLE_TOKEN)" -H "X-Cattle-Id: $($env:CATTLE_ID)" -H "X-Cattle-Role-Worker: $($env:CATTLE_ROLE_WORKER)" -H "X-Cattle-Labels: $($env:CATTLE_LABELS)" -H "X-Cattle-Taints: $($env:CATTLE_TAINTS)" -H "Content-Type: application/json"
}
else
{
$cert = Get-PfxCertificate -FilePath $env:RANCHER_CERT
Invoke-RestMethod -Uri $Uri -Outfile $Outfile -Certificate $cert -Headers $headers
curl.exe --insecure --cacert $env:RANCHER_CERT -sfL $Uri -o $configFile -H "Authorization: Bearer $($env:CATTLE_TOKEN)" -H "X-Cattle-Id: $($env:CATTLE_ID)" -H "X-Cattle-Role-Worker: $($env:CATTLE_ROLE_WORKER)" -H "X-Cattle-Labels: $($env:CATTLE_LABELS)" -H "X-Cattle-Taints: $($env:CATTLE_TAINTS)" -H "Content-Type: application/json"
}

if(-Not(Test-Path $configFile))
{
Write-LogFatal "RKE2 Config file wasn't found."
}
}
}
Expand Down Expand Up @@ -412,20 +408,27 @@ function Rke2-Installer

Invoke-Expression -Command "C:\var\lib\rancher\install.ps1"

Write-LogInfo "Checking if RKE2 agent service exists"
if ((Get-Service -Name $rke2ServiceName -ErrorAction SilentlyContinue))
{
Write-LogInfo "RKE2 agent service found, stopping now"
Stop-Service -Name $rke2ServiceName
while ((Get-Service $rke2ServiceName).Status -ne 'Running')
while ((Get-Service $rke2ServiceName).Status -ne 'Stopped')
{
Write-LogInfo "Waiting for RKE2 agent service to stop"
Start-Sleep -s 5
}
}
else
{
# Create Windows Service
Write-LogInfo "Enabling RKE2 agent service"
Write-LogInfo "RKE2 agent service not found, enabling agent service"
rke2.exe agent service --add
Start-Sleep -s 5
}

Write-LogInfo "Starting for RKE2 agent service"
Start-Service -Name $rke2ServiceName
}

Invoke-RancherInstall
Expand Down

0 comments on commit b25c1f4

Please sign in to comment.