Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

chore: Add EnableAHUB in WindowsProfile #3322

Merged
merged 6 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/topics/clusterdefinitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ https://{keyvaultname}.vault.azure.net:443/secrets/{secretName}/{version}
| imageReference.gallery | no | Name of a Shared Image Gallery. |
| imageReference.version | no | Version of an Image from a Shared Image Gallery. |
| sshEnabled | no | If set to `true`, OpenSSH will be installed on windows nodes to allow for ssh remoting. **Only for Windows version 1809/2019 or later**. The same SSH authorized public key(s) will be added from [linuxProfile.ssh.publicKeys](#linuxProfile). Default: `true` |
| enableAHUB | no | If set to `true`, Windows nodepools was licensed on-premises. If this element is set to `true`, the value cannot be changed to `false`. <br> For more information, see [Azure Hybrid Use Benefit for Windows Server](https://docs.microsoft.com/azure/virtual-machines/virtual-machines-windows-hybrid-use-benefit-licensing?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json) |

#### Windows Images

Expand Down
15 changes: 15 additions & 0 deletions docs/topics/windows-and-kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ If you want to disable automatic Windows updates, you can use the `enableAutomat
},
```

### Enabling Azure Hybrid Benefit for Windows Server

If you want to enable [Azure hybrid benefit for Windows server](https://docs.microsoft.com/azure/virtual-machines/virtual-machines-windows-hybrid-use-benefit-licensing?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json), you can use the `enableAHUB` option.

```json
"windowsProfile": {
"adminUsername": "azureuser",
"adminPassword": "...",
"windowsPublisher": "MicrosoftWindowsServer",
"windowsOffer": "WindowsServerSemiAnnual",
"windowsSku": "Datacenter-Core-1809-with-Containers-smalldisk",
"enableAHUB": true
},
```

## More Examples

### Using Azure Files
Expand Down
11 changes: 6 additions & 5 deletions examples/windows/kubernetes-wincni.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
"osType": "Windows",
"osDiskSizeGB": 128,
"extensions": [
{
"name": "winrm"
}
{
"name": "winrm"
}
]
}
],
"windowsProfile": {
"adminUsername": "azureuser",
"adminPassword": "replacepassword1234$"
"adminPassword": "replacepassword1234$",
"enableAHUB": true
},
"linuxProfile": {
"adminUsername": "azureuser",
Expand All @@ -52,4 +53,4 @@
}
]
}
}
}
5 changes: 3 additions & 2 deletions examples/windows/kubernetes-windows-1903.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"windowsPublisher": "MicrosoftWindowsServer",
"windowsOffer": "WindowsServer",
"windowsSku": "Datacenter-Core-1903-with-Containers-smalldisk",
"imageVersion": "1903.0.20190603"
"imageVersion": "1903.0.20190603",
"enableAHUB": true
},
"linuxProfile": {
"adminUsername": "azureuser",
Expand All @@ -43,4 +44,4 @@
"secret": ""
}
}
}
}
4 changes: 4 additions & 0 deletions pkg/api/converterfromapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/Azure/aks-engine/pkg/api/vlabs"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
"github.com/blang/semver"
)

Expand Down Expand Up @@ -210,6 +211,9 @@ func convertWindowsProfileToVLabs(api *WindowsProfile, vlabsProfile *vlabs.Windo
vlabsProfile.SSHEnabled = api.SSHEnabled
}
vlabsProfile.EnableAutomaticUpdates = api.EnableAutomaticUpdates
if api.GetEnableAHUB() {
vlabsProfile.EnableAHUB = to.BoolPtr(true)
}
}

func convertOrchestratorProfileToVLabs(api *OrchestratorProfile, o *vlabs.OrchestratorProfile) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/converterfromapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ func TestConvertWindowsProfileToVlabs(t *testing.T) {
WindowsOffer: "WindowsServer",
WindowsSku: "2019-Datacenter-Core-smalldisk",
WindowsDockerVersion: "18.09",
EnableAHUB: to.BoolPtr(true),
},
expected: vlabs.WindowsProfile{
AdminUsername: "user",
Expand All @@ -790,6 +791,7 @@ func TestConvertWindowsProfileToVlabs(t *testing.T) {
WindowsSku: "2019-Datacenter-Core-smalldisk",
WindowsDockerVersion: "18.09",
Secrets: []vlabs.KeyVaultSecrets{},
EnableAHUB: to.BoolPtr(true),
},
},
{
Expand Down Expand Up @@ -817,9 +819,9 @@ func TestConvertWindowsProfileToVlabs(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()

actual := vlabs.WindowsProfile{}
convertWindowsProfileToVLabs(&c.w, &actual)

Expand Down
4 changes: 4 additions & 0 deletions pkg/api/convertertoapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Azure/aks-engine/pkg/api/vlabs"
"github.com/Azure/aks-engine/pkg/helpers"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
)

///////////////////////////////////////////////////////////
Expand Down Expand Up @@ -204,6 +205,9 @@ func convertVLabsWindowsProfile(vlabs *vlabs.WindowsProfile, api *WindowsProfile
api.SSHEnabled = vlabs.SSHEnabled
}
api.EnableAutomaticUpdates = vlabs.EnableAutomaticUpdates
if vlabs.EnableAHUB != nil && *vlabs.EnableAHUB {
api.EnableAHUB = to.BoolPtr(true)
}
}

func convertVLabsOrchestratorProfile(vp *vlabs.Properties, api *OrchestratorProfile, isUpdate bool) error {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/convertertoapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ func TestConvertVLabsWindowsProfile(t *testing.T) {
WindowsOffer: "WindowsServer",
WindowsSku: "2019-Datacenter-Core-smalldisk",
WindowsDockerVersion: "18.09",
EnableAHUB: to.BoolPtr(true),
},
expected: WindowsProfile{
AdminUsername: "user",
Expand All @@ -919,6 +920,7 @@ func TestConvertVLabsWindowsProfile(t *testing.T) {
WindowsSku: "2019-Datacenter-Core-smalldisk",
WindowsDockerVersion: "18.09",
Secrets: []KeyVaultSecrets{},
EnableAHUB: to.BoolPtr(true),
},
},
{
Expand Down Expand Up @@ -946,9 +948,9 @@ func TestConvertVLabsWindowsProfile(t *testing.T) {
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()

actual := WindowsProfile{}
convertVLabsWindowsProfile(&c.w, &actual)

Expand Down
14 changes: 14 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ type CustomNodesDNS struct {
DNSServer string `json:"dnsServer,omitempty"`
}

const (
// WindowsLicenseTypeServer specifies that the image or disk that is being used was licensed server on-premises.
WindowsLicenseTypeServer string = "Windows_Server"
)

// WindowsProfile represents the windows parameters passed to the cluster
type WindowsProfile struct {
AdminUsername string `json:"adminUsername"`
Expand All @@ -222,6 +227,7 @@ type WindowsProfile struct {
SSHEnabled *bool `json:"sshEnabled,omitempty"`
EnableAutomaticUpdates *bool `json:"enableAutomaticUpdates,omitempty"`
IsCredentialAutoGenerated *bool `json:"isCredentialAutoGenerated,omitempty"`
EnableAHUB *bool `json:"enableAHUB,omitempty"`
}

// ProvisioningState represents the current state of container service resource.
Expand Down Expand Up @@ -1805,6 +1811,14 @@ func (w *WindowsProfile) GetIsCredentialAutoGenerated() bool {
return false
}

// GetEnableAHUB gets it AHUB should be enabled for Windows nodes
func (w *WindowsProfile) GetEnableAHUB() bool {
if w.EnableAHUB != nil {
return *w.EnableAHUB
}
return false
}

// HasSecrets returns true if the customer specified secrets to install
func (l *LinuxProfile) HasSecrets() bool {
return len(l.Secrets) > 0
Expand Down
17 changes: 17 additions & 0 deletions pkg/api/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,11 @@ func TestWindowsProfile(t *testing.T) {
t.Fatalf("Expected GetIsCredentialAutoGenerated() to equal default 'false', got %t", autoGenerated)
}

enableAHUB := w.GetEnableAHUB()
if enableAHUB {
t.Fatalf("Expected GetEnableAHUB() to equal default 'false', got %t", enableAHUB)
}

w = WindowsProfile{
Secrets: []KeyVaultSecrets{
{
Expand All @@ -3477,6 +3482,7 @@ func TestWindowsProfile(t *testing.T) {
},
WindowsImageSourceURL: "testCustomImage",
IsCredentialAutoGenerated: to.BoolPtr(true),
EnableAHUB: to.BoolPtr(true),
}

if !(w.HasSecrets() && w.HasCustomImage()) {
Expand All @@ -3488,11 +3494,17 @@ func TestWindowsProfile(t *testing.T) {
t.Fatalf("Expected GetIsCredentialAutoGenerated() to equal default 'true', got %t", autoGenerated)
}

enableAHUB = w.GetEnableAHUB()
if !enableAHUB {
t.Fatalf("Expected GetEnableAHUB() to equal default 'true', got %t", enableAHUB)
}

w = WindowsProfile{
WindowsDockerVersion: "18.03.1-ee-3",
WindowsSku: "Datacenter-Core-1809-with-Containers-smalldisk",
SSHEnabled: &trueVar,
IsCredentialAutoGenerated: to.BoolPtr(false),
EnableAHUB: to.BoolPtr(false),
}

dv = w.GetWindowsDockerVersion()
Expand All @@ -3514,6 +3526,11 @@ func TestWindowsProfile(t *testing.T) {
if autoGenerated {
t.Fatalf("Expected GetIsCredentialAutoGenerated() to equal default 'false', got %t", autoGenerated)
}

enableAHUB = w.GetEnableAHUB()
if enableAHUB {
t.Fatalf("Expected GetEnableAHUB() to equal default 'false', got %t", enableAHUB)
}
}

func TestWindowsProfileCustomOS(t *testing.T) {
Expand Down
38 changes: 24 additions & 14 deletions pkg/api/vlabs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,32 @@ type CustomNodesDNS struct {
DNSServer string `json:"dnsServer,omitempty"`
}

// WindowsLicenseType represents Windows license type
type WindowsLicenseType string

const (
// WindowsLicenseTypeServer specifies that the image or disk that is being used was licensed server on-premises.
WindowsLicenseTypeServer WindowsLicenseType = "Windows_Server"
)

// WindowsProfile represents the windows parameters passed to the cluster
type WindowsProfile struct {
AdminUsername string `json:"adminUsername,omitempty"`
AdminPassword string `json:"adminPassword,omitempty"`
CSIProxyURL string `json:"csiProxyURL,omitempty"`
EnableCSIProxy *bool `json:"enableCSIProxy,omitempty"`
ImageRef *ImageReference `json:"imageReference,omitempty"`
ImageVersion string `json:"imageVersion,omitempty"`
WindowsImageSourceURL string `json:"WindowsImageSourceUrl"`
WindowsPublisher string `json:"WindowsPublisher"`
WindowsOffer string `json:"WindowsOffer"`
WindowsSku string `json:"WindowsSku"`
WindowsDockerVersion string `json:"windowsDockerVersion"`
Secrets []KeyVaultSecrets `json:"secrets,omitempty"`
SSHEnabled *bool `json:"sshEnabled,omitempty"`
EnableAutomaticUpdates *bool `json:"enableAutomaticUpdates,omitempty"`
AdminUsername string `json:"adminUsername,omitempty"`
AdminPassword string `json:"adminPassword,omitempty"`
CSIProxyURL string `json:"csiProxyURL,omitempty"`
EnableCSIProxy *bool `json:"enableCSIProxy,omitempty"`
ImageRef *ImageReference `json:"imageReference,omitempty"`
ImageVersion string `json:"imageVersion,omitempty"`
WindowsImageSourceURL string `json:"WindowsImageSourceUrl"`
WindowsPublisher string `json:"WindowsPublisher"`
WindowsOffer string `json:"WindowsOffer"`
WindowsSku string `json:"WindowsSku"`
WindowsDockerVersion string `json:"windowsDockerVersion"`
Secrets []KeyVaultSecrets `json:"secrets,omitempty"`
SSHEnabled *bool `json:"sshEnabled,omitempty"`
EnableAutomaticUpdates *bool `json:"enableAutomaticUpdates,omitempty"`
IsCredentialAutoGenerated *bool `json:"isCredentialAutoGenerated,omitempty"`
EnableAHUB *bool `json:"enableAHUB,omitempty"`
}

// ProvisioningState represents the current state of container service resource.
Expand Down
5 changes: 5 additions & 0 deletions pkg/engine/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ func createAgentAvailabilitySetVM(cs *api.ContainerService, profile *api.AgentPo
}
agentCustomData := getCustomDataFromJSON(t.GetKubernetesWindowsNodeCustomDataJSONObject(cs, profile))
osProfile.CustomData = to.StringPtr(agentCustomData)

if cs.Properties.WindowsProfile.GetEnableAHUB() {
licenseType := api.WindowsLicenseTypeServer
virtualMachine.LicenseType = &licenseType
}
}

virtualMachine.OsProfile = &osProfile
Expand Down
15 changes: 15 additions & 0 deletions pkg/engine/virtualmachines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ func TestCreateAgentAvailabilitySetVM(t *testing.T) {
if diff != "" {
t.Errorf("unexpected diff while expecting equal structs: %s", diff)
}

cs.Properties.WindowsProfile = &api.WindowsProfile{
SSHEnabled: &trueVar,
EnableAHUB: &trueVar,
}

actualVM = createAgentAvailabilitySetVM(cs, profile)
licenseType := api.WindowsLicenseTypeServer
expectedVM.VirtualMachine.VirtualMachineProperties.LicenseType = &licenseType

diff = cmp.Diff(actualVM, expectedVM)

if diff != "" {
t.Errorf("unexpected diff while expecting equal structs: %s", diff)
}
}

func TestCreateVmWithCustomTags(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/engine/virtualmachinescalesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,11 @@ func CreateAgentVMSS(cs *api.ContainerService, profile *api.AgentPoolProfile) Vi
CustomData: to.StringPtr(customDataStr),
}
vmssVMProfile.OsProfile = &windowsOsProfile

if cs.Properties.WindowsProfile.GetEnableAHUB() {
licenseType := api.WindowsLicenseTypeServer
vmssVMProfile.LicenseType = &licenseType
}
} else {
customDataStr := getCustomDataFromJSON(t.GetKubernetesLinuxNodeCustomDataJSONObject(cs, profile))
linuxOsProfile := compute.VirtualMachineScaleSetOSProfile{
Expand Down
16 changes: 16 additions & 0 deletions pkg/engine/virtualmachinescalesets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,22 @@ func TestCreateAgentVMSSHostedMasterProfile(t *testing.T) {
if diff != "" {
t.Errorf("unexpected diff while expecting equal structs: %s", diff)
}

// Now Test AgentVMSS with windows and LicenseType
licenseType := api.WindowsLicenseTypeServer
cs.Properties.WindowsProfile = &api.WindowsProfile{
SSHEnabled: &trueVar,
EnableAHUB: &trueVar,
}

actual = CreateAgentVMSS(cs, cs.Properties.AgentPoolProfiles[0])
expected.VirtualMachineProfile.LicenseType = &licenseType

diff = cmp.Diff(actual, expected)

if diff != "" {
t.Errorf("unexpected diff while expecting equal structs: %s", diff)
}
}

func getIPConfigsMaster() *[]compute.VirtualMachineScaleSetIPConfiguration {
Expand Down