Skip to content

Commit eecc329

Browse files
authored
Adding MacOS and Windows hosts values to prod-02 (#9519)
* KFLUXINFRA-2686: Adding MacOS and Windows hosts values to prod-02 * KFLUXINFRA-2686 II: reverting changes to p02's cluster-queue.yaml * KFLUXINFRA-2686 III: Fixing host-values.yaml for p02, adding a script-generated cluser-queue and updating MPC's version on p02 * KFLUXINFRA-2686 IV: Fixing host-values.yaml for p02 properly dividing windows and macos config values between dynamicConfigs and archDefaults * KFLUXINFRA-2686 V: Formatting the user-data scripts for macos and windows, reverting MPC's version update from production-downstream/base/ to only p02's kustomization.yaml * KFLUXINFRA-2686 VI: Fix for errors from forbid-clusterpolicies.yaml check * KFLUXINFRA-2686 VI: Adding fix to MacOS cloud-init script from #9513
1 parent 5a825d4 commit eecc329

File tree

3 files changed

+270
-1
lines changed

3 files changed

+270
-1
lines changed

components/kueue/production/stone-prod-p02/queue-config/cluster-queue.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ spec:
149149
- linux-x86-64
150150
- local
151151
- localhost
152+
- macos-mac2metal-arm64
153+
- windows-amd64
152154
flavors:
153155
- name: platform-group-3
154156
resources:
@@ -174,6 +176,10 @@ spec:
174176
nominalQuota: '1000'
175177
- name: localhost
176178
nominalQuota: '1000'
179+
- name: macos-mac2metal-arm64
180+
nominalQuota: '5'
181+
- name: windows-amd64
182+
nominalQuota: '5'
177183
stopPolicy: None
178184
---
179185
apiVersion: kueue.x-k8s.io/v1beta1

components/multi-platform-controller/production-downstream/stone-prod-p02/host-values.yaml

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ archDefaults:
1111
key-name: "konflux-prod-int-mab01"
1212
security-group-id: "sg-0903aedd465be979e"
1313
subnet-id: "subnet-02c476f8d2a4ae05e"
14+
windows-amd64:
15+
ami: "ami-0cf643428c5013531"
16+
key-name: "konflux-prod-int-mab01"
17+
security-group-id: "sg-0903aedd465be979e"
18+
subnet-id: "subnet-02c476f8d2a4ae05e"
19+
macos-mac2metal-arm64:
20+
ami: "ami-000ce2c23b96216d3"
21+
host-resource-group-arn: "arn:aws:resource-groups:us-east-1:381491906438:group/macos-servers"
22+
license-configuration-arn: "arn:aws:license-manager:us-east-1:381491906438:license-configuration:lic-becd775af7ca09c097f1fa94e495e148"
1423

1524

1625
dynamicConfigs:
@@ -189,6 +198,246 @@ dynamicConfigs:
189198
sudo-commands: "/usr/bin/podman, /usr/bin/rm /usr/share/containers/mounts.conf"
190199
disk: "200"
191200

201+
macos-mac2metal-arm64:
202+
user-data: |
203+
#!/bin/bash
204+
set -eu
205+
set -x
206+
207+
user="konflux-builder"
208+
209+
# Check if user already exists
210+
if ! id "$user" &>/dev/null; then
211+
# Generate random password
212+
random_password=$(openssl rand -base64 32)
213+
214+
# Create user
215+
sudo sysadminctl -addUser "$user" -fullName "Konflux Builder" -password "$random_password" -home /Users/$user
216+
217+
# Clear password from variable
218+
unset random_password
219+
else
220+
echo "User $user already exists, skipping user creation"
221+
fi
222+
223+
# Create home directory if it doesn't exist
224+
sudo mkdir -p /Users/$user
225+
226+
# Create SSH directory
227+
sudo mkdir -p /Users/$user/.ssh
228+
229+
# Remove existing SSH keys if they exist
230+
sudo rm -f /Users/$user/.ssh/id_rsa /Users/$user/.ssh/id_rsa.pub
231+
232+
# Generate new SSH keys
233+
sudo ssh-keygen -t rsa -b 4096 -f /Users/$user/.ssh/id_rsa -N "" -C ""
234+
235+
# Set proper permissions on .ssh directory
236+
sudo chmod 700 /Users/$user/.ssh
237+
238+
# Create/overwrite authorized_keys
239+
sudo chmod 600 /Users/$user/.ssh/authorized_keys 2>/dev/null || true
240+
sudo cat /Users/$user/.ssh/id_rsa.pub | sudo tee /Users/$user/.ssh/authorized_keys > /dev/null
241+
sudo cat /Users/$user/.ssh/id_rsa | sudo tee /Users/ec2-user/$user > /dev/null
242+
243+
# Set ownership of entire home directory to ensure user has full control
244+
sudo chown -R $user:staff /Users/$user
245+
246+
# Set ownership of the copied private key to ec2-user
247+
sudo chown ec2-user:staff /Users/ec2-user/$user
248+
sudo chmod 600 /Users/ec2-user/$user
249+
250+
windows-amd64:
251+
user-data: |
252+
<powershell>
253+
## -----------------------------------------
254+
## --------- Helper Functions --------------
255+
## -----------------------------------------
256+
function Wait-Folder {
257+
param(
258+
[Parameter(Mandatory=$true)]
259+
[string]$FolderPath,
260+
[Parameter(Mandatory=$false)]
261+
[int]$TimeoutSeconds = 30
262+
)
263+
264+
Write-Host "Waiting for folder '${FolderPath}' to be created"
265+
266+
# Start a timer
267+
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
268+
269+
while (-not (Test-Path -Path ${FolderPath})) {
270+
# Check if we have exceeded the timeout
271+
if ($stopwatch.Elapsed.TotalSeconds -ge $TimeoutSeconds) {
272+
Write-Error "Timeout reached! Folder was not created within $TimeoutSeconds seconds."
273+
$stopwatch.Stop()
274+
return $false
275+
}
276+
277+
Write-Host "Waiting for folder..." -NoNewline
278+
Start-Sleep -Seconds 1
279+
}
280+
281+
$stopwatch.Stop()
282+
return $true
283+
}
284+
285+
## -----------------------------------------
286+
## --------- Create Local User -------------
287+
## -----------------------------------------
288+
$user = "konflux-builder"
289+
290+
if ((Get-LocalUser -Name "${user}" -ErrorAction SilentlyContinue) -eq $null) {
291+
# Generate random password
292+
$password = (-join([char[]](33..122) | Get-Random -Count 30))
293+
$securePassword = (ConvertTo-SecureString $password -AsPlainText -Force)
294+
295+
# Create user
296+
New-LocalUser -Name $user -Password $securePassword -Description "Konflux Builder" | Out-Null
297+
Add-LocalGroupMember -Group 'Users' -Member "${user}"
298+
Add-LocalGroupMember -Group 'OpenSSH Users' -Member "${user}"
299+
300+
# Create a Credential Object for the new user
301+
$userCred = New-Object System.Management.Automation.PSCredential($user, $securePassword)
302+
303+
# Start a dummy Process as the new User
304+
# This is required to have the user home folder initialized.
305+
# TODO: can we do better?
306+
Start-Process -FilePath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" `
307+
-Credential ${userCred} `
308+
-ArgumentList "-Command exit" `
309+
-LoadUserProfile `
310+
-WindowStyle Hidden `
311+
-WorkingDirectory "C:\Users\" `
312+
-Wait
313+
314+
# Create SSH Key for user
315+
Write-Host "Creating SSH Key for user '${user}'"
316+
$tempKey = "${env:TEMP}\${user}"
317+
318+
if (Test-Path "${tempKey}") { Remove-Item -Force "${tempKey}" }
319+
if (Test-Path "${tempKey}.pub") { Remove-Item -Force "${tempKey}.pub" }
320+
321+
ssh-keygen -t rsa -f "${tempKey}" -N `"`" | Out-Null
322+
323+
# Move private key to a secure location and restrict access to it
324+
$privateKeyPath = "C:\Users\Administrator\${user}"
325+
mv "${env:TEMP}\${user}" "${privateKeyPath}"
326+
327+
$ACL = Get-Acl "${privateKeyPath}"
328+
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("NT AUTHORITY\SYSTEM", "FullControl", "Allow")
329+
$ACL.SetAccessRule($Ar)
330+
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators", "FullControl", "Allow")
331+
$ACL.SetAccessRule($Ar)
332+
Set-Acl "${privateKeyPath}" ${ACL}
333+
334+
# Initialize user home folder
335+
$userHome = "C:\Users\${user}"
336+
Write-Host "Waiting for User Home '${userHome}' to be created"
337+
338+
# Ensure User's home folder is eventually created
339+
if (-not (Wait-Folder -FolderPath ${userHome})) {
340+
Write-Error "Folder '${userHome}' not found! Cleanup..." -ForegroundColor Red
341+
if (Test-Path "\${tempKey}") { Remove-Item -Force "${tempKey}" }
342+
if (Test-Path "\${tempKey}.pub") { Remove-Item -Force "${tempKey}.pub" }
343+
exit 1
344+
}
345+
346+
# Set up SSH Keys for User
347+
Write-Host "User Home found. Configuring SSH access" -ForegroundColor Green
348+
New-Item -ItemType Directory -Force -Path "${userHome}\.ssh"
349+
New-Item -ItemType Directory -Force -Path "${userHome}\build"
350+
351+
# Copying and removing to preserve file permissions! Do not use `mv`! :)
352+
cp "${tempKey}.pub" "${userHome}\.ssh\authorized_keys"
353+
rm "${tempKey}.pub"
354+
}
355+
356+
## -------------------------------------------------
357+
## --------- Enable Windows Containers -------------
358+
## -------------------------------------------------
359+
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/Windows-Containers/Main/helpful_tools/Install-DockerCE/install-docker-ce.ps1" -o install-docker-ce.ps1
360+
.\install-docker-ce.ps1 -NoRestart
361+
362+
if (${global:RebootRequired}) {
363+
Restart-Computer
364+
exit
365+
}
366+
367+
# Create docker-users group and add konflux-builder to it
368+
if ((Get-LocalGroup -Name 'docker-users') -eq $null) {
369+
New-LocalGroup -Name 'docker-users' -Description 'Docker Users'
370+
}
371+
372+
if ((Get-LocalGroupMember -Group 'docker-users' -Member 'konflux-builder') -eq $null) {
373+
Add-LocalGroupMember -Group 'docker-users' -Member "${user}"
374+
}
375+
376+
# Allow the docker-users group to use docker
377+
$dockerConfigPath = "C:\ProgramData\docker\config\daemon.json"
378+
$existingConfig = Get-Content $dockerConfigPath -Raw | ConvertFrom-Json
379+
380+
if ((${existingConfig}.group) -eq $null) {
381+
$existingConfig | Add-Member -NotePropertyName "group" -NotePropertyValue "docker-users" -Force
382+
$existingConfig | ConvertTo-Json -Depth 10 | Set-Content $dockerConfigPath
383+
Restart-Service docker
384+
}
385+
386+
# Exclude docker in Windows Defender
387+
Add-MpPreference -ExclusionProcess "dockerd.exe"
388+
Add-MpPreference -ExclusionProcess "docker.exe"
389+
Add-MpPreference -ExclusionProcess "containerd.exe"
390+
Add-MpPreference -ExclusionProcess "vmcompute.exe"
391+
392+
## -----------------------------------------
393+
## --------- Configure OpenSSH -------------
394+
## -----------------------------------------
395+
# Install OpenSSH Server
396+
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
397+
398+
# Start the sshd service and set it to start automatically
399+
Start-Service sshd
400+
Set-Service -Name sshd -StartupType 'Automatic'
401+
402+
# Grab the Public Key from AWS Metadata and configure authorized_keys
403+
# This allows you to log in with your .pem/.ppk file instead of a password
404+
$MAGIC_IP = "169.254.169.254"
405+
$IMDS_TOKEN = Invoke-RestMethod -Uri "http://${MAGIC_IP}/latest/api/token" -Method 'PUT' -Headers @{'X-aws-ec2-metadata-token-ttl-seconds' = '21600'}
406+
$PUBKEY = Invoke-RestMethod -Uri "http://${MAGIC_IP}/latest/meta-data/public-keys/0/openssh-key" -Headers @{'X-aws-ec2-metadata-token' = $IMDS_TOKEN}
407+
408+
# Ensure SSH_PATH folder was created
409+
$SSH_PATH = "C:\ProgramData\ssh"
410+
Write-Host "Waiting for SSH Folder"
411+
412+
if (-not (Wait-Folder -FolderPath ${SSH_PATH})) {
413+
Write-Error "Folder '${SSH_PATH}' not found! Exiting..." -ForegroundColor Red
414+
exit 1
415+
}
416+
417+
Write-Host "Folder '${SSH_PATH}' found"
418+
419+
# Add key to administrators_authorized_keys
420+
$PUBKEY | Out-File -FilePath "$SSH_PATH\administrators_authorized_keys" -Encoding ascii
421+
422+
# Fix permissions (ACLs) for the authorized_keys file
423+
# OpenSSH is strict: only System and Administrators should have access
424+
$ACL = Get-Acl "$SSH_PATH\administrators_authorized_keys"
425+
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("NT AUTHORITY\SYSTEM", "FullControl", "Allow")
426+
$ACL.SetAccessRule($Ar)
427+
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators", "FullControl", "Allow")
428+
$ACL.SetAccessRule($Ar)
429+
Set-Acl "$SSH_PATH\administrators_authorized_keys" $ACL
430+
431+
# Restart sshd to apply key changes
432+
Restart-Service sshd
433+
434+
# Configure the Firewall to allow SSH (Port 22)
435+
Remove-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' | Out-Null
436+
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -RemoteAddress any
437+
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' updated"
438+
</powershell>
439+
<persist>true</persist>
440+
192441
linux-root-amd64:
193442
iops: "16000"
194443
throughput: "1000"

components/multi-platform-controller/production-downstream/stone-prod-p02/kustomization.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ kind: Kustomization
44
namespace: multi-platform-controller
55

66
resources:
7-
- ../base
7+
- ../../base/common
8+
- ../../base/rbac
89
- external-secrets.yaml
10+
- https://github.com/konflux-ci/multi-platform-controller/deploy/operator?ref=6347caa2deb2dce08f4f3a100cb96f23ae7f14c6
11+
- https://github.com/konflux-ci/multi-platform-controller/deploy/otp?ref=6347caa2deb2dce08f4f3a100cb96f23ae7f14c6
12+
13+
components:
14+
- ../../k-components/manager-resources
915

1016
helmGlobals:
1117
chartHome: ../../base
@@ -15,3 +21,11 @@ helmCharts:
1521
releaseName: host-config
1622
namespace: multi-platform-controller
1723
valuesFile: host-values.yaml
24+
25+
images:
26+
- name: multi-platform-controller
27+
newName: quay.io/konflux-ci/multi-platform-controller
28+
newTag: 6347caa2deb2dce08f4f3a100cb96f23ae7f14c6
29+
- name: multi-platform-otp-server
30+
newName: quay.io/konflux-ci/multi-platform-controller-otp-service
31+
newTag: 6347caa2deb2dce08f4f3a100cb96f23ae7f14c6

0 commit comments

Comments
 (0)