From 751c186f7698c34b238c6822b736ef07ceaedbc8 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Mon, 5 Oct 2020 17:00:51 -0700 Subject: [PATCH] Simplify code since MasterProfile is always nil in AgentBaker. (#365) * Simplify code since MasterProfile is always nil in AgentBaker. * Remove the unnecessary !hasZone check. --- cmd/generate.go | 6 +- pkg/agent/baker.go | 2 +- pkg/agent/datamodel/types.go | 14 +-- pkg/agent/datamodel/types_test.go | 202 +----------------------------- pkg/agent/params.go | 17 +-- 5 files changed, 9 insertions(+), 232 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index 56d4fb2677c..5a9894ea202 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -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 diff --git a/pkg/agent/baker.go b/pkg/agent/baker.go index 66079499157..4c8753b8611 100644 --- a/pkg/agent/baker.go +++ b/pkg/agent/baker.go @@ -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() diff --git a/pkg/agent/datamodel/types.go b/pkg/agent/datamodel/types.go index b3be76b669f..1bb8bea056f 100644 --- a/pkg/agent/datamodel/types.go +++ b/pkg/agent/datamodel/types.go @@ -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 } @@ -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 @@ -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)) @@ -826,9 +821,6 @@ func (p *Properties) IsVHDDistroForAllNodes() bool { } } } - if p.MasterProfile != nil { - return p.MasterProfile.IsVHDDistro() - } return true } diff --git a/pkg/agent/datamodel/types_test.go b/pkg/agent/datamodel/types_test.go index 84dc22faea1..e73fc926412 100644 --- a/pkg/agent/datamodel/types_test.go +++ b/pkg/agent/datamodel/types_test.go @@ -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{ @@ -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 { @@ -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{ @@ -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{ @@ -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) { @@ -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{ { diff --git a/pkg/agent/params.go b/pkg/agent/params.go index eaa959b9a84..7eeafc2b9bd 100644 --- a/pkg/agent/params.go +++ b/pkg/agent/params.go @@ -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) } @@ -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 {