Skip to content

Commit

Permalink
Simplify code since MasterProfile is always nil in AgentBaker. (Azure…
Browse files Browse the repository at this point in the history
…#365)

* Simplify code since MasterProfile is always nil in AgentBaker.

* Remove the unnecessary !hasZone check.
  • Loading branch information
yizhang4321 authored Oct 6, 2020
1 parent 213f681 commit 751c186
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 232 deletions.
6 changes: 1 addition & 5 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@ func (gc *generateCmd) loadAPIModel() error {
}

if gc.outputDirectory == "" {
if gc.containerService.Properties.MasterProfile != nil {
gc.outputDirectory = path.Join("_output", gc.containerService.Properties.MasterProfile.DNSPrefix)
} else {
gc.outputDirectory = path.Join("_output", gc.containerService.Properties.HostedMasterProfile.DNSPrefix)
}
gc.outputDirectory = path.Join("_output", gc.containerService.Properties.HostedMasterProfile.DNSPrefix)
}

// consume gc.caCertificatePath and gc.caPrivateKeyPath
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/baker.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func getContainerServiceFuncMap(config *NodeBootstrappingConfiguration) template
return cs.Properties.OrchestratorProfile.IsAzureCNI()
},
"HasCosmosEtcd": func() bool {
return cs.Properties.MasterProfile != nil && cs.Properties.MasterProfile.HasCosmosEtcd()
return false
},
"IsPrivateCluster": func() bool {
return cs.Properties.OrchestratorProfile.IsPrivateCluster()
Expand Down
14 changes: 3 additions & 11 deletions pkg/agent/datamodel/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,6 @@ func (p *Properties) HasWindows() bool {
// TotalNodes returns the total number of nodes in the cluster configuration
func (p *Properties) TotalNodes() int {
var totalNodes int
if p.MasterProfile != nil {
totalNodes = p.MasterProfile.Count
}
for _, pool := range p.AgentPoolProfiles {
totalNodes += pool.Count
}
Expand All @@ -708,8 +705,8 @@ func (p *Properties) TotalNodes() int {

// HasAvailabilityZones returns true if the cluster contains a profile with zones
func (p *Properties) HasAvailabilityZones() bool {
hasZones := p.MasterProfile != nil && p.MasterProfile.HasAvailabilityZones()
if !hasZones && p.AgentPoolProfiles != nil {
hasZones := false
if p.AgentPoolProfiles != nil {
for _, agentPoolProfile := range p.AgentPoolProfiles {
if agentPoolProfile.HasAvailabilityZones() {
hasZones = true
Expand Down Expand Up @@ -742,9 +739,7 @@ func (p *Properties) GetClusterID() string {
// the name suffix uniquely identifies the cluster and is generated off a hash
// from the master dns name
h := fnv.New64a()
if p.MasterProfile != nil {
h.Write([]byte(p.MasterProfile.DNSPrefix))
} else if p.HostedMasterProfile != nil {
if p.HostedMasterProfile != nil {
h.Write([]byte(p.HostedMasterProfile.DNSPrefix))
} else if len(p.AgentPoolProfiles) > 0 {
h.Write([]byte(p.AgentPoolProfiles[0].Name))
Expand Down Expand Up @@ -826,9 +821,6 @@ func (p *Properties) IsVHDDistroForAllNodes() bool {
}
}
}
if p.MasterProfile != nil {
return p.MasterProfile.IsVHDDistro()
}
return true
}

Expand Down
202 changes: 3 additions & 199 deletions pkg/agent/datamodel/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,6 @@ func TestTotalNodes(t *testing.T) {
p Properties
expected int
}{
{
name: "2 total nodes between master and pool",
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 1,
},
},
},
expected: 2,
},
{
name: "7 total nodes between 2 pools",
p: Properties{
Expand All @@ -290,20 +276,6 @@ func TestTotalNodes(t *testing.T) {
},
expected: 7,
},
{
name: "11 total nodes between master and pool",
p: Properties{
MasterProfile: &MasterProfile{
Count: 5,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 6,
},
},
},
expected: 11,
},
}

for _, c := range cases {
Expand Down Expand Up @@ -564,20 +536,6 @@ func TestGenerateClusterID(t *testing.T) {
properties *Properties
expectedClusterID string
}{
{
name: "From Master Profile",
properties: &Properties{
MasterProfile: &MasterProfile{
DNSPrefix: "foo_master",
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Name: "foo_agent0",
},
},
},
expectedClusterID: "24569115",
},
{
name: "From Hosted Master Profile",
properties: &Properties{
Expand Down Expand Up @@ -772,126 +730,6 @@ func TestIsVHDDistroForAllNodes(t *testing.T) {
p Properties
expected bool
}{
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: AKSUbuntu1604,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 1,
Distro: Ubuntu,
},
{
Count: 1,
Distro: AKSUbuntu1604,
},
},
},
expected: false,
},
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: AKSUbuntu1804,
},
},
expected: true,
},
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: Ubuntu1804,
},
},
expected: false,
},
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: AKSUbuntu1804,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 1,
Distro: AKSUbuntu1804,
},
{
Count: 1,
Distro: AKSUbuntu1804,
},
},
},
expected: true,
},
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: Ubuntu1804,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 1,
Distro: Ubuntu,
},
{
Count: 1,
Distro: Ubuntu1804Gen2,
},
},
},
expected: false,
},
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: Ubuntu1804,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 1,
Distro: Ubuntu1804,
},
},
},
expected: false,
},
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: AKSUbuntu1604,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 1,
OSType: Windows,
},
},
},
expected: false,
},
{
p: Properties{
MasterProfile: &MasterProfile{
Count: 1,
Distro: AKSUbuntu1804,
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Count: 1,
OSType: Windows,
},
},
},
expected: false,
},
{
p: Properties{
AgentPoolProfiles: []*AgentPoolProfile{
Expand Down Expand Up @@ -1187,39 +1025,6 @@ func TestGetRouteTableName(t *testing.T) {
if actualNSGName != expectedNSGName {
t.Errorf("expected route table name %s, but got %s", expectedNSGName, actualNSGName)
}

p = &Properties{
OrchestratorProfile: &OrchestratorProfile{
OrchestratorType: Kubernetes,
},
MasterProfile: &MasterProfile{
Count: 1,
DNSPrefix: "foo",
VMSize: "Standard_DS2_v2",
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Name: "agentpool",
VMSize: "Standard_D2_v2",
Count: 1,
AvailabilityProfile: VirtualMachineScaleSets,
},
},
}

actualRTName = p.GetRouteTableName()
expectedRTName = "k8s-master-28513887-routetable"

actualNSGName = p.GetNSGName()
expectedNSGName = "k8s-master-28513887-nsg"

if actualRTName != expectedRTName {
t.Errorf("expected route table name %s, but got %s", actualRTName, expectedRTName)
}

if actualNSGName != expectedNSGName {
t.Errorf("expected route table name %s, but got %s", actualNSGName, expectedNSGName)
}
}

func TestProperties_GetVirtualNetworkName(t *testing.T) {
Expand Down Expand Up @@ -1316,10 +1121,9 @@ func TestGetPrimaryAvailabilitySetName(t *testing.T) {
OrchestratorProfile: &OrchestratorProfile{
OrchestratorType: Kubernetes,
},
MasterProfile: &MasterProfile{
Count: 1,
DNSPrefix: "foo",
VMSize: "Standard_DS2_v2",
HostedMasterProfile: &HostedMasterProfile{
IPMasqAgent: false,
DNSPrefix: "foo",
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Expand Down
17 changes: 1 addition & 16 deletions pkg/agent/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ func getParameters(config *NodeBootstrappingConfiguration, generatorCode string,
}
}
// masterEndpointDNSNamePrefix is the basis for storage account creation across dcos, swarm, and k8s
if properties.MasterProfile != nil {
// MasterProfile exists, uses master DNS prefix
addValue(parametersMap, "masterEndpointDNSNamePrefix", properties.MasterProfile.DNSPrefix)
} else if properties.HostedMasterProfile != nil {
if properties.HostedMasterProfile != nil {
// Agents only, use cluster DNS prefix
addValue(parametersMap, "masterEndpointDNSNamePrefix", properties.HostedMasterProfile.DNSPrefix)
}
Expand Down Expand Up @@ -314,18 +311,6 @@ func assignKubernetesParameters(properties *datamodel.Properties, parametersMap
addSecret(parametersMap, "clientPrivateKey", certificateProfile.ClientPrivateKey, true)
addSecret(parametersMap, "kubeConfigCertificate", certificateProfile.KubeConfigCertificate, true)
addSecret(parametersMap, "kubeConfigPrivateKey", certificateProfile.KubeConfigPrivateKey, true)
if properties.MasterProfile != nil {
addSecret(parametersMap, "etcdServerCertificate", certificateProfile.EtcdServerCertificate, true)
addSecret(parametersMap, "etcdServerPrivateKey", certificateProfile.EtcdServerPrivateKey, true)
addSecret(parametersMap, "etcdClientCertificate", certificateProfile.EtcdClientCertificate, true)
addSecret(parametersMap, "etcdClientPrivateKey", certificateProfile.EtcdClientPrivateKey, true)
for i, pc := range certificateProfile.EtcdPeerCertificates {
addSecret(parametersMap, "etcdPeerCertificate"+strconv.Itoa(i), pc, true)
}
for i, pk := range certificateProfile.EtcdPeerPrivateKeys {
addSecret(parametersMap, "etcdPeerPrivateKey"+strconv.Itoa(i), pk, true)
}
}
}

if properties.AADProfile != nil {
Expand Down

0 comments on commit 751c186

Please sign in to comment.