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

Commit

Permalink
chore: more tests, get rid of dead code, rationalize GetPrimaryAvaila…
Browse files Browse the repository at this point in the history
…bilitySetName
  • Loading branch information
jackfrancis committed Apr 11, 2019
1 parent 63f70b8 commit 8f991cb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
4 changes: 3 additions & 1 deletion pkg/api/types.go
Expand Up @@ -889,7 +889,9 @@ func (p *Properties) GetNSGName() string {
// GetPrimaryAvailabilitySetName returns the name of the primary availability set of the cluster
func (p *Properties) GetPrimaryAvailabilitySetName() string {
if p.AgentPoolProfiles != nil {
return p.AgentPoolProfiles[0].Name + "-availabilitySet-" + p.GetClusterID()
if p.AgentPoolProfiles[0].AvailabilityProfile == AvailabilitySet {
return p.AgentPoolProfiles[0].Name + "-availabilitySet-" + p.GetClusterID()
}
}
return ""
}
Expand Down
44 changes: 43 additions & 1 deletion pkg/api/types_test.go
Expand Up @@ -2207,6 +2207,27 @@ func TestGetPrimaryAvailabilitySetName(t *testing.T) {
if got != expected {
t.Errorf("expected primary availability set name %s, but got %s", expected, got)
}

p.AgentPoolProfiles = []*AgentPoolProfile{
{
Name: "agentpool",
VMSize: "Standard_D2_v2",
Count: 1,
AvailabilityProfile: VirtualMachineScaleSets,
},
}
expected = ""
got = p.GetPrimaryAvailabilitySetName()
if got != expected {
t.Errorf("expected primary availability set name %s, but got %s", expected, got)
}

p.AgentPoolProfiles = nil
expected = ""
got = p.GetPrimaryAvailabilitySetName()
if got != expected {
t.Errorf("expected primary availability set name %s, but got %s", expected, got)
}
}

func TestGetPrimaryScaleSetName(t *testing.T) {
Expand All @@ -2232,14 +2253,35 @@ func TestGetPrimaryScaleSetName(t *testing.T) {
expected := "k8s-agentpool-28513887-vmss"
got := p.GetPrimaryScaleSetName()
if got != expected {
t.Errorf("expected primary availability set name %s, but got %s", expected, got)
t.Errorf("expected primary scaleset name %s, but got %s", expected, got)
}

// Test with Windows agentpool
p.AgentPoolProfiles[0].OSType = "Windows"

expected = "2851k8s00"
got = p.GetPrimaryScaleSetName()
if got != expected {
t.Errorf("expected primary scaleset name %s, but got %s", expected, got)
}

p.AgentPoolProfiles = []*AgentPoolProfile{
{
Name: "agentpool",
VMSize: "Standard_D2_v2",
Count: 1,
AvailabilityProfile: AvailabilitySet,
},
}
expected = ""
got = p.GetPrimaryScaleSetName()
if got != expected {
t.Errorf("expected primary availability set name %s, but got %s", expected, got)
}

p.AgentPoolProfiles = nil
expected = ""
got = p.GetPrimaryScaleSetName()
if got != expected {
t.Errorf("expected primary availability set name %s, but got %s", expected, got)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/engine/armvariables.go
Expand Up @@ -326,7 +326,6 @@ func getK8sMasterVars(cs *api.ContainerService) (map[string]interface{}, error)
}

if cs.Properties.AnyAgentUsesVirtualMachineScaleSets() {
masterVars["primaryScaleSetName"] = cs.Properties.GetPrimaryScaleSetName()
masterVars["primaryAvailabilitySetName"] = ""
masterVars["vmType"] = "vmss"
} else {
Expand All @@ -335,9 +334,9 @@ func getK8sMasterVars(cs *api.ContainerService) (map[string]interface{}, error)
} else {
masterVars["primaryAvailabilitySetName"] = ""
}
masterVars["primaryScaleSetName"] = ""
masterVars["vmType"] = "standard"
}
masterVars["primaryScaleSetName"] = cs.Properties.GetPrimaryScaleSetName()

if isHostedMaster {
masterVars["kubernetesAPIServerIP"] = "[parameters('kubernetesEndpoint')]"
Expand Down
6 changes: 0 additions & 6 deletions pkg/engine/template_generator.go
Expand Up @@ -968,12 +968,6 @@ func (t *TemplateGenerator) getTemplateFuncMap(cs *api.ContainerService) templat
"GetMasterEtcdClientPort": func() int {
return DefaultMasterEtcdClientPort
},
"GetPrimaryAvailabilitySetName": func() string {
return cs.Properties.GetPrimaryAvailabilitySetName()
},
"GetPrimaryScaleSetName": func() string {
return cs.Properties.GetPrimaryScaleSetName()
},
"UseCloudControllerManager": func() bool {
return cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager != nil && *cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager
},
Expand Down

0 comments on commit 8f991cb

Please sign in to comment.