Skip to content

Commit

Permalink
feat: Enabling SSH on windows nodes by default (Azure#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
marosset authored and AbelHu committed May 26, 2020
1 parent 2c68d52 commit 326e014
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 46 deletions.
2 changes: 2 additions & 0 deletions pkg/api/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ const (
DefaultNonMasqueradeCIDR = "0.0.0.0/0"
// DefaultKubeProxyMode is the default KubeProxyMode value
DefaultKubeProxyMode KubeProxyMode = KubeProxyModeIPTables
// DefaultWindowsSSHEnabled is the default windowsProfile.sshEnabled value
DefaultWindowsSSHEnabled = true
)

const (
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/converterfromapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ func convertWindowsProfileToVLabs(api *WindowsProfile, vlabsProfile *vlabs.Windo
convertKeyVaultSecretsToVlabs(&s, secret)
vlabsProfile.Secrets = append(vlabsProfile.Secrets, *secret)
}
vlabsProfile.SSHEnabled = api.SSHEnabled
if api.SSHEnabled != nil {
vlabsProfile.SSHEnabled = api.SSHEnabled
}
vlabsProfile.EnableAutomaticUpdates = api.EnableAutomaticUpdates
if api.LicenseType != nil {
licenseType := vlabs.WindowsLicenseType(*api.LicenseType)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/converterfromapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ func TestConvertWindowsProfileToVlabs(t *testing.T) {
AdminPassword: "password",
EnableAutomaticUpdates: &falseVar,
ImageVersion: "17763.615.1907121548",
SSHEnabled: false,
SSHEnabled: &falseVar,
WindowsPublisher: "MicrosoftWindowsServer",
WindowsOffer: "WindowsServer",
WindowsSku: "2019-Datacenter-Core-smalldisk",
Expand All @@ -778,7 +778,7 @@ func TestConvertWindowsProfileToVlabs(t *testing.T) {
AdminPassword: "password",
EnableAutomaticUpdates: &falseVar,
ImageVersion: "17763.615.1907121548",
SSHEnabled: false,
SSHEnabled: &falseVar,
WindowsPublisher: "MicrosoftWindowsServer",
WindowsOffer: "WindowsServer",
WindowsSku: "2019-Datacenter-Core-smalldisk",
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/convertertoapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ func convertVLabsWindowsProfile(vlabs *vlabs.WindowsProfile, api *WindowsProfile
convertVLabsKeyVaultSecrets(&s, secret)
api.Secrets = append(api.Secrets, *secret)
}
api.SSHEnabled = vlabs.SSHEnabled
if vlabs.SSHEnabled != nil {
api.SSHEnabled = vlabs.SSHEnabled
}
api.EnableAutomaticUpdates = vlabs.EnableAutomaticUpdates
if vlabs.LicenseType != nil {
licenseType := WindowsLicenseType(*vlabs.LicenseType)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/convertertoapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ func TestConvertVLabsWindowsProfile(t *testing.T) {
AdminPassword: "password",
EnableAutomaticUpdates: &falseVar,
ImageVersion: "17763.615.1907121548",
SSHEnabled: false,
SSHEnabled: &falseVar,
WindowsPublisher: "MicrosoftWindowsServer",
WindowsOffer: "WindowsServer",
WindowsSku: "2019-Datacenter-Core-smalldisk",
Expand All @@ -888,7 +888,7 @@ func TestConvertVLabsWindowsProfile(t *testing.T) {
AdminPassword: "password",
EnableAutomaticUpdates: &falseVar,
ImageVersion: "17763.615.1907121548",
SSHEnabled: false,
SSHEnabled: &falseVar,
WindowsPublisher: "MicrosoftWindowsServer",
WindowsOffer: "WindowsServer",
WindowsSku: "2019-Datacenter-Core-smalldisk",
Expand Down
60 changes: 44 additions & 16 deletions pkg/api/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,24 +712,52 @@ func (p *Properties) setAgentProfileDefaults(isUpgrade, isScale bool) {
func (p *Properties) setWindowsProfileDefaults(isUpgrade, isScale bool) {
windowsProfile := p.WindowsProfile
if !isUpgrade && !isScale {
if windowsProfile.WindowsPublisher == "" {
windowsProfile.WindowsPublisher = AKSWindowsServer2019OSImageConfig.ImagePublisher
}
if windowsProfile.WindowsOffer == "" {
windowsProfile.WindowsOffer = AKSWindowsServer2019OSImageConfig.ImageOffer
}
if windowsProfile.WindowsSku == "" {
windowsProfile.WindowsSku = AKSWindowsServer2019OSImageConfig.ImageSku
if windowsProfile.SSHEnabled == nil {
windowsProfile.SSHEnabled = to.BoolPtr(DefaultWindowsSSHEnabled)
}

if windowsProfile.ImageVersion == "" {
// default versions are specific to a publisher/offer/sku
if windowsProfile.WindowsPublisher == AKSWindowsServer2019OSImageConfig.ImagePublisher && windowsProfile.WindowsOffer == AKSWindowsServer2019OSImageConfig.ImageOffer && windowsProfile.WindowsSku == AKSWindowsServer2019OSImageConfig.ImageSku {
windowsProfile.ImageVersion = AKSWindowsServer2019OSImageConfig.ImageVersion
} else if windowsProfile.WindowsPublisher == WindowsServer2019OSImageConfig.ImagePublisher && windowsProfile.WindowsOffer == WindowsServer2019OSImageConfig.ImageOffer && windowsProfile.WindowsSku == WindowsServer2019OSImageConfig.ImageSku {
windowsProfile.ImageVersion = WindowsServer2019OSImageConfig.ImageVersion
} else {
windowsProfile.ImageVersion = "latest"
// This allows caller to use the latest ImageVersion and WindowsSku for adding a new Windows pool to an existing cluster.
// We must assure that same WindowsPublisher and WindowsOffer are used in an existing cluster.
if windowsProfile.WindowsPublisher == AKSWindowsServer2019OSImageConfig.ImagePublisher && windowsProfile.WindowsOffer == AKSWindowsServer2019OSImageConfig.ImageOffer {
if windowsProfile.WindowsSku == "" {
windowsProfile.WindowsSku = AKSWindowsServer2019OSImageConfig.ImageSku
}
if windowsProfile.ImageVersion == "" {
if windowsProfile.WindowsSku == AKSWindowsServer2019OSImageConfig.ImageSku {
windowsProfile.ImageVersion = AKSWindowsServer2019OSImageConfig.ImageVersion
} else {
windowsProfile.ImageVersion = "latest"
}
}
} else if windowsProfile.WindowsPublisher == WindowsServer2019OSImageConfig.ImagePublisher && windowsProfile.WindowsOffer == WindowsServer2019OSImageConfig.ImageOffer {
if windowsProfile.WindowsSku == "" {
windowsProfile.WindowsSku = WindowsServer2019OSImageConfig.ImageSku
}
if windowsProfile.ImageVersion == "" {
if windowsProfile.WindowsSku == WindowsServer2019OSImageConfig.ImageSku {
windowsProfile.ImageVersion = WindowsServer2019OSImageConfig.ImageVersion
} else {
windowsProfile.ImageVersion = "latest"
}
}
} else {
if windowsProfile.WindowsPublisher == "" {
windowsProfile.WindowsPublisher = AKSWindowsServer2019OSImageConfig.ImagePublisher
}
if windowsProfile.WindowsOffer == "" {
windowsProfile.WindowsOffer = AKSWindowsServer2019OSImageConfig.ImageOffer
}
if windowsProfile.WindowsSku == "" {
windowsProfile.WindowsSku = AKSWindowsServer2019OSImageConfig.ImageSku
}

if windowsProfile.ImageVersion == "" {
// default versions are specific to a publisher/offer/sku
if windowsProfile.WindowsPublisher == AKSWindowsServer2019OSImageConfig.ImagePublisher && windowsProfile.WindowsOffer == AKSWindowsServer2019OSImageConfig.ImageOffer && windowsProfile.WindowsSku == AKSWindowsServer2019OSImageConfig.ImageSku {
windowsProfile.ImageVersion = AKSWindowsServer2019OSImageConfig.ImageVersion
} else {
windowsProfile.ImageVersion = "latest"
}
}
}
} else if isUpgrade {
Expand Down
97 changes: 82 additions & 15 deletions pkg/api/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ func TestDistroDefaults(t *testing.T) {
}

func TestWindowsProfileDefaults(t *testing.T) {
trueVar := true

var tests = []struct {
name string // test case name
Expand All @@ -1764,7 +1765,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: &trueVar,
},
false,
false,
Expand All @@ -1786,14 +1787,36 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: &trueVar,
},
false,
false,
false,
},
{
"aks vhd specific version in creating",
"aks vhd override sku in creating",
WindowsProfile{
WindowsPublisher: AKSWindowsServer2019OSImageConfig.ImagePublisher,
WindowsOffer: AKSWindowsServer2019OSImageConfig.ImageOffer,
WindowsSku: "override",
},
WindowsProfile{
WindowsPublisher: AKSWindowsServer2019OSImageConfig.ImagePublisher,
WindowsOffer: AKSWindowsServer2019OSImageConfig.ImageOffer,
WindowsSku: "override",
ImageVersion: "latest",
AdminUsername: "",
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: &trueVar,
},
false,
false,
false,
},
{
"aks vhd override version in creating",
WindowsProfile{
WindowsPublisher: AKSWindowsServer2019OSImageConfig.ImagePublisher,
WindowsOffer: AKSWindowsServer2019OSImageConfig.ImageOffer,
Expand All @@ -1809,7 +1832,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: &trueVar,
},
false,
false,
Expand All @@ -1831,7 +1854,51 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: &trueVar,
},
false,
false,
false,
},
{
"vanilla vhd override sku in creating",
WindowsProfile{
WindowsPublisher: WindowsServer2019OSImageConfig.ImagePublisher,
WindowsOffer: WindowsServer2019OSImageConfig.ImageOffer,
WindowsSku: "override",
},
WindowsProfile{
WindowsPublisher: WindowsServer2019OSImageConfig.ImagePublisher,
WindowsOffer: WindowsServer2019OSImageConfig.ImageOffer,
WindowsSku: "override",
ImageVersion: "latest",
AdminUsername: "",
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: &trueVar,
},
false,
false,
false,
},
{
"vanilla vhd override version in creating",
WindowsProfile{
WindowsPublisher: WindowsServer2019OSImageConfig.ImagePublisher,
WindowsOffer: WindowsServer2019OSImageConfig.ImageOffer,
ImageVersion: "override",
},
WindowsProfile{
WindowsPublisher: WindowsServer2019OSImageConfig.ImagePublisher,
WindowsOffer: WindowsServer2019OSImageConfig.ImageOffer,
WindowsSku: WindowsServer2019OSImageConfig.ImageSku,
ImageVersion: "override",
AdminUsername: "",
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: &trueVar,
},
false,
false,
Expand All @@ -1854,7 +1921,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: &trueVar,
},
false,
false,
Expand All @@ -1876,7 +1943,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: &trueVar,
},
false,
false,
Expand All @@ -1899,7 +1966,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: &trueVar,
},
false,
false,
Expand All @@ -1922,7 +1989,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: nil,
},
false,
true,
Expand All @@ -1945,7 +2012,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: nil,
},
false,
true,
Expand All @@ -1968,7 +2035,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: nil,
},
false,
true,
Expand All @@ -1991,7 +2058,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: nil,
},
false,
true,
Expand All @@ -2014,7 +2081,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: nil,
},
false,
true,
Expand All @@ -2037,7 +2104,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: nil,
},
false,
true,
Expand All @@ -2060,7 +2127,7 @@ func TestWindowsProfileDefaults(t *testing.T) {
AdminPassword: "",
WindowsImageSourceURL: "",
WindowsDockerVersion: "",
SSHEnabled: false,
SSHEnabled: nil,
},
false,
false,
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,14 @@ func (w *WindowsProfile) GetWindowsSku() string {
return KubernetesDefaultWindowsSku
}

// GetSSHEnabled gets it ssh should be enabled for Windows nodes
func (w *WindowsProfile) GetSSHEnabled() bool {
if w.SSHEnabled != nil {
return *w.SSHEnabled
}
return DefaultWindowsSSHEnabled
}

// GetEnableWindowsUpdate gets the flag for enable windows update or returns the default value
func (w *WindowsProfile) GetEnableWindowsUpdate() bool {
if w.EnableAutomaticUpdates != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,7 @@ func TestIsDCOS19(t *testing.T) {
}

func TestWindowsProfile(t *testing.T) {
trueVar := true
w := WindowsProfile{}

if w.HasSecrets() || w.HasCustomImage() {
Expand Down Expand Up @@ -3334,7 +3335,7 @@ func TestWindowsProfile(t *testing.T) {
w = WindowsProfile{
WindowsDockerVersion: "18.03.1-ee-3",
WindowsSku: "Datacenter-Core-1809-with-Containers-smalldisk",
SSHEnabled: true,
SSHEnabled: &trueVar,
IsCredentialAutoGenerated: to.BoolPtr(false),
LicenseType: &licenseType,
}
Expand All @@ -3349,7 +3350,7 @@ func TestWindowsProfile(t *testing.T) {
t.Fatalf("Expected GetWindowsSku() to equal Datacenter-Core-1809-with-Containers-smalldisk, got %s", windowsSku)
}

se := w.SSHEnabled
se := w.GetSSHEnabled()
if !se {
t.Fatalf("Expected SSHEnabled to return true, got %v", se)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/template_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func getContainerServiceFuncMap(cs *api.ContainerService) template.FuncMap {
return cs.Properties.WindowsProfile.HasCustomImage()
},
"WindowsSSHEnabled": func() bool {
return cs.Properties.WindowsProfile.SSHEnabled
return cs.Properties.WindowsProfile.GetSSHEnabled()
},
"GetConfigurationScriptRootURL": func() string {
linuxProfile := cs.Properties.LinuxProfile
Expand Down

0 comments on commit 326e014

Please sign in to comment.