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

Refactor: Moving set defaults logic from package acsengine to package api #3974

Merged
merged 20 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 15 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
8 changes: 7 additions & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,13 @@ func (dc *deployCmd) run() error {
log.Fatalf("failed to initialize template generator: %s", err.Error())
}

template, parameters, certsgenerated, err := templateGenerator.GenerateTemplate(dc.containerService, acsengine.DefaultGeneratorCode, false, false, BuildTag)
certsgenerated, err := dc.containerService.SetPropertiesDefaults(false, false)
if err != nil {
log.Fatalf("error in SetPropertiesDefaults template %s: %s", dc.apimodelPath, err.Error())
os.Exit(1)
}

template, parameters, err := templateGenerator.GenerateTemplate(dc.containerService, acsengine.DefaultGeneratorCode, BuildTag)
if err != nil {
log.Fatalf("error generating template %s: %s", dc.apimodelPath, err.Error())
os.Exit(1)
Expand Down
7 changes: 6 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ func (gc *generateCmd) run() error {
log.Fatalf("failed to initialize template generator: %s", err.Error())
}

template, parameters, certsGenerated, err := templateGenerator.GenerateTemplate(gc.containerService, acsengine.DefaultGeneratorCode, false, false, BuildTag)
certsGenerated, err := gc.containerService.SetPropertiesDefaults(false, false)
if err != nil {
log.Fatalf("error in SetPropertiesDefaults template %s: %s", gc.apimodelPath, err.Error())
os.Exit(1)
}
template, parameters, err := templateGenerator.GenerateTemplate(gc.containerService, acsengine.DefaultGeneratorCode, BuildTag)
if err != nil {
log.Fatalf("error generating template %s: %s", gc.apimodelPath, err.Error())
os.Exit(1)
Expand Down
7 changes: 6 additions & 1 deletion cmd/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@ func (sc *scaleCmd) run(cmd *cobra.Command, args []string) error {

sc.containerService.Properties.AgentPoolProfiles = []*api.AgentPoolProfile{sc.agentPool}

template, parameters, _, err := templateGenerator.GenerateTemplate(sc.containerService, acsengine.DefaultGeneratorCode, false, true, BuildTag)
_, err = sc.containerService.SetPropertiesDefaults(false, true)
if err != nil {
log.Fatalf("error in SetPropertiesDefaults template %s: %s", sc.apiModelPath, err.Error())
os.Exit(1)
}
template, parameters, err := templateGenerator.GenerateTemplate(sc.containerService, acsengine.DefaultGeneratorCode, BuildTag)
if err != nil {
return errors.Wrapf(err, "error generating template %s", sc.apiModelPath)
}
Expand Down
110 changes: 1 addition & 109 deletions pkg/acsengine/const.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,8 @@
package acsengine

const (
// DefaultOpenShiftMasterSubnet is the default value for master subnet for Openshift.
DefaultOpenShiftMasterSubnet = "10.0.0.0/24"
// DefaultOpenShiftFirstConsecutiveStaticIP is the default static ip address for master 0 for Openshift.
DefaultOpenShiftFirstConsecutiveStaticIP = "10.0.0.11"
// DefaultMasterSubnet specifies the default master subnet for DCOS or Swarm
DefaultMasterSubnet = "172.16.0.0/24"
// DefaultFirstConsecutiveStaticIP specifies the static IP address on master 0 for DCOS or Swarm
DefaultFirstConsecutiveStaticIP = "172.16.0.5"
// DefaultSwarmWindowsMasterSubnet specifies the default master subnet for a Swarm Windows cluster
DefaultSwarmWindowsMasterSubnet = "192.168.255.0/24"
// DefaultSwarmWindowsFirstConsecutiveStaticIP specifies the static IP address on master 0 for a Swarm WIndows cluster
DefaultSwarmWindowsFirstConsecutiveStaticIP = "192.168.255.5"
// DefaultDCOSMasterSubnet specifies the default master subnet for a DCOS cluster
DefaultDCOSMasterSubnet = "192.168.255.0/24"
// DefaultDCOSFirstConsecutiveStaticIP specifies the static IP address on master 0 for a DCOS cluster
DefaultDCOSFirstConsecutiveStaticIP = "192.168.255.5"
// DefaultDCOSBootstrapStaticIP specifies the static IP address on bootstrap for a DCOS cluster
DefaultDCOSBootstrapStaticIP = "192.168.255.240"
// DefaultKubernetesMasterSubnet specifies the default subnet for masters and agents.
// Except when master VMSS is used, this specifies the default subnet for masters.
DefaultKubernetesMasterSubnet = "10.240.0.0/16"
// DefaultKubernetesClusterSubnet specifies the default subnet for pods.
DefaultKubernetesClusterSubnet = "10.244.0.0/16"
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
// DefaultDockerBridgeSubnet specifies the default subnet for the docker bridge network for masters and agents.
DefaultDockerBridgeSubnet = "172.17.0.1/16"
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
// DefaultAgentSubnetTemplate specifies a default agent subnet
DefaultAgentSubnetTemplate = "10.%d.0.0/16"
// DefaultKubernetesSubnet specifies the default subnet used for all masters, agents and pods
// when VNET integration is enabled.
DefaultKubernetesSubnet = "10.240.0.0/12"
// DefaultVNETCIDR is the default CIDR block for the VNET
DefaultVNETCIDR = "10.0.0.0/8"
// DefaultKubernetesMaxPods is the maximum number of pods to run on a node.
DefaultKubernetesMaxPods = 110
// DefaultKubernetesMaxPodsVNETIntegrated is the maximum number of pods to run on a node when VNET integration is enabled.
DefaultKubernetesMaxPodsVNETIntegrated = 30
// DefaultKubernetesClusterDomain is the dns suffix used in the cluster (used as a SAN in the PKI generation)
DefaultKubernetesClusterDomain = "cluster.local"
// DefaultInternalLbStaticIPOffset specifies the offset of the internal LoadBalancer's IP
// address relative to the first consecutive Kubernetes static IP
DefaultInternalLbStaticIPOffset = 10
Expand All @@ -56,34 +20,6 @@ const (
NetworkPluginKubenet = "kubenet"
// NetworkPluginFlannel is the string expression for flannel network policy config option
NetworkPluginFlannel = "flannel"
// DefaultNetworkPlugin defines the network plugin to use by default
DefaultNetworkPlugin = NetworkPluginKubenet
// DefaultNetworkPolicy defines the network policy implementation to use by default
DefaultNetworkPolicy = ""
// DefaultNetworkPluginWindows defines the network plugin implementation to use by default for clusters with Windows agent pools
DefaultNetworkPluginWindows = NetworkPluginKubenet
// DefaultNetworkPolicyWindows defines the network policy implementation to use by default for clusters with Windows agent pools
DefaultNetworkPolicyWindows = ""
// DefaultContainerRuntime is docker
DefaultContainerRuntime = "docker"
// DefaultKubernetesNodeStatusUpdateFrequency is 10s, see --node-status-update-frequency at https://kubernetes.io/docs/admin/kubelet/
DefaultKubernetesNodeStatusUpdateFrequency = "10s"
// DefaultKubernetesHardEvictionThreshold is memory.available<100Mi,nodefs.available<10%,nodefs.inodesFree<5%, see --eviction-hard at https://kubernetes.io/docs/admin/kubelet/
DefaultKubernetesHardEvictionThreshold = "memory.available<100Mi,nodefs.available<10%,nodefs.inodesFree<5%"
// DefaultKubernetesCtrlMgrNodeMonitorGracePeriod is 40s, see --node-monitor-grace-period at https://kubernetes.io/docs/admin/kube-controller-manager/
DefaultKubernetesCtrlMgrNodeMonitorGracePeriod = "40s"
// DefaultKubernetesCtrlMgrPodEvictionTimeout is 5m0s, see --pod-eviction-timeout at https://kubernetes.io/docs/admin/kube-controller-manager/
DefaultKubernetesCtrlMgrPodEvictionTimeout = "5m0s"
// DefaultKubernetesCtrlMgrRouteReconciliationPeriod is 10s, see --route-reconciliation-period at https://kubernetes.io/docs/admin/kube-controller-manager/
DefaultKubernetesCtrlMgrRouteReconciliationPeriod = "10s"
// DefaultKubernetesCtrlMgrTerminatedPodGcThreshold is set to 5000, see --terminated-pod-gc-threshold at https://kubernetes.io/docs/admin/kube-controller-manager/ and https://github.com/kubernetes/kubernetes/issues/22680
DefaultKubernetesCtrlMgrTerminatedPodGcThreshold = "5000"
// DefaultKubernetesCtrlMgrUseSvcAccountCreds is "true", see --use-service-account-credentials at https://kubernetes.io/docs/admin/kube-controller-manager/
DefaultKubernetesCtrlMgrUseSvcAccountCreds = "false"
// DefaultKubernetesCloudProviderBackoff is false to disable cloudprovider backoff implementation for API calls
DefaultKubernetesCloudProviderBackoff = true
// DefaultKubernetesCloudProviderRateLimit is false to disable cloudprovider rate limiting implementation for API calls
DefaultKubernetesCloudProviderRateLimit = true
// DefaultKubeHeapsterDeploymentAddonName is the name of the kube-heapster-deployment addon
DefaultKubeHeapsterDeploymentAddonName = "kube-heapster-deployment"
// DefaultKubeDNSDeploymentAddonName is the name of the kube-dns-deployment addon
Expand Down Expand Up @@ -128,28 +64,8 @@ const (
DefaultKeyVaultFlexVolumeAddonName = "keyvault-flexvolume"
// DefaultELBSVCAddonName is the name of the elb service addon deployment
DefaultELBSVCAddonName = "elb-svc"
// DefaultKubernetesDNSServiceIP specifies the IP address that kube-dns
// listens on by default. must by in the default Service CIDR range.
DefaultKubernetesDNSServiceIP = "10.0.0.10"
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
// DefaultKubernetesServiceCIDR specifies the IP subnet that kubernetes will
// create Service IPs within.
DefaultKubernetesServiceCIDR = "10.0.0.0/16"
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
//DefaultKubernetesGCHighThreshold specifies the value for for the image-gc-high-threshold kubelet flag
DefaultKubernetesGCHighThreshold = 85
//DefaultKubernetesGCLowThreshold specifies the value for the image-gc-low-threshold kubelet flag
DefaultKubernetesGCLowThreshold = 80
// DefaultGeneratorCode specifies the source generator of the cluster template.
DefaultGeneratorCode = "acsengine"
// DefaultEtcdVersion specifies the default etcd version to install
DefaultEtcdVersion = "3.2.23"
// DefaultEtcdDiskSize specifies the default size for Kubernetes master etcd disk volumes in GB
DefaultEtcdDiskSize = "256"
// DefaultEtcdDiskSizeGT3Nodes = size for Kubernetes master etcd disk volumes in GB if > 3 nodes
DefaultEtcdDiskSizeGT3Nodes = "512"
// DefaultEtcdDiskSizeGT10Nodes = size for Kubernetes master etcd disk volumes in GB if > 10 nodes
DefaultEtcdDiskSizeGT10Nodes = "1024"
// DefaultEtcdDiskSizeGT20Nodes = size for Kubernetes master etcd disk volumes in GB if > 20 nodes
DefaultEtcdDiskSizeGT20Nodes = "2048"
// DefaultReschedulerAddonName is the name of the rescheduler addon deployment
DefaultReschedulerAddonName = "rescheduler"
// DefaultMetricsServerAddonName is the name of the kubernetes Metrics server addon deployment
Expand All @@ -170,31 +86,10 @@ const (
DefaultMasterEtcdServerPort = 2380
// DefaultMasterEtcdClientPort is the default etcd client port for Kubernetes master nodes
DefaultMasterEtcdClientPort = 2379
// DefaultKubeletEventQPS is 0, see --event-qps at https://kubernetes.io/docs/reference/generated/kubelet/
DefaultKubeletEventQPS = "0"
// DefaultKubeletCadvisorPort is 0, see --cadvisor-port at https://kubernetes.io/docs/reference/generated/kubelet/
DefaultKubeletCadvisorPort = "0"
// DefaultJumpboxDiskSize specifies the default size for private cluster jumpbox OS disk in GB
DefaultJumpboxDiskSize = 30
// DefaultJumpboxUsername specifies the default admin username for the private cluster jumpbox
DefaultJumpboxUsername = "azureuser"
// DefaultKubeletPodMaxPIDs specifies the default max pid authorized by pods
DefaultKubeletPodMaxPIDs = 100
// DefaultKubernetesAgentSubnetVMSS specifies the default subnet for agents when master is VMSS
DefaultKubernetesAgentSubnetVMSS = "10.248.0.0/13"
// DefaultUserAssignedID specifies the default name for the user assigned identity
DefaultUserAssignedID = "acsenginetestid"
)

const (
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
// DCOSMaster represents the master node type
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
DCOSMaster DCOSNodeType = "DCOSMaster"
// DCOSPrivateAgent represents the private agent node type
DCOSPrivateAgent DCOSNodeType = "DCOSPrivateAgent"
// DCOSPublicAgent represents the public agent node type
DCOSPublicAgent DCOSNodeType = "DCOSPublicAgent"
)

const (
//DefaultExtensionsRootURL Root URL for extensions
DefaultExtensionsRootURL = "https://raw.githubusercontent.com/Azure/acs-engine/master/"
Expand Down Expand Up @@ -301,8 +196,5 @@ const (
)

const (
azurePublicCloud = "AzurePublicCloud"
azureChinaCloud = "AzureChinaCloud"
azureGermanCloud = "AzureGermanCloud"
azureUSGovernmentCloud = "AzureUSGovernmentCloud"
azurePublicCloud = "AzurePublicCloud"
)
27 changes: 1 addition & 26 deletions pkg/acsengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func GenerateKubeConfig(properties *api.Properties, location string) (string, er
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVerbatim \"reference(concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))).dnsSettings.fqdn\"}}", properties.MasterProfile.FirstConsecutiveStaticIP, -1)
}
} else {
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVerbatim \"reference(concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))).dnsSettings.fqdn\"}}", FormatAzureProdFQDN(properties.MasterProfile.DNSPrefix, location), -1)
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVerbatim \"reference(concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))).dnsSettings.fqdn\"}}", api.FormatAzureProdFQDNByLocation(properties.MasterProfile.DNSPrefix, location), -1)
}
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVariable \"resourceGroup\"}}", properties.MasterProfile.DNSPrefix, -1)

Expand All @@ -102,31 +102,6 @@ func GenerateKubeConfig(properties *api.Properties, location string) (string, er
return kubeconfig, nil
}

// formatAzureProdFQDNs constructs all possible Azure prod fqdn
func formatAzureProdFQDNs(fqdnPrefix string) []string {
var fqdns []string
for _, location := range AzureLocations {
fqdns = append(fqdns, FormatAzureProdFQDN(fqdnPrefix, location))
}
return fqdns
}

// FormatAzureProdFQDN constructs an Azure prod fqdn
func FormatAzureProdFQDN(fqdnPrefix string, location string) string {
var FQDNFormat string
switch helpers.GetCloudTargetEnv(location) {
case azureChinaCloud:
FQDNFormat = api.AzureChinaCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix
case azureGermanCloud:
FQDNFormat = api.AzureGermanCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix
case azureUSGovernmentCloud:
FQDNFormat = api.AzureUSGovernmentCloud.EndpointConfig.ResourceManagerVMDNSSuffix
default:
FQDNFormat = api.AzureCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix
}
return fmt.Sprintf("%s.%s."+FQDNFormat, fqdnPrefix, location)
}

// validateDistro checks if the requested orchestrator type is supported on the requested Linux distro.
func validateDistro(cs *api.ContainerService) bool {
// Check Master distro
Expand Down
72 changes: 7 additions & 65 deletions pkg/acsengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"path"
"path/filepath"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -73,7 +72,9 @@ func TestExpected(t *testing.T) {
continue
}

armTemplate, params, certsGenerated, err := templateGenerator.GenerateTemplate(containerService, DefaultGeneratorCode, false, false, TestACSEngineVersion)
certsGenerated, err := containerService.SetPropertiesDefaults(false, false)

armTemplate, params, err := templateGenerator.GenerateTemplate(containerService, DefaultGeneratorCode, TestACSEngineVersion)
if err != nil {
t.Error(errors.Errorf("error in file %s: %s", tuple.APIModelFilename, err.Error()))
continue
Expand All @@ -97,7 +98,8 @@ func TestExpected(t *testing.T) {
}

for i := 0; i < 3; i++ {
armTemplate, params, certsGenerated, err := templateGenerator.GenerateTemplate(containerService, DefaultGeneratorCode, false, false, TestACSEngineVersion)
certsGenerated, err = containerService.SetPropertiesDefaults(false, false)
armTemplate, params, err := templateGenerator.GenerateTemplate(containerService, DefaultGeneratorCode, TestACSEngineVersion)
if err != nil {
t.Error(errors.Errorf("error in file %s: %s", tuple.APIModelFilename, err.Error()))
continue
Expand Down Expand Up @@ -290,7 +292,8 @@ func TestTemplateOutputPresence(t *testing.T) {
if err != nil {
t.Fatalf("Failed to load container service from file: %v", err)
}
armTemplate, _, _, err := templateGenerator.GenerateTemplate(containerService, DefaultGeneratorCode, false, false, TestACSEngineVersion)
containerService.SetPropertiesDefaults(false, false)
armTemplate, _, err := templateGenerator.GenerateTemplate(containerService, DefaultGeneratorCode, TestACSEngineVersion)
if err != nil {
t.Fatalf("Failed to generate arm template: %v", err)
}
Expand Down Expand Up @@ -557,64 +560,3 @@ func TestGenerateKubeConfig(t *testing.T) {
t.Fatalf("Expected an error result from nil Properties child properties")
}
}

func TestFormatAzureProdFQDN(t *testing.T) {
dnsPrefix := "santest"

actual := formatAzureProdFQDNs(dnsPrefix)

expected := []string{
"santest.australiacentral.cloudapp.azure.com",
"santest.australiacentral2.cloudapp.azure.com",
"santest.australiaeast.cloudapp.azure.com",
"santest.australiasoutheast.cloudapp.azure.com",
"santest.brazilsouth.cloudapp.azure.com",
"santest.canadacentral.cloudapp.azure.com",
"santest.canadaeast.cloudapp.azure.com",
"santest.centralindia.cloudapp.azure.com",
"santest.centralus.cloudapp.azure.com",
"santest.centraluseuap.cloudapp.azure.com",
"santest.chinaeast.cloudapp.chinacloudapi.cn",
"santest.chinaeast2.cloudapp.chinacloudapi.cn",
"santest.chinanorth.cloudapp.chinacloudapi.cn",
"santest.chinanorth2.cloudapp.chinacloudapi.cn",
"santest.eastasia.cloudapp.azure.com",
"santest.eastus.cloudapp.azure.com",
"santest.eastus2.cloudapp.azure.com",
"santest.eastus2euap.cloudapp.azure.com",
"santest.francecentral.cloudapp.azure.com",
"santest.francesouth.cloudapp.azure.com",
"santest.japaneast.cloudapp.azure.com",
"santest.japanwest.cloudapp.azure.com",
"santest.koreacentral.cloudapp.azure.com",
"santest.koreasouth.cloudapp.azure.com",
"santest.northcentralus.cloudapp.azure.com",
"santest.northeurope.cloudapp.azure.com",
"santest.southcentralus.cloudapp.azure.com",
"santest.southeastasia.cloudapp.azure.com",
"santest.southindia.cloudapp.azure.com",
"santest.uksouth.cloudapp.azure.com",
"santest.ukwest.cloudapp.azure.com",
"santest.westcentralus.cloudapp.azure.com",
"santest.westeurope.cloudapp.azure.com",
"santest.westindia.cloudapp.azure.com",
"santest.westus.cloudapp.azure.com",
"santest.westus2.cloudapp.azure.com",
"santest.chinaeast.cloudapp.chinacloudapi.cn",
"santest.chinanorth.cloudapp.chinacloudapi.cn",
"santest.chinanorth2.cloudapp.chinacloudapi.cn",
"santest.chinaeast2.cloudapp.chinacloudapi.cn",
"santest.germanycentral.cloudapp.microsoftazure.de",
"santest.germanynortheast.cloudapp.microsoftazure.de",
"santest.usgovvirginia.cloudapp.usgovcloudapi.net",
"santest.usgoviowa.cloudapp.usgovcloudapi.net",
"santest.usgovarizona.cloudapp.usgovcloudapi.net",
"santest.usgovtexas.cloudapp.usgovcloudapi.net",
"santest.francecentral.cloudapp.azure.com",
}

if !reflect.DeepEqual(actual, expected) {
t.Errorf("expected formatted fqdns %s, but got %s", expected, actual)
}

}
2 changes: 1 addition & 1 deletion pkg/acsengine/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (w *ArtifactWriter) WriteTLSArtifacts(containerService *api.ContainerServic
if containerService.Location != "" {
locations = []string{containerService.Location}
} else {
locations = AzureLocations
locations = helpers.GetAzureLocations()
}

for _, location := range locations {
Expand Down
6 changes: 4 additions & 2 deletions pkg/acsengine/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"path"
"testing"

"github.com/Azure/acs-engine/pkg/api"
"github.com/Azure/acs-engine/pkg/helpers"
"github.com/Azure/acs-engine/pkg/i18n"
)

func TestWriteTLSArtifacts(t *testing.T) {

cs := CreateMockContainerService("testcluster", defaultTestClusterVer, 1, 2, true)
cs := api.CreateMockContainerService("testcluster", "1.7.12", 1, 2, true)
writer := &ArtifactWriter{
Translator: &i18n.Translator{
Locale: nil,
Expand Down Expand Up @@ -75,7 +77,7 @@ func TestWriteTLSArtifacts(t *testing.T) {
t.Fatalf("unexpected error trying to write TLS artifacts: %s", err.Error())
}

for _, region := range AzureLocations {
for _, region := range helpers.GetAzureLocations() {
if _, err := os.Stat(kubeDir + "/" + "kubeconfig." + region + ".json"); os.IsNotExist(err) {
t.Fatalf("expected kubeconfig for region %s to be generated by WriteTLSArtifacts", region)
}
Expand Down
Loading