From 6df08d4eadf71bf9c34d3d1f0f7cec5810caab49 Mon Sep 17 00:00:00 2001 From: Christian Glombek Date: Tue, 22 Sep 2020 14:14:07 +0200 Subject: [PATCH 1/2] UPSTREAM: : openshift: vm: Add AdditionalUnattendContent on Windows machines This commit adds functionality for automatically running C:\AzureData\CustomData.bin on first boot. This file is provided via the user data secret, and contains init scripts. The Windows Machine Config Operator relies on the user data script being executed automatically on the Windows VM to set up SSH access. On AWS, it is invoked automatically after provisioning. This commit is intended to align Azure with that behavior. --- .../virtualmachines/virtualmachines.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pkg/cloud/azure/services/virtualmachines/virtualmachines.go b/pkg/cloud/azure/services/virtualmachines/virtualmachines.go index 7378cb2fe7e..4057995f415 100644 --- a/pkg/cloud/azure/services/virtualmachines/virtualmachines.go +++ b/pkg/cloud/azure/services/virtualmachines/virtualmachines.go @@ -34,6 +34,34 @@ import ( "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/services/networkinterfaces" ) +const ( + // winAutoLogonFormatString is the format string used to create the AutoLogon + // AdditionalUnattendContent configuration for Windows machines. + winAutoLogonFormatString = ` + %s + + %s + + true + 1 + ` + + // winFirstLogonCommandsString is the string used to create the FirstLogonCommands + // AdditionalUnattendContent configuration for Windows machines. + winFirstLogonCommandsString = ` + + Copy user data secret contents to init script + cmd /c "copy C:\AzureData\CustomData.bin C:\init.ps1" + 11 + + + Launch init script + powershell.exe -NonInteractive -ExecutionPolicy Bypass -File C:\init.ps1 + 12 + + ` +) + // Spec input specification for Get/CreateOrUpdate/Delete calls type Spec struct { Name string @@ -126,6 +154,20 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error { if compute.OperatingSystemTypes(vmSpec.OSDisk.OSType) == compute.Windows { osProfile.WindowsConfiguration = &compute.WindowsConfiguration{ EnableAutomaticUpdates: to.BoolPtr(false), + AdditionalUnattendContent: &[]compute.AdditionalUnattendContent{ + { + PassName: "OobeSystem", + ComponentName: "Microsoft-Windows-Shell-Setup", + SettingName: "AutoLogon", + Content: to.StringPtr(fmt.Sprintf(winAutoLogonFormatString, *osProfile.AdminUsername, *osProfile.AdminPassword)), + }, + { + PassName: "OobeSystem", + ComponentName: "Microsoft-Windows-Shell-Setup", + SettingName: "FirstLogonCommands", + Content: to.StringPtr(winFirstLogonCommandsString), + }, + }, } } else if sshKeyData != "" { osProfile.LinuxConfiguration = &compute.LinuxConfiguration{ From 3b68ceb9c2de8ea89c8a6b1a259b1ef92b4833e6 Mon Sep 17 00:00:00 2001 From: Christian Glombek Date: Tue, 22 Sep 2020 14:14:39 +0200 Subject: [PATCH 2/2] UPSTREAM: : openshift: machine: Return full invalid configuration error --- pkg/cloud/azure/actuators/machine/reconciler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cloud/azure/actuators/machine/reconciler.go b/pkg/cloud/azure/actuators/machine/reconciler.go index b8d2e766ffe..20e4d97d608 100644 --- a/pkg/cloud/azure/actuators/machine/reconciler.go +++ b/pkg/cloud/azure/actuators/machine/reconciler.go @@ -617,7 +617,7 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName string) e var detailedError autorest.DetailedError if errors.As(err, &detailedError) && detailedError.Message == "Failure sending request" { - return machinecontroller.InvalidMachineConfiguration("failure sending request for machine %s", s.scope.Machine.Name) + return machinecontroller.InvalidMachineConfiguration("failure sending request for machine %s: %v", s.scope.Machine.Name, err) } return fmt.Errorf("failed to create or get machine: %w", err) }