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

more general vlabs kubernetes defaults enforcement #1932

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions pkg/api/convertertoapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ func convertVLabsOrchestratorProfile(vp *vlabs.Properties, api *OrchestratorProf
api.KubernetesConfig = &KubernetesConfig{}
convertVLabsKubernetesConfig(vp, api.KubernetesConfig)
}
setVlabsKubernetesDefaults(vp, api)
api.OrchestratorVersion = common.RationalizeReleaseAndVersion(
vlabscs.OrchestratorType,
vlabscs.OrchestratorRelease,
Expand Down Expand Up @@ -620,15 +621,17 @@ func convertVLabsKubernetesConfig(vp *vlabs.Properties, api *KubernetesConfig) {
api.EtcdVersion = vlabs.EtcdVersion
api.EtcdDiskSizeGB = vlabs.EtcdDiskSizeGB
convertAddonsToAPI(vlabs, api)
setVlabsDefaultsKubernetesConfig(vp, api)
}

func setVlabsDefaultsKubernetesConfig(vp *vlabs.Properties, api *KubernetesConfig) {
if api.NetworkPolicy == "" {
func setVlabsKubernetesDefaults(vp *vlabs.Properties, api *OrchestratorProfile) {
if api.KubernetesConfig == nil {
api.KubernetesConfig = &KubernetesConfig{}
}
if api.KubernetesConfig.NetworkPolicy == "" {
if vp.HasWindows() {
api.NetworkPolicy = vlabs.DefaultNetworkPolicyWindows
api.KubernetesConfig.NetworkPolicy = vlabs.DefaultNetworkPolicyWindows
} else {
api.NetworkPolicy = vlabs.DefaultNetworkPolicy
api.KubernetesConfig.NetworkPolicy = vlabs.DefaultNetworkPolicy
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions pkg/api/convertertoapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,41 @@ func TestOrchestratorVersion(t *testing.T) {
t.Fatalf("incorrect OrchestratorVersion '%s'", cs.Properties.OrchestratorProfile.OrchestratorVersion)
}
}

func TestKubernetesVlabsDefaults(t *testing.T) {
vp := makeKubernetesPropertiesVlabs()
ap := makeKubernetesProperties()
setVlabsKubernetesDefaults(vp, ap.OrchestratorProfile)
if ap.OrchestratorProfile.KubernetesConfig == nil {
t.Fatalf("KubernetesConfig cannot be nil after vlabs default conversion")
}
if ap.OrchestratorProfile.KubernetesConfig.NetworkPolicy != vlabs.DefaultNetworkPolicy {
t.Fatalf("vlabs defaults not applied, expected NetworkPolicy: %s, instead got: %s", vlabs.DefaultNetworkPolicy, ap.OrchestratorProfile.KubernetesConfig.NetworkPolicy)
}

vp = makeKubernetesPropertiesVlabs()
vp.WindowsProfile = &vlabs.WindowsProfile{}
vp.AgentPoolProfiles = append(vp.AgentPoolProfiles, &vlabs.AgentPoolProfile{OSType: "Windows"})
ap = makeKubernetesProperties()
setVlabsKubernetesDefaults(vp, ap.OrchestratorProfile)
if ap.OrchestratorProfile.KubernetesConfig == nil {
t.Fatalf("KubernetesConfig cannot be nil after vlabs default conversion")
}
if ap.OrchestratorProfile.KubernetesConfig.NetworkPolicy != vlabs.DefaultNetworkPolicyWindows {
t.Fatalf("vlabs defaults not applied, expected NetworkPolicy: %s, instead got: %s", vlabs.DefaultNetworkPolicyWindows, ap.OrchestratorProfile.KubernetesConfig.NetworkPolicy)
}
}

func makeKubernetesProperties() *Properties {
ap := &Properties{}
ap.OrchestratorProfile = &OrchestratorProfile{}
ap.OrchestratorProfile.OrchestratorType = "Kubernetes"
return ap
}

func makeKubernetesPropertiesVlabs() *vlabs.Properties {
vp := &vlabs.Properties{}
vp.OrchestratorProfile = &vlabs.OrchestratorProfile{}
vp.OrchestratorProfile.OrchestratorType = "Kubernetes"
return vp
}