diff --git a/pkg/acsengine/defaults-apiserver_test.go b/pkg/acsengine/defaults-apiserver_test.go index c0b3bc6c5d..4167aea8a9 100644 --- a/pkg/acsengine/defaults-apiserver_test.go +++ b/pkg/acsengine/defaults-apiserver_test.go @@ -4,14 +4,16 @@ import ( "testing" "github.com/Azure/acs-engine/pkg/api" - "github.com/Azure/acs-engine/pkg/api/common" + "github.com/Azure/acs-engine/pkg/helpers" "github.com/satori/uuid" ) +const defaultTestClusterVer = "1.7.12" + func TestAPIServerConfigEnableDataEncryptionAtRest(t *testing.T) { // Test EnableDataEncryptionAtRest = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableDataEncryptionAtRest = pointerToBool(true) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableDataEncryptionAtRest = helpers.PointerToBool(true) setAPIServerConfig(cs) a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if a["--experimental-encryption-provider-config"] != "/etc/kubernetes/encryption-config.yaml" { @@ -20,8 +22,8 @@ func TestAPIServerConfigEnableDataEncryptionAtRest(t *testing.T) { } // Test EnableDataEncryptionAtRest = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableDataEncryptionAtRest = pointerToBool(false) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableDataEncryptionAtRest = helpers.PointerToBool(false) setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if _, ok := a["--experimental-encryption-provider-config"]; ok { @@ -32,7 +34,7 @@ func TestAPIServerConfigEnableDataEncryptionAtRest(t *testing.T) { func TestAPIServerConfigEnableAggregatedAPIs(t *testing.T) { // Test EnableAggregatedAPIs = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) cs.Properties.OrchestratorProfile.KubernetesConfig.EnableAggregatedAPIs = true setAPIServerConfig(cs) a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig @@ -66,7 +68,7 @@ func TestAPIServerConfigEnableAggregatedAPIs(t *testing.T) { } // Test EnableAggregatedAPIs = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) cs.Properties.OrchestratorProfile.KubernetesConfig.EnableAggregatedAPIs = false setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig @@ -82,8 +84,8 @@ func TestAPIServerConfigEnableAggregatedAPIs(t *testing.T) { func TestAPIServerConfigUseCloudControllerManager(t *testing.T) { // Test UseCloudControllerManager = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = pointerToBool(true) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = helpers.PointerToBool(true) setAPIServerConfig(cs) a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if _, ok := a["--cloud-provider"]; ok { @@ -96,8 +98,8 @@ func TestAPIServerConfigUseCloudControllerManager(t *testing.T) { } // Test UseCloudControllerManager = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = pointerToBool(false) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = helpers.PointerToBool(false) setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if a["--cloud-provider"] != "azure" { @@ -112,7 +114,7 @@ func TestAPIServerConfigUseCloudControllerManager(t *testing.T) { func TestAPIServerConfigHasAadProfile(t *testing.T) { // Test HasAadProfile = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) cs.Properties.AADProfile = &api.AADProfile{ ServerAppID: "test-id", TenantID: "test-tenant", @@ -137,7 +139,7 @@ func TestAPIServerConfigHasAadProfile(t *testing.T) { } // Test China Cloud settings - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) cs.Properties.AADProfile = &api.AADProfile{ ServerAppID: "test-id", TenantID: "test-tenant", @@ -151,7 +153,7 @@ func TestAPIServerConfigHasAadProfile(t *testing.T) { } // Test HasAadProfile = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig for _, key := range []string{"--oidc-username-claim", "--oidc-groups-claim", "--oidc-client-id", "--oidc-issuer-url"} { @@ -164,8 +166,8 @@ func TestAPIServerConfigHasAadProfile(t *testing.T) { func TestAPIServerConfigEnableRbac(t *testing.T) { // Test EnableRbac = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = pointerToBool(true) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(true) setAPIServerConfig(cs) a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if a["--authorization-mode"] != "Node,RBAC" { @@ -174,8 +176,8 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { } // Test EnableRbac = true with 1.6 cluster - cs = createContainerService("testcluster", common.KubernetesVersion1Dot6Dot11, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = pointerToBool(true) + cs = createContainerService("testcluster", "1.6.11", 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(true) setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if a["--authorization-mode"] != "RBAC" { @@ -184,8 +186,8 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { } // Test EnableRbac = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = pointerToBool(false) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(false) setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if _, ok := a["--authorization-mode"]; ok { @@ -194,8 +196,8 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { } // Test EnableRbac = false with 1.6 cluster - cs = createContainerService("testcluster", common.KubernetesVersion1Dot6Dot11, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = pointerToBool(false) + cs = createContainerService("testcluster", "1.6.11", 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(false) setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if _, ok := a["--authorization-mode"]; ok { @@ -206,8 +208,8 @@ func TestAPIServerConfigEnableRbac(t *testing.T) { func TestAPIServerConfigEnableSecureKubelet(t *testing.T) { // Test EnableSecureKubelet = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = pointerToBool(true) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(true) setAPIServerConfig(cs) a := cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig if a["--kubelet-client-certificate"] != "/etc/kubernetes/certs/client.crt" { @@ -220,8 +222,8 @@ func TestAPIServerConfigEnableSecureKubelet(t *testing.T) { } // Test EnableSecureKubelet = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = pointerToBool(false) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(false) setAPIServerConfig(cs) a = cs.Properties.OrchestratorProfile.KubernetesConfig.APIServerConfig for _, key := range []string{"--kubelet-client-certificate", "--kubelet-client-key"} { @@ -275,8 +277,8 @@ func createContainerService(containerServiceName string, orchestratorVersion str cs.Properties.OrchestratorProfile.OrchestratorType = api.Kubernetes cs.Properties.OrchestratorProfile.OrchestratorVersion = orchestratorVersion cs.Properties.OrchestratorProfile.KubernetesConfig = &api.KubernetesConfig{ - EnableSecureKubelet: pointerToBool(api.DefaultSecureKubeletEnabled), - EnableRbac: pointerToBool(api.DefaultRBACEnabled), + EnableSecureKubelet: helpers.PointerToBool(api.DefaultSecureKubeletEnabled), + EnableRbac: helpers.PointerToBool(api.DefaultRBACEnabled), EtcdDiskSizeGB: DefaultEtcdDiskSize, ServiceCIDR: DefaultKubernetesServiceCIDR, DockerBridgeSubnet: DefaultDockerBridgeSubnet, diff --git a/pkg/acsengine/defaults-kubelet_test.go b/pkg/acsengine/defaults-kubelet_test.go index 03d10b8090..fd518ddd26 100644 --- a/pkg/acsengine/defaults-kubelet_test.go +++ b/pkg/acsengine/defaults-kubelet_test.go @@ -3,13 +3,13 @@ package acsengine import ( "testing" - "github.com/Azure/acs-engine/pkg/api/common" + "github.com/Azure/acs-engine/pkg/helpers" ) func TestKubeletConfigUseCloudControllerManager(t *testing.T) { // Test UseCloudControllerManager = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = pointerToBool(true) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = helpers.PointerToBool(true) setKubeletConfig(cs) k := cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig if k["--cloud-provider"] != "external" { @@ -18,8 +18,8 @@ func TestKubeletConfigUseCloudControllerManager(t *testing.T) { } // Test UseCloudControllerManager = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = pointerToBool(false) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager = helpers.PointerToBool(false) setKubeletConfig(cs) k = cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig if k["--cloud-provider"] != "azure" { @@ -31,7 +31,7 @@ func TestKubeletConfigUseCloudControllerManager(t *testing.T) { func TestKubeletConfigNetworkPolicy(t *testing.T) { // Test NetworkPolicy = none - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) cs.Properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy = NetworkPolicyNone setKubeletConfig(cs) k := cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig @@ -41,7 +41,7 @@ func TestKubeletConfigNetworkPolicy(t *testing.T) { } // Test NetworkPolicy = azure - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) cs.Properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy = "azure" setKubeletConfig(cs) k = cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig @@ -54,8 +54,8 @@ func TestKubeletConfigNetworkPolicy(t *testing.T) { func TestKubeletConfigEnableSecureKubelet(t *testing.T) { // Test EnableSecureKubelet = true - cs := createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = pointerToBool(true) + cs := createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(true) setKubeletConfig(cs) k := cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig if k["--anonymous-auth"] != "false" { @@ -72,8 +72,8 @@ func TestKubeletConfigEnableSecureKubelet(t *testing.T) { } // Test EnableSecureKubelet = false - cs = createContainerService("testcluster", common.KubernetesVersion1Dot7Dot12, 3, 2) - cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = pointerToBool(false) + cs = createContainerService("testcluster", defaultTestClusterVer, 3, 2) + cs.Properties.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(false) setKubeletConfig(cs) k = cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig for _, key := range []string{"--anonymous-auth", "--client-ca-file"} { diff --git a/pkg/acsengine/defaults.go b/pkg/acsengine/defaults.go index 39078c3cee..3f5254da06 100644 --- a/pkg/acsengine/defaults.go +++ b/pkg/acsengine/defaults.go @@ -10,6 +10,7 @@ import ( "github.com/Azure/acs-engine/pkg/api" "github.com/Azure/acs-engine/pkg/api/common" + "github.com/Azure/acs-engine/pkg/helpers" "github.com/Masterminds/semver" ) @@ -179,7 +180,7 @@ var ( // DefaultTillerAddonsConfig is the default tiller Kubernetes addon Config DefaultTillerAddonsConfig = api.KubernetesAddon{ Name: DefaultTillerAddonName, - Enabled: pointerToBool(api.DefaultTillerAddonEnabled), + Enabled: helpers.PointerToBool(api.DefaultTillerAddonEnabled), Containers: []api.KubernetesContainerSpec{ { Name: DefaultTillerAddonName, @@ -197,7 +198,7 @@ var ( // DefaultACIConnectorAddonsConfig is the default ACI Connector Kubernetes addon Config DefaultACIConnectorAddonsConfig = api.KubernetesAddon{ Name: DefaultACIConnectorAddonName, - Enabled: pointerToBool(api.DefaultACIConnectorAddonEnabled), + Enabled: helpers.PointerToBool(api.DefaultACIConnectorAddonEnabled), Config: map[string]string{ "region": "westus", "nodeName": "aci-connector", @@ -218,7 +219,7 @@ var ( // DefaultDashboardAddonsConfig is the default kubernetes-dashboard addon Config DefaultDashboardAddonsConfig = api.KubernetesAddon{ Name: DefaultDashboardAddonName, - Enabled: pointerToBool(api.DefaultDashboardAddonEnabled), + Enabled: helpers.PointerToBool(api.DefaultDashboardAddonEnabled), Containers: []api.KubernetesContainerSpec{ { Name: DefaultDashboardAddonName, @@ -233,7 +234,7 @@ var ( // DefaultReschedulerAddonsConfig is the default rescheduler Kubernetes addon Config DefaultReschedulerAddonsConfig = api.KubernetesAddon{ Name: DefaultReschedulerAddonName, - Enabled: pointerToBool(api.DefaultReschedulerAddonEnabled), + Enabled: helpers.PointerToBool(api.DefaultReschedulerAddonEnabled), Containers: []api.KubernetesContainerSpec{ { Name: DefaultReschedulerAddonName, @@ -248,7 +249,7 @@ var ( // DefaultMetricsServerAddonsConfig is the default metrics-server Kubernetes addon Config DefaultMetricsServerAddonsConfig = api.KubernetesAddon{ Name: DefaultMetricsServerAddonName, - Enabled: pointerToBool(api.DefaultMetricsServerAddonEnabled), + Enabled: helpers.PointerToBool(api.DefaultMetricsServerAddonEnabled), Containers: []api.KubernetesContainerSpec{ { Name: DefaultMetricsServerAddonName, @@ -441,7 +442,7 @@ func setOrchestratorDefaults(cs *api.ContainerService) { } if o.KubernetesConfig.PrivateCluster.Enabled == nil { - o.KubernetesConfig.PrivateCluster.Enabled = pointerToBool(api.DefaultPrivateClusterEnabled) + o.KubernetesConfig.PrivateCluster.Enabled = helpers.PointerToBool(api.DefaultPrivateClusterEnabled) } if "" == a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB { @@ -461,15 +462,15 @@ func setOrchestratorDefaults(cs *api.ContainerService) { } if a.OrchestratorProfile.KubernetesConfig.EnableRbac == nil { - a.OrchestratorProfile.KubernetesConfig.EnableRbac = pointerToBool(api.DefaultRBACEnabled) + a.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(api.DefaultRBACEnabled) } if a.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet == nil { - a.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = pointerToBool(api.DefaultSecureKubeletEnabled) + a.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(api.DefaultSecureKubeletEnabled) } if a.OrchestratorProfile.KubernetesConfig.UseInstanceMetadata == nil { - a.OrchestratorProfile.KubernetesConfig.UseInstanceMetadata = pointerToBool(api.DefaultUseInstanceMetadata) + a.OrchestratorProfile.KubernetesConfig.UseInstanceMetadata = helpers.PointerToBool(api.DefaultUseInstanceMetadata) } // Configure kubelet @@ -833,12 +834,6 @@ func assignDefaultAddonVals(addon, defaults api.KubernetesAddon) api.KubernetesA return addon } -// pointerToBool returns a pointer to a bool -func pointerToBool(b bool) *bool { - p := b - return &p -} - // combine user-provided --feature-gates vals with defaults // a minimum k8s version may be declared as required for defaults assignment func addDefaultFeatureGates(m map[string]string, version string, minVersion string, defaults string) { @@ -893,5 +888,5 @@ func enforceK8sVersionAddonOverrides(addons []api.KubernetesAddon, o *api.Orches } func k8sVersionMetricsServerAddonEnabled(o *api.OrchestratorProfile) *bool { - return pointerToBool(common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.9.0")) + return helpers.PointerToBool(common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.9.0")) } diff --git a/pkg/acsengine/defaults_test.go b/pkg/acsengine/defaults_test.go index b0b58f192e..951f1e5d73 100644 --- a/pkg/acsengine/defaults_test.go +++ b/pkg/acsengine/defaults_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/Azure/acs-engine/pkg/api" + "github.com/Azure/acs-engine/pkg/helpers" ) func TestCertsAlreadyPresent(t *testing.T) { @@ -198,7 +199,7 @@ func TestAssignDefaultAddonVals(t *testing.T) { // Verify that an addon with all custom values provided remains unmodified during default value assignment customAddon := api.KubernetesAddon{ Name: addonName, - Enabled: pointerToBool(true), + Enabled: helpers.PointerToBool(true), Containers: []api.KubernetesContainerSpec{ { Name: addonName, @@ -230,7 +231,7 @@ func TestAssignDefaultAddonVals(t *testing.T) { // Verify that an addon with no custom values provided gets all the appropriate defaults customAddon = api.KubernetesAddon{ Name: addonName, - Enabled: pointerToBool(true), + Enabled: helpers.PointerToBool(true), Containers: []api.KubernetesContainerSpec{ { Name: addonName, @@ -254,7 +255,7 @@ func TestAssignDefaultAddonVals(t *testing.T) { // More checking to verify default interpolation customAddon = api.KubernetesAddon{ Name: addonName, - Enabled: pointerToBool(true), + Enabled: helpers.PointerToBool(true), Containers: []api.KubernetesContainerSpec{ { Name: addonName, @@ -279,14 +280,6 @@ func TestAssignDefaultAddonVals(t *testing.T) { } -func TestPointerToBool(t *testing.T) { - boolVar := true - ret := pointerToBool(boolVar) - if *ret != boolVar { - t.Fatalf("expected pointerToBool(true) to return *true, instead returned %#v", ret) - } -} - func TestKubeletFeatureGatesEnsureAcceleratorsOnAgentsFor1_6_0(t *testing.T) { mockCS := getMockBaseContainerService("1.6.0") properties := mockCS.Properties @@ -336,7 +329,7 @@ func TestKubeletFeatureGatesEnsureMasterAndAgentConfigUsedFor1_6_0(t *testing.T) func getMockAddon(name string) api.KubernetesAddon { return api.KubernetesAddon{ Name: name, - Enabled: pointerToBool(true), + Enabled: helpers.PointerToBool(true), Containers: []api.KubernetesContainerSpec{ { Name: name, diff --git a/pkg/acsengine/k8s_versions.go b/pkg/acsengine/k8s_versions.go index 3cb9bf5bd6..e0ec9af930 100644 --- a/pkg/acsengine/k8s_versions.go +++ b/pkg/acsengine/k8s_versions.go @@ -141,43 +141,51 @@ var k8sComponentVersions = map[string]map[string]string{ } // KubeConfigs represents Docker images used for Kubernetes components based on Kubernetes versions (major.minor.patch) -var KubeConfigs = map[string]map[string]string{ - common.KubernetesVersion1Dot10Dot0RC1: getK8sVersionComponents("1.10.0-rc.1", nil), - common.KubernetesVersion1Dot10Dot0Beta4: getK8sVersionComponents("1.10.0-beta.4", nil), - common.KubernetesVersion1Dot10Dot0Beta2: getK8sVersionComponents("1.10.0-beta.2", nil), - common.KubernetesVersion1Dot9Dot6: getK8sVersionComponents("1.9.6", nil), - common.KubernetesVersion1Dot9Dot5: getK8sVersionComponents("1.9.5", nil), - common.KubernetesVersion1Dot9Dot4: getK8sVersionComponents("1.9.4", nil), - common.KubernetesVersion1Dot9Dot3: getK8sVersionComponents("1.9.3", nil), - common.KubernetesVersion1Dot9Dot2: getK8sVersionComponents("1.9.2", nil), - common.KubernetesVersion1Dot9Dot1: getK8sVersionComponents("1.9.1", nil), - common.KubernetesVersion1Dot9Dot0: getK8sVersionComponents("1.9.0", nil), - common.KubernetesVersion1Dot8Dot10: getK8sVersionComponents("1.8.10", nil), - common.KubernetesVersion1Dot8Dot9: getK8sVersionComponents("1.8.9", map[string]string{"windowszip": "v1.8.9-2int.zip"}), - common.KubernetesVersion1Dot8Dot8: getK8sVersionComponents("1.8.8", nil), - common.KubernetesVersion1Dot8Dot7: getK8sVersionComponents("1.8.7", nil), - common.KubernetesVersion1Dot8Dot6: getK8sVersionComponents("1.8.6", map[string]string{"windowszip": "v1.8.6-2int.zip"}), - common.KubernetesVersion1Dot8Dot4: getK8sVersionComponents("1.8.4", nil), - common.KubernetesVersion1Dot8Dot2: getK8sVersionComponents("1.8.2", map[string]string{"windowszip": "v1.8.2-2int.zip"}), - common.KubernetesVersion1Dot8Dot1: getK8sVersionComponents("1.8.1", map[string]string{"windowszip": "v1.8.1-2int.zip"}), - common.KubernetesVersion1Dot8Dot0: getK8sVersionComponents("1.8.0", map[string]string{"windowszip": "v1.8.0-2int.zip"}), - common.KubernetesVersion1Dot7Dot15: getK8sVersionComponents("1.7.15", map[string]string{"windowszip": "v1.7.15-1int.zip"}), - common.KubernetesVersion1Dot7Dot14: getK8sVersionComponents("1.7.14", map[string]string{"windowszip": "v1.7.14-1int.zip"}), - common.KubernetesVersion1Dot7Dot13: getK8sVersionComponents("1.7.13", map[string]string{"windowszip": "v1.7.13-1int.zip"}), - common.KubernetesVersion1Dot7Dot12: getK8sVersionComponents("1.7.12", map[string]string{"windowszip": "v1.7.12-2int.zip"}), - common.KubernetesVersion1Dot7Dot10: getK8sVersionComponents("1.7.10", map[string]string{"windowszip": "v1.7.10-1int.zip"}), - common.KubernetesVersion1Dot7Dot9: getK8sVersionComponents("1.7.9", map[string]string{"windowszip": "v1.7.9-2int.zip"}), - common.KubernetesVersion1Dot7Dot7: getK8sVersionComponents("1.7.7", map[string]string{"windowszip": "v1.7.7-2int.zip"}), - common.KubernetesVersion1Dot7Dot5: getK8sVersionComponents("1.7.5", map[string]string{"windowszip": "v1.7.5-4int.zip"}), - common.KubernetesVersion1Dot7Dot4: getK8sVersionComponents("1.7.4", map[string]string{"windowszip": "v1.7.4-2int.zip"}), - common.KubernetesVersion1Dot7Dot2: getK8sVersionComponents("1.7.2", map[string]string{"windowszip": "v1.7.2-1int.zip"}), - common.KubernetesVersion1Dot7Dot1: getK8sVersionComponents("1.7.1", nil), - common.KubernetesVersion1Dot7Dot0: getK8sVersionComponents("1.7.0", nil), - common.KubernetesVersion1Dot6Dot13: getK8sVersionComponents("1.6.13", nil), - common.KubernetesVersion1Dot6Dot12: getK8sVersionComponents("1.6.12", nil), - common.KubernetesVersion1Dot6Dot11: getK8sVersionComponents("1.6.11", nil), - common.KubernetesVersion1Dot6Dot9: getK8sVersionComponents("1.6.9", nil), - common.KubernetesVersion1Dot6Dot6: getK8sVersionComponents("1.6.6", nil), +var KubeConfigs = getKubeConfigs() + +func getKubeConfigs() map[string]map[string]string { + ret := make(map[string]map[string]string) + for _, version := range common.GetAllSupportedKubernetesVersions() { + ret[version] = getK8sVersionComponents(version, getVersionOverrides(version)) + } + return ret +} + +func getVersionOverrides(v string) map[string]string { + switch v { + case "1.8.9": + return map[string]string{"windowszip": "v1.8.9-2int.zip"} + case "1.8.6": + return map[string]string{"windowszip": "v1.8.6-2int.zip"} + case "1.8.2": + return map[string]string{"windowszip": "v1.8.2-2int.zip"} + case "1.8.1": + return map[string]string{"windowszip": "v1.8.1-2int.zip"} + case "1.8.0": + return map[string]string{"windowszip": "v1.8.0-2int.zip"} + case "1.7.15": + return map[string]string{"windowszip": "v1.7.15-1int.zip"} + case "1.7.14": + return map[string]string{"windowszip": "v1.7.14-1int.zip"} + case "1.7.13": + return map[string]string{"windowszip": "v1.7.13-1int.zip"} + case "1.7.12": + return map[string]string{"windowszip": "v1.7.12-2int.zip"} + case "1.7.10": + return map[string]string{"windowszip": "v1.7.10-1int.zip"} + case "1.7.9": + return map[string]string{"windowszip": "v1.7.9-2int.zip"} + case "1.7.7": + return map[string]string{"windowszip": "v1.7.7-2int.zip"} + case "1.7.5": + return map[string]string{"windowszip": "v1.7.5-4int.zip"} + case "1.7.4": + return map[string]string{"windowszip": "v1.7.4-2int.zip"} + case "1.7.2": + return map[string]string{"windowszip": "v1.7.2-1int.zip"} + default: + return nil + } } func getK8sVersionComponents(version string, overrides map[string]string) map[string]string { diff --git a/pkg/api/apiloader_test.go b/pkg/api/apiloader_test.go index 62a64d70e4..dd245cad5c 100644 --- a/pkg/api/apiloader_test.go +++ b/pkg/api/apiloader_test.go @@ -11,7 +11,7 @@ import ( func TestLoadContainerServiceFromFile(t *testing.T) { existingContainerService := &ContainerService{Name: "test", - Properties: &Properties{OrchestratorProfile: &OrchestratorProfile{OrchestratorType: Kubernetes, OrchestratorVersion: common.KubernetesVersion1Dot6Dot9}}} + Properties: &Properties{OrchestratorProfile: &OrchestratorProfile{OrchestratorType: Kubernetes, OrchestratorVersion: "1.6.9"}}} locale := gotext.NewLocale(path.Join("..", "..", "translations"), "en_US") i18n.Initialize(locale) @@ -25,7 +25,7 @@ func TestLoadContainerServiceFromFile(t *testing.T) { if err != nil { t.Error(err.Error()) } - if containerService.Properties.OrchestratorProfile.OrchestratorVersion != common.KubernetesVersion1Dot6Dot11 { + if containerService.Properties.OrchestratorProfile.OrchestratorVersion != "1.6.11" { t.Error("Failed to set orcherstator version when it is set in the json") } @@ -33,7 +33,7 @@ func TestLoadContainerServiceFromFile(t *testing.T) { if err != nil { t.Error(err.Error()) } - if containerService.Properties.OrchestratorProfile.OrchestratorVersion != common.KubernetesVersion1Dot6Dot9 { + if containerService.Properties.OrchestratorProfile.OrchestratorVersion != "1.6.9" { t.Errorf("Failed set orcherstator version when it is not set in the json, got %s", containerService.Properties.OrchestratorProfile.OrchestratorVersion) } @@ -41,7 +41,7 @@ func TestLoadContainerServiceFromFile(t *testing.T) { if err != nil { t.Error(err.Error()) } - if containerService.Properties.OrchestratorProfile.OrchestratorVersion != common.KubernetesVersion1Dot6Dot9 { + if containerService.Properties.OrchestratorProfile.OrchestratorVersion != "1.6.9" { t.Errorf("Failed set orcherstator version when it is not set in the json, got %s", containerService.Properties.OrchestratorProfile.OrchestratorVersion) } @@ -49,7 +49,7 @@ func TestLoadContainerServiceFromFile(t *testing.T) { if err != nil { t.Error(err.Error()) } - if containerService.Properties.OrchestratorProfile.OrchestratorVersion != common.KubernetesVersion1Dot6Dot9 { + if containerService.Properties.OrchestratorProfile.OrchestratorVersion != "1.6.9" { t.Errorf("Failed set orcherstator version when it is not set in the json, got %s", containerService.Properties.OrchestratorProfile.OrchestratorVersion) } diff --git a/pkg/api/common/const.go b/pkg/api/common/const.go index 530b167072..23bb4812de 100644 --- a/pkg/api/common/const.go +++ b/pkg/api/common/const.go @@ -53,181 +53,10 @@ const ( ) const ( - // KubernetesVersion1Dot10Dot0RC1 is the string for kubernetes 1.10.0-rc.1 - KubernetesVersion1Dot10Dot0RC1 string = "1.10.0-rc.1" - // KubernetesVersion1Dot10Dot0Beta2 is the string for kubernetes 1.10.0-beta.2 - KubernetesVersion1Dot10Dot0Beta2 string = "1.10.0-beta.2" - // KubernetesVersion1Dot10Dot0Beta4 is the string for kubernetes 1.10.0-beta.4 - KubernetesVersion1Dot10Dot0Beta4 string = "1.10.0-beta.4" - // KubernetesVersion1Dot9Dot0 is the major.minor.patch string for the 1.9.0 version of kubernetes - KubernetesVersion1Dot9Dot0 string = "1.9.0" - // KubernetesVersion1Dot9Dot1 is the major.minor.patch string for the 1.9.1 version of kubernetes - KubernetesVersion1Dot9Dot1 string = "1.9.1" - // KubernetesVersion1Dot9Dot2 is the major.minor.patch string for the 1.9.2 version of kubernetes - KubernetesVersion1Dot9Dot2 string = "1.9.2" - // KubernetesVersion1Dot9Dot3 is the major.minor.patch string for the 1.9.3 version of kubernetes - KubernetesVersion1Dot9Dot3 string = "1.9.3" - // KubernetesVersion1Dot9Dot4 is the major.minor.patch string for the 1.9.4 version of kubernetes - KubernetesVersion1Dot9Dot4 string = "1.9.4" - // KubernetesVersion1Dot9Dot5 is the major.minor.patch string for the 1.9.5 version of kubernetes - KubernetesVersion1Dot9Dot5 string = "1.9.5" - // KubernetesVersion1Dot9Dot6 is the major.minor.patch string for the 1.9.6 version of kubernetes - KubernetesVersion1Dot9Dot6 string = "1.9.6" - // KubernetesVersion1Dot8Dot0 is the major.minor.patch string for the 1.8.0 version of kubernetes - KubernetesVersion1Dot8Dot0 string = "1.8.0" - // KubernetesVersion1Dot8Dot1 is the major.minor.patch string for the 1.8.1 version of kubernetes - KubernetesVersion1Dot8Dot1 string = "1.8.1" - // KubernetesVersion1Dot8Dot2 is the major.minor.patch string for the 1.8.2 version of kubernetes - KubernetesVersion1Dot8Dot2 string = "1.8.2" - // KubernetesVersion1Dot8Dot4 is the major.minor.patch string for the 1.8.4 version of kubernetes - KubernetesVersion1Dot8Dot4 string = "1.8.4" - // KubernetesVersion1Dot8Dot6 is the major.minor.patch string for the 1.8.6 version of kubernetes - KubernetesVersion1Dot8Dot6 string = "1.8.6" - // KubernetesVersion1Dot8Dot7 is the major.minor.patch string for the 1.8.7 version of kubernetes - KubernetesVersion1Dot8Dot7 string = "1.8.7" - // KubernetesVersion1Dot8Dot8 is the major.minor.patch string for the 1.8.8 version of kubernetes - KubernetesVersion1Dot8Dot8 string = "1.8.8" - // KubernetesVersion1Dot8Dot9 is the major.minor.patch string for the 1.8.9 version of kubernetes - KubernetesVersion1Dot8Dot9 string = "1.8.9" - // KubernetesVersion1Dot8Dot10 is the major.minor.patch string for the 1.8.10 version of kubernetes - KubernetesVersion1Dot8Dot10 string = "1.8.10" - // KubernetesVersion1Dot7Dot0 is the major.minor.patch string for the 1.7.0 version of kubernetes - KubernetesVersion1Dot7Dot0 string = "1.7.0" - // KubernetesVersion1Dot7Dot1 is the major.minor.patch string for the 1.7.1 version of kubernetes - KubernetesVersion1Dot7Dot1 string = "1.7.1" - // KubernetesVersion1Dot7Dot2 is the major.minor.patch string for the 1.7.2 version of kubernetes - KubernetesVersion1Dot7Dot2 string = "1.7.2" - // KubernetesVersion1Dot7Dot4 is the major.minor.patch string for the 1.7.4 version of kubernetes - KubernetesVersion1Dot7Dot4 string = "1.7.4" - // KubernetesVersion1Dot7Dot5 is the major.minor.patch string for the 1.7.5 version of kubernetes - KubernetesVersion1Dot7Dot5 string = "1.7.5" - // KubernetesVersion1Dot7Dot7 is the major.minor.patch string for the 1.7.7 version of kubernetes - KubernetesVersion1Dot7Dot7 string = "1.7.7" - // KubernetesVersion1Dot7Dot9 is the major.minor.patch string for the 1.7.9 version of kubernetes - KubernetesVersion1Dot7Dot9 string = "1.7.9" - // KubernetesVersion1Dot7Dot10 is the major.minor.patch string for the 1.7.10 version of kubernetes - KubernetesVersion1Dot7Dot10 string = "1.7.10" - // KubernetesVersion1Dot7Dot12 is the major.minor.patch string for the 1.7.12 version of kubernetes - KubernetesVersion1Dot7Dot12 string = "1.7.12" - // KubernetesVersion1Dot7Dot13 is the major.minor.patch string for the 1.7.13 version of kubernetes - KubernetesVersion1Dot7Dot13 string = "1.7.13" - // KubernetesVersion1Dot7Dot14 is the major.minor.patch string for the 1.7.14 version of kubernetes - KubernetesVersion1Dot7Dot14 string = "1.7.14" - // KubernetesVersion1Dot7Dot15 is the major.minor.patch string for the 1.7.15 version of kubernetes - KubernetesVersion1Dot7Dot15 string = "1.7.15" - // KubernetesVersion1Dot6Dot6 is the major.minor.patch string for the 1.6.6 version of kubernetes - KubernetesVersion1Dot6Dot6 string = "1.6.6" - // KubernetesVersion1Dot6Dot9 is the major.minor.patch string for the 1.6.9 version of kubernetes - KubernetesVersion1Dot6Dot9 string = "1.6.9" - // KubernetesVersion1Dot6Dot11 is the major.minor.patch string for the 1.6.11 version of kubernetes - KubernetesVersion1Dot6Dot11 string = "1.6.11" - // KubernetesVersion1Dot6Dot12 is the major.minor.patch string for the 1.6.12 version of kubernetes - KubernetesVersion1Dot6Dot12 string = "1.6.12" - // KubernetesVersion1Dot6Dot13 is the major.minor.patch string for the 1.6.13 version of kubernetes - KubernetesVersion1Dot6Dot13 string = "1.6.13" - // KubernetesDefaultVersion is the default major.minor.patch version for kubernetes - KubernetesDefaultVersion string = KubernetesVersion1Dot8Dot9 + // KubernetesDefaultVersion is the default Kubernetes version + KubernetesDefaultVersion string = "1.8.9" ) -// AllKubernetesSupportedVersions is a whitelist map of supported Kubernetes version strings -var AllKubernetesSupportedVersions = map[string]bool{ - KubernetesVersion1Dot6Dot6: true, - KubernetesVersion1Dot6Dot9: true, - KubernetesVersion1Dot6Dot11: true, - KubernetesVersion1Dot6Dot12: true, - KubernetesVersion1Dot6Dot13: true, - KubernetesVersion1Dot7Dot0: true, - KubernetesVersion1Dot7Dot1: true, - KubernetesVersion1Dot7Dot2: true, - KubernetesVersion1Dot7Dot4: true, - KubernetesVersion1Dot7Dot5: true, - KubernetesVersion1Dot7Dot7: true, - KubernetesVersion1Dot7Dot9: true, - KubernetesVersion1Dot7Dot10: true, - KubernetesVersion1Dot7Dot12: true, - KubernetesVersion1Dot7Dot13: true, - KubernetesVersion1Dot7Dot14: true, - KubernetesVersion1Dot7Dot15: true, - KubernetesVersion1Dot8Dot0: true, - KubernetesVersion1Dot8Dot1: true, - KubernetesVersion1Dot8Dot2: true, - KubernetesVersion1Dot8Dot4: true, - KubernetesVersion1Dot8Dot6: true, - KubernetesVersion1Dot8Dot7: true, - KubernetesVersion1Dot8Dot8: true, - KubernetesVersion1Dot8Dot9: true, - KubernetesVersion1Dot8Dot10: true, - KubernetesVersion1Dot9Dot0: true, - KubernetesVersion1Dot9Dot1: true, - KubernetesVersion1Dot9Dot2: true, - KubernetesVersion1Dot9Dot3: true, - KubernetesVersion1Dot9Dot4: true, - KubernetesVersion1Dot9Dot5: true, - KubernetesVersion1Dot9Dot6: true, - KubernetesVersion1Dot10Dot0Beta2: true, - KubernetesVersion1Dot10Dot0Beta4: true, - KubernetesVersion1Dot10Dot0RC1: true, -} - -// GetSupportedKubernetesVersion verifies that a passed-in version string is supported, or returns a default version string if not -func GetSupportedKubernetesVersion(version string) string { - if k8sVersion := version; AllKubernetesSupportedVersions[k8sVersion] { - return k8sVersion - } - return KubernetesDefaultVersion -} - -// GetAllSupportedKubernetesVersions returns a slice of all supported Kubernetes versions -func GetAllSupportedKubernetesVersions() []string { - versions := make([]string, 0, len(AllKubernetesSupportedVersions)) - for k := range AllKubernetesSupportedVersions { - versions = append(versions, k) - } - return versions -} - -// AllKubernetesWindowsSupportedVersions maintain a set of available k8s Windows versions in acs-engine -var AllKubernetesWindowsSupportedVersions = map[string]bool{ - KubernetesVersion1Dot7Dot2: true, - KubernetesVersion1Dot7Dot4: true, - KubernetesVersion1Dot7Dot5: true, - KubernetesVersion1Dot7Dot7: true, - KubernetesVersion1Dot7Dot9: true, - KubernetesVersion1Dot7Dot10: true, - KubernetesVersion1Dot7Dot12: true, - KubernetesVersion1Dot7Dot13: true, - KubernetesVersion1Dot7Dot14: true, - KubernetesVersion1Dot7Dot15: true, - KubernetesVersion1Dot8Dot0: true, - KubernetesVersion1Dot8Dot1: true, - KubernetesVersion1Dot8Dot2: true, - KubernetesVersion1Dot8Dot4: true, - KubernetesVersion1Dot8Dot6: true, - KubernetesVersion1Dot8Dot7: true, - KubernetesVersion1Dot8Dot8: true, - KubernetesVersion1Dot8Dot9: true, - KubernetesVersion1Dot8Dot10: true, - KubernetesVersion1Dot9Dot0: true, - KubernetesVersion1Dot9Dot1: true, - KubernetesVersion1Dot9Dot2: true, - KubernetesVersion1Dot9Dot3: true, - KubernetesVersion1Dot9Dot4: true, - KubernetesVersion1Dot9Dot5: true, - KubernetesVersion1Dot9Dot6: true, - KubernetesVersion1Dot10Dot0Beta2: false, - KubernetesVersion1Dot10Dot0Beta4: false, - KubernetesVersion1Dot10Dot0RC1: false, -} - -// GetAllSupportedKubernetesVersionsWindows returns a slice of all supported Kubernetes versions on Windows -func GetAllSupportedKubernetesVersionsWindows() []string { - versions := make([]string, 0, len(AllKubernetesWindowsSupportedVersions)) - for k := range AllKubernetesWindowsSupportedVersions { - versions = append(versions, k) - } - return versions -} - const ( // DCOSVersion1Dot10Dot0 is the major.minor.patch string for 1.10.0 versions of DCOS DCOSVersion1Dot10Dot0 string = "1.10.0" diff --git a/pkg/api/common/const_test.go b/pkg/api/common/const_test.go deleted file mode 100644 index 0768090371..0000000000 --- a/pkg/api/common/const_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package common - -import ( - "testing" -) - -func Test_GetAllSupportedKubernetesVersions(t *testing.T) { - responseFromGetter := GetAllSupportedKubernetesVersions() - - if len(AllKubernetesSupportedVersions) != len(responseFromGetter) { - t.Errorf("GetAllSupportedKubernetesVersions() returned %d items, expected %d", len(responseFromGetter), len(AllKubernetesSupportedVersions)) - } - - for _, version := range responseFromGetter { - if !AllKubernetesSupportedVersions[version] { - t.Errorf("GetAllSupportedKubernetesVersions() returned a version %s that was not in the definitive AllKubernetesSupportedVersions map", version) - } - } -} - -func Test_GetSupportedKubernetesVersion(t *testing.T) { - versions := GetAllSupportedKubernetesVersions() - for _, version := range versions { - supportedVersion := GetSupportedKubernetesVersion(version) - if supportedVersion != version { - t.Errorf("GetSupportedKubernetesVersion(%s) should return the same passed-in string, instead returned %s", version, supportedVersion) - } - } - - defaultVersion := GetSupportedKubernetesVersion("") - if defaultVersion != KubernetesDefaultVersion { - t.Errorf("GetSupportedKubernetesVersion(\"\") should return the default version %s, instead returned %s", KubernetesDefaultVersion, defaultVersion) - } -} diff --git a/pkg/api/common/helper.go b/pkg/api/common/helper.go index 379f43cf4d..1c1ede318a 100644 --- a/pkg/api/common/helper.go +++ b/pkg/api/common/helper.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/Masterminds/semver" - validator "gopkg.in/go-playground/validator.v9" ) @@ -53,122 +51,3 @@ func HandleValidationErrors(e validator.ValidationErrors) error { } return fmt.Errorf("Namespace %s is not caught, %+v", ns, e) } - -// GetSupportedVersions get supported version list for a certain orchestrator -func GetSupportedVersions(orchType string, hasWindows bool) (versions []string, defaultVersion string) { - switch orchType { - case Kubernetes: - if hasWindows { - return GetAllSupportedKubernetesVersionsWindows(), string(KubernetesDefaultVersion) - } - return GetAllSupportedKubernetesVersions(), string(KubernetesDefaultVersion) - - case DCOS: - return AllDCOSSupportedVersions, DCOSDefaultVersion - default: - return nil, "" - } -} - -//GetValidPatchVersion gets the current valid patch version for the minor version of the passed in version -func GetValidPatchVersion(orchType, orchVer string) string { - if orchVer == "" { - return RationalizeReleaseAndVersion( - orchType, - "", - "", - false) - } - - // check if the current version is valid, this allows us to have multiple supported patch versions in the future if we need it - version := RationalizeReleaseAndVersion( - orchType, - "", - orchVer, - false) - - if version == "" { - sv, err := semver.NewVersion(orchVer) - if err != nil { - return "" - } - sr := fmt.Sprintf("%d.%d", sv.Major(), sv.Minor()) - - version = RationalizeReleaseAndVersion( - orchType, - sr, - "", - false) - } - return version -} - -// RationalizeReleaseAndVersion return a version when it can be rationalized from the input, otherwise "" -func RationalizeReleaseAndVersion(orchType, orchRel, orchVer string, hasWindows bool) (version string) { - // ignore "v" prefix in orchestrator version and release: "v1.8.0" is equivalent to "1.8.0", "v1.9" is equivalent to "1.9" - orchVer = strings.TrimPrefix(orchVer, "v") - orchRel = strings.TrimPrefix(orchRel, "v") - supportedVersions, defaultVersion := GetSupportedVersions(orchType, hasWindows) - if supportedVersions == nil { - return "" - } - - if orchRel == "" && orchVer == "" { - return defaultVersion - } - - if orchVer == "" { - // Try to get latest version matching the release - version = GetLatestPatchVersion(orchRel, supportedVersions) - return version - } else if orchRel == "" { - // Try to get version the same with orchVer - version = "" - for _, ver := range supportedVersions { - if ver == orchVer { - version = ver - break - } - } - return version - } - // Try to get latest version matching the release - version = "" - for _, ver := range supportedVersions { - sv, _ := semver.NewVersion(ver) - sr := fmt.Sprintf("%d.%d", sv.Major(), sv.Minor()) - if sr == orchRel && ver == orchVer { - version = ver - break - } - } - return version -} - -// IsKubernetesVersionGe returns if a semver string is >= to a compare-against semver string (suppport "-" suffixes) -func IsKubernetesVersionGe(actualVersion, version string) bool { - orchestratorVersion, _ := semver.NewVersion(strings.Split(actualVersion, "-")[0]) // to account for -alpha and -beta suffixes - constraint, _ := semver.NewConstraint(">=" + version) - return constraint.Check(orchestratorVersion) -} - -// GetLatestPatchVersion gets the most recent patch version from a list of semver versions given a major.minor string -func GetLatestPatchVersion(majorMinor string, versionsList []string) (version string) { - // Try to get latest version matching the release - version = "" - for _, ver := range versionsList { - sv, _ := semver.NewVersion(ver) - sr := fmt.Sprintf("%d.%d", sv.Major(), sv.Minor()) - if sr == majorMinor { - if version == "" { - version = ver - } else { - cons, _ := semver.NewConstraint(">" + version) - if cons.Check(sv) { - version = ver - } - } - } - } - return version -} diff --git a/pkg/api/common/helper_test.go b/pkg/api/common/helper_test.go deleted file mode 100644 index 6e2fbf493b..0000000000 --- a/pkg/api/common/helper_test.go +++ /dev/null @@ -1,145 +0,0 @@ -package common - -import "testing" - -func Test_GetValidPatchVersion(t *testing.T) { - version := GetValidPatchVersion(Kubernetes, "") - if version != KubernetesDefaultVersion { - t.Errorf("It is not the default Kubernetes version") - } - - version = GetValidPatchVersion(Kubernetes, "1.6.3") - if version != KubernetesVersion1Dot6Dot13 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot6Dot13) - } - - version = GetValidPatchVersion(Kubernetes, "1.7.3") - if version != KubernetesVersion1Dot7Dot15 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot7Dot15) - } - - version = GetValidPatchVersion(Kubernetes, "1.8.7") - if version != KubernetesVersion1Dot8Dot7 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot8Dot7) - } - - version = GetValidPatchVersion(Kubernetes, "1.9.1") - if version != KubernetesVersion1Dot9Dot1 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot9Dot1) - } - - version = GetValidPatchVersion(Kubernetes, "1.9.6") - if version != KubernetesVersion1Dot9Dot6 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot9Dot6) - } - - version = GetValidPatchVersion(Kubernetes, "1.10.0-rc.1") - if version != KubernetesVersion1Dot10Dot0RC1 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot10Dot0RC1) - } -} - -func TestGetLatestPatchVersion(t *testing.T) { - version := GetLatestPatchVersion("1.6", GetAllSupportedKubernetesVersions()) - if version != KubernetesVersion1Dot6Dot13 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot6Dot13) - } - - version = GetLatestPatchVersion("1.7", GetAllSupportedKubernetesVersions()) - if version != KubernetesVersion1Dot7Dot15 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot7Dot15) - } - - version = GetLatestPatchVersion("1.8", GetAllSupportedKubernetesVersions()) - if version != KubernetesVersion1Dot8Dot10 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot8Dot10) - } - - version = GetLatestPatchVersion("1.9", GetAllSupportedKubernetesVersions()) - if version != KubernetesVersion1Dot9Dot6 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot9Dot6) - } - - version = GetLatestPatchVersion("1.10", GetAllSupportedKubernetesVersions()) - if version != KubernetesVersion1Dot10Dot0RC1 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot10Dot0RC1) - } - - expected := "99.1.2" - version = GetLatestPatchVersion("99.1", []string{"99.1.1", "99.1.2-beta.5", expected}) - if version != expected { - t.Errorf("GetLatestPatchVersion returned the wrong latest version, expected %s", expected) - } -} - -func Test_RationalizeReleaseAndVersion(t *testing.T) { - version := RationalizeReleaseAndVersion(Kubernetes, "", "", false) - if version != KubernetesDefaultVersion { - t.Errorf("It is not the default Kubernetes version") - } - - version = RationalizeReleaseAndVersion(Kubernetes, "1.6", "", false) - if version != KubernetesVersion1Dot6Dot13 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot6Dot13) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "", "1.6.11", false) - if version != KubernetesVersion1Dot6Dot11 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot6Dot11) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "1.6", "1.6.11", false) - if version != KubernetesVersion1Dot6Dot11 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot6Dot11) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "1.7", "", false) - if version != KubernetesVersion1Dot7Dot15 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot7Dot15) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "", "1.7.14", false) - if version != KubernetesVersion1Dot7Dot14 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot7Dot14) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "1.7", "1.7.15", false) - if version != KubernetesVersion1Dot7Dot15 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot7Dot15) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "", "1.6.7", false) - if version != "" { - t.Errorf("It is not empty string") - } - - version = RationalizeReleaseAndVersion(Kubernetes, "1.1", "", false) - if version != "" { - t.Errorf("It is not empty string") - } - - version = RationalizeReleaseAndVersion(Kubernetes, "1.1", "1.6.6", false) - if version != "" { - t.Errorf("It is not empty string") - } - - version = RationalizeReleaseAndVersion(Kubernetes, "v1.8", "", false) - if version != KubernetesVersion1Dot8Dot10 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot8Dot10) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "", "v1.8.8", false) - if version != KubernetesVersion1Dot8Dot8 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot8Dot8) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "v1.9", "", false) - if version != KubernetesVersion1Dot9Dot6 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot9Dot6) - } - - version = RationalizeReleaseAndVersion(Kubernetes, "1.10", "", false) - if version != KubernetesVersion1Dot10Dot0RC1 { - t.Errorf("It is not Kubernetes version %s", KubernetesVersion1Dot10Dot0RC1) - } -} diff --git a/pkg/api/common/versions.go b/pkg/api/common/versions.go new file mode 100644 index 0000000000..e38d3004ba --- /dev/null +++ b/pkg/api/common/versions.go @@ -0,0 +1,325 @@ +package common + +import ( + "fmt" + "strings" + + "github.com/Masterminds/semver" +) + +// AllKubernetesSupportedVersions is a whitelist map of supported Kubernetes version strings +var AllKubernetesSupportedVersions = map[string]bool{ + "1.6.6": true, + "1.6.9": true, + "1.6.11": true, + "1.6.12": true, + "1.6.13": true, + "1.7.0": true, + "1.7.1": true, + "1.7.2": true, + "1.7.4": true, + "1.7.5": true, + "1.7.7": true, + "1.7.9": true, + "1.7.10": true, + "1.7.12": true, + "1.7.13": true, + "1.7.14": true, + "1.7.15": true, + "1.8.0": true, + "1.8.1": true, + "1.8.2": true, + "1.8.4": true, + "1.8.6": true, + "1.8.7": true, + "1.8.8": true, + "1.8.9": true, + "1.8.10": true, + "1.9.0": true, + "1.9.1": true, + "1.9.2": true, + "1.9.3": true, + "1.9.4": true, + "1.9.5": true, + "1.9.6": true, + "1.10.0-beta.2": true, + "1.10.0-beta.4": true, + "1.10.0-rc.1": true, +} + +// GetSupportedKubernetesVersion verifies that a passed-in version string is supported, or returns a default version string if not +func GetSupportedKubernetesVersion(version string) string { + if k8sVersion := version; AllKubernetesSupportedVersions[k8sVersion] { + return k8sVersion + } + return KubernetesDefaultVersion +} + +// GetAllSupportedKubernetesVersions returns a slice of all supported Kubernetes versions +func GetAllSupportedKubernetesVersions() []string { + versions := make([]string, 0, len(AllKubernetesSupportedVersions)) + for k := range AllKubernetesSupportedVersions { + versions = append(versions, k) + } + return versions +} + +// GetVersionsGt returns a list of versions greater than a semver string given a list of versions +// inclusive=true means that we test for equality as well +// preReleases=true means that we include pre-release versions in the list +func GetVersionsGt(versions []string, version string, inclusive, preReleases bool) []string { + // Try to get latest version matching the release + var ret []string + var cons *semver.Constraints + minVersion, _ := semver.NewVersion(version) + for _, v := range versions { + sv, _ := semver.NewVersion(v) + if preReleases && minVersion.Prerelease() == "" { + sv, _ = semver.NewVersion(fmt.Sprintf("%d.%d.%d", sv.Major(), sv.Minor(), sv.Patch())) + } + if inclusive { + cons, _ = semver.NewConstraint(">=" + version) + } else { + cons, _ = semver.NewConstraint(">" + version) + } + if cons.Check(sv) { + ret = append(ret, v) + } + } + return ret +} + +// GetVersionsLt returns a list of versions less than than a semver string given a list of versions +// inclusive=true means that we test for equality as well +// preReleases=true means that we include pre-release versions in the list +func GetVersionsLt(versions []string, version string, inclusive, preReleases bool) []string { + // Try to get latest version matching the release + var ret []string + var cons *semver.Constraints + for _, v := range versions { + sv, _ := semver.NewVersion(v) + if preReleases { + sv, _ = semver.NewVersion(fmt.Sprintf("%d.%d.%d", sv.Major(), sv.Minor(), sv.Patch())) + } + if inclusive { + cons, _ = semver.NewConstraint("<=" + version) + } else { + cons, _ = semver.NewConstraint("<" + version) + } + if cons.Check(sv) { + ret = append(ret, v) + } + } + return ret +} + +// GetVersionsBetween returns a list of versions between a min and max +// inclusive=true means that we test for equality on both bounds +// preReleases=true means that we include pre-release versions in the list +func GetVersionsBetween(versions []string, versionMin, versionMax string, inclusive, preReleases bool) []string { + var ret []string + if minV, _ := semver.NewVersion(versionMin); minV.Prerelease() != "" { + preReleases = true + } + greaterThan := GetVersionsGt(versions, versionMin, inclusive, preReleases) + lessThan := GetVersionsLt(versions, versionMax, inclusive, preReleases) + for _, lv := range lessThan { + for _, gv := range greaterThan { + if lv == gv { + ret = append(ret, lv) + } + } + } + return ret +} + +// GetMaxVersion gets the highest semver version +// preRelease=true means accept a pre-release version as a max value +func GetMaxVersion(versions []string, preRelease bool) string { + if len(versions) < 1 { + return "" + } + highest, _ := semver.NewVersion("0.0.0") + highestPreRelease, _ := semver.NewVersion("0.0.0-alpha.0") + var preReleaseVersions []*semver.Version + for _, v := range versions { + sv, _ := semver.NewVersion(v) + if sv.Prerelease() != "" { + preReleaseVersions = append(preReleaseVersions, sv) + } else { + if sv.Compare(highest) == 1 { + highest = sv + } + } + } + if preRelease { + for _, sv := range preReleaseVersions { + if sv.Compare(highestPreRelease) == 1 { + highestPreRelease = sv + } + } + switch highestPreRelease.Compare(highest) { + case 1: + return highestPreRelease.String() + default: + return highest.String() + } + + } + return highest.String() +} + +// AllKubernetesWindowsSupportedVersions maintain a set of available k8s Windows versions in acs-engine +var AllKubernetesWindowsSupportedVersions = getAllKubernetesWindowsSupportedVersionsMap() + +func getAllKubernetesWindowsSupportedVersionsMap() map[string]bool { + ret := make(map[string]bool) + for k, v := range AllKubernetesSupportedVersions { + ret[k] = v + } + for _, version := range []string{ + "1.6.6", + "1.6.9", + "1.6.11", + "1.6.12", + "1.6.13", + "1.7.0", + "1.7.1", + "1.10.0-beta.2", + "1.10.0-beta.4", + "1.10.0-rc.1"} { + ret[version] = false + } + return ret +} + +// GetAllSupportedKubernetesVersionsWindows returns a slice of all supported Kubernetes versions on Windows +func GetAllSupportedKubernetesVersionsWindows() []string { + versions := make([]string, 0, len(AllKubernetesWindowsSupportedVersions)) + for k := range AllKubernetesWindowsSupportedVersions { + versions = append(versions, k) + } + return versions +} + +// GetSupportedVersions get supported version list for a certain orchestrator +func GetSupportedVersions(orchType string, hasWindows bool) (versions []string, defaultVersion string) { + switch orchType { + case Kubernetes: + if hasWindows { + return GetAllSupportedKubernetesVersionsWindows(), string(KubernetesDefaultVersion) + } + return GetAllSupportedKubernetesVersions(), string(KubernetesDefaultVersion) + + case DCOS: + return AllDCOSSupportedVersions, DCOSDefaultVersion + default: + return nil, "" + } +} + +//GetValidPatchVersion gets the current valid patch version for the minor version of the passed in version +func GetValidPatchVersion(orchType, orchVer string) string { + if orchVer == "" { + return RationalizeReleaseAndVersion( + orchType, + "", + "", + false) + } + + // check if the current version is valid, this allows us to have multiple supported patch versions in the future if we need it + version := RationalizeReleaseAndVersion( + orchType, + "", + orchVer, + false) + + if version == "" { + sv, err := semver.NewVersion(orchVer) + if err != nil { + return "" + } + sr := fmt.Sprintf("%d.%d", sv.Major(), sv.Minor()) + + version = RationalizeReleaseAndVersion( + orchType, + sr, + "", + false) + } + return version +} + +// RationalizeReleaseAndVersion return a version when it can be rationalized from the input, otherwise "" +func RationalizeReleaseAndVersion(orchType, orchRel, orchVer string, hasWindows bool) (version string) { + // ignore "v" prefix in orchestrator version and release: "v1.8.0" is equivalent to "1.8.0", "v1.9" is equivalent to "1.9" + orchVer = strings.TrimPrefix(orchVer, "v") + orchRel = strings.TrimPrefix(orchRel, "v") + supportedVersions, defaultVersion := GetSupportedVersions(orchType, hasWindows) + if supportedVersions == nil { + return "" + } + + if orchRel == "" && orchVer == "" { + return defaultVersion + } + + if orchVer == "" { + // Try to get latest version matching the release + version = GetLatestPatchVersion(orchRel, supportedVersions) + return version + } else if orchRel == "" { + // Try to get version the same with orchVer + version = "" + for _, ver := range supportedVersions { + if ver == orchVer { + version = ver + break + } + } + return version + } + // Try to get latest version matching the release + version = "" + for _, ver := range supportedVersions { + sv, _ := semver.NewVersion(ver) + sr := fmt.Sprintf("%d.%d", sv.Major(), sv.Minor()) + if sr == orchRel && ver == orchVer { + version = ver + break + } + } + return version +} + +// IsKubernetesVersionGe returns if a semver string is >= to a compare-against semver string (suppport "-" suffixes) +func IsKubernetesVersionGe(actualVersion, version string) bool { + orchestratorVersion, _ := semver.NewVersion(strings.Split(actualVersion, "-")[0]) // to account for -alpha and -beta suffixes + constraint, _ := semver.NewConstraint(">=" + version) + return constraint.Check(orchestratorVersion) +} + +// GetLatestPatchVersion gets the most recent patch version from a list of semver versions given a major.minor string +func GetLatestPatchVersion(majorMinor string, versionsList []string) (version string) { + // Try to get latest version matching the release + version = "" + for _, ver := range versionsList { + sv, err := semver.NewVersion(ver) + if err != nil { + return + } + sr := fmt.Sprintf("%d.%d", sv.Major(), sv.Minor()) + if sr == majorMinor { + if version == "" { + version = ver + } else { + cons, _ := semver.NewConstraint(">" + version) + if cons.Check(sv) { + version = ver + } + } + } + } + return version +} diff --git a/pkg/api/common/versions_test.go b/pkg/api/common/versions_test.go new file mode 100644 index 0000000000..01f39c7da0 --- /dev/null +++ b/pkg/api/common/versions_test.go @@ -0,0 +1,357 @@ +package common + +import ( + "testing" +) + +func Test_GetAllSupportedKubernetesVersions(t *testing.T) { + responseFromGetter := GetAllSupportedKubernetesVersions() + + if len(AllKubernetesSupportedVersions) != len(responseFromGetter) { + t.Errorf("GetAllSupportedKubernetesVersions() returned %d items, expected %d", len(responseFromGetter), len(AllKubernetesSupportedVersions)) + } + + for _, version := range responseFromGetter { + if !AllKubernetesSupportedVersions[version] { + t.Errorf("GetAllSupportedKubernetesVersions() returned a version %s that was not in the definitive AllKubernetesSupportedVersions map", version) + } + } +} + +func Test_GetSupportedKubernetesVersion(t *testing.T) { + versions := GetAllSupportedKubernetesVersions() + for _, version := range versions { + supportedVersion := GetSupportedKubernetesVersion(version) + if supportedVersion != version { + t.Errorf("GetSupportedKubernetesVersion(%s) should return the same passed-in string, instead returned %s", version, supportedVersion) + } + } + + defaultVersion := GetSupportedKubernetesVersion("") + if defaultVersion != KubernetesDefaultVersion { + t.Errorf("GetSupportedKubernetesVersion(\"\") should return the default version %s, instead returned %s", KubernetesDefaultVersion, defaultVersion) + } +} + +func TestGetVersionsGt(t *testing.T) { + versions := []string{"1.1.0-rc.1", "1.2.0-rc.1", "1.2.0", "1.2.1"} + expected := []string{"1.1.0-rc.1", "1.2.0-rc.1", "1.2.0", "1.2.1"} + expectedMap := map[string]bool{ + "1.1.0-rc.1": true, + "1.2.0-rc.1": true, + "1.2.0": true, + "1.2.1": true, + } + v := GetVersionsGt(versions, "1.1.0-alpha.1", false, false) + errStr := "GetVersionsGt returned an unexpected list of strings" + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } + + versions = []string{"1.1.0", "1.2.0", "1.2.1"} + expected = []string{"1.1.0", "1.2.0", "1.2.1"} + expectedMap = map[string]bool{ + "1.1.0": true, + "1.2.0": true, + "1.2.1": true, + } + v = GetVersionsGt(versions, "1.1.0", true, false) + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } +} + +func TestGetVersionsLt(t *testing.T) { + versions := []string{"1.1.0", "1.2.0-rc.1", "1.2.0", "1.2.1"} + expected := []string{"1.2.0", "1.2.1"} + // less than comparisons exclude pre-release versions from the result + expectedMap := map[string]bool{ + "1.1.0": true, + "1.2.0": true, + } + v := GetVersionsLt(versions, "1.2.1", false, false) + errStr := "GetVersionsLt returned an unexpected list of strings" + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } + + versions = []string{"1.1.0", "1.2.0", "1.2.1"} + expected = []string{"1.1.0", "1.2.0", "1.2.1"} + expectedMap = map[string]bool{ + "1.1.0": true, + "1.2.0": true, + "1.2.1": true, + } + v = GetVersionsLt(versions, "1.2.1", true, false) + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } +} + +func TestGetVersionsBetween(t *testing.T) { + versions := []string{"1.1.0", "1.2.0", "1.2.1"} + expected := []string{"1.2.0"} + expectedMap := map[string]bool{ + "1.2.0": true, + } + v := GetVersionsBetween(versions, "1.1.0", "1.2.1", false, false) + errStr := "GetVersionsBetween returned an unexpected list of strings" + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } + + versions = []string{"1.1.0", "1.2.0", "1.2.1"} + expected = []string{"1.1.0", "1.2.0", "1.2.1"} + expectedMap = map[string]bool{ + "1.1.0": true, + "1.2.0": true, + "1.2.1": true, + } + v = GetVersionsBetween(versions, "1.1.0", "1.2.1", true, false) + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } + + versions = []string{"1.9.6", "1.10.0-beta.2", "1.10.0-beta.4", "1.10.0-rc.1"} + expected = []string{"1.10.0-beta.2", "1.10.0-beta.4", "1.10.0-rc.1"} + expectedMap = map[string]bool{ + "1.10.0-beta.2": true, + "1.10.0-beta.4": true, + "1.10.0-rc.1": true, + } + v = GetVersionsBetween(versions, "1.9.6", "1.11.0", false, true) + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } + v = GetVersionsBetween(versions, "1.9.6", "1.11.0", false, false) + if len(v) != 0 { + t.Errorf(errStr) + } + + versions = []string{"1.9.6", "1.10.0-beta.2", "1.10.0-beta.4", "1.10.0-rc.1"} + expected = []string{"1.10.0-beta.4", "1.10.0-rc.1"} + expectedMap = map[string]bool{ + "1.10.0-beta.4": true, + "1.10.0-rc.1": true, + } + v = GetVersionsBetween(versions, "1.10.0-beta.2", "1.12.0", false, false) + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } + + versions = []string{"1.10.0", "1.10.0-beta.2", "1.10.0-beta.4", "1.10.0-rc.1"} + v = GetVersionsBetween(versions, "1.10.0", "1.12.0", false, false) + if len(v) != 0 { + t.Errorf(errStr) + } + + versions = []string{"1.9.6", "1.10.0-beta.2", "1.10.0-beta.4", "1.10.0-rc.1"} + expectedMap = map[string]bool{ + "1.9.6": true, + "1.10.0-beta.2": true, + "1.10.0-beta.4": true, + "1.10.0-rc.1": true, + } + v = GetVersionsBetween(versions, "1.9.5", "1.12.0", false, true) + if len(v) != len(versions) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } + + versions = []string{"1.9.6", "1.10.0", "1.10.1", "1.10.2"} + expected = []string{"1.10.0", "1.10.1", "1.10.2"} + expectedMap = map[string]bool{ + "1.10.0": true, + "1.10.1": true, + "1.10.2": true, + } + v = GetVersionsBetween(versions, "1.10.0-rc.1", "1.12.0", false, true) + if len(v) != len(expected) { + t.Errorf(errStr) + } + for _, ver := range v { + if !expectedMap[ver] { + t.Errorf(errStr) + } + } +} + +func Test_GetValidPatchVersion(t *testing.T) { + v := GetValidPatchVersion(Kubernetes, "") + if v != KubernetesDefaultVersion { + t.Errorf("It is not the default Kubernetes version") + } + + for version, enabled := range AllKubernetesSupportedVersions { + if enabled { + v = GetValidPatchVersion(Kubernetes, version) + if v != version { + t.Errorf("Expected version %s, instead got version %s", version, v) + } + } + } +} + +func TestGetLatestPatchVersion(t *testing.T) { + expected := "1.1.2" + version := GetLatestPatchVersion("1.1", []string{"1.1.1", expected}) + if version != expected { + t.Errorf("GetLatestPatchVersion returned the wrong latest version, expected %s, got %s", expected, version) + } + + expected = "1.1.2" + version = GetLatestPatchVersion("1.1", []string{"1.1.0", expected}) + if version != expected { + t.Errorf("GetLatestPatchVersion returned the wrong latest version, expected %s, got %s", expected, version) + } + + expected = "1.2.0" + version = GetLatestPatchVersion("1.2", []string{"1.1.0", "1.3.0", expected}) + if version != expected { + t.Errorf("GetLatestPatchVersion returned the wrong latest version, expected %s, got %s", expected, version) + } + + expected = "1.2.0-rc.3" + version = GetLatestPatchVersion("1.2", []string{"1.2.0-alpha.1", "1.2.0-beta.1", "1.2.0-rc.3", expected}) + if version != expected { + t.Errorf("GetLatestPatchVersion returned the wrong latest version, expected %s, got %s", expected, version) + } + + expected = "" + version = GetLatestPatchVersion("1.2", []string{"1.1.0", "1.1.1", "1.1.2", expected}) + if version != expected { + t.Errorf("GetLatestPatchVersion returned the wrong latest version, expected %s, got %s", expected, version) + } +} + +func TestGetMaxVersion(t *testing.T) { + expected := "1.0.3" + versions := []string{"1.0.1", "1.0.2", expected} + max := GetMaxVersion(versions, false) + if max != expected { + t.Errorf("GetMaxVersion returned the wrong max version, expected %s, got %s", expected, max) + } + + expected = "1.2.3" + versions = []string{"1.0.1", "1.1.2", expected} + max = GetMaxVersion(versions, false) + if max != expected { + t.Errorf("GetMaxVersion returned the wrong max version, expected %s, got %s", expected, max) + } + + expected = "1.1.2" + versions = []string{"1.0.1", expected, "1.2.3-alpha.1"} + max = GetMaxVersion(versions, false) + if max != expected { + t.Errorf("GetMaxVersion returned the wrong max version, expected %s, got %s", expected, max) + } + + expected = "1.2.3-alpha.1" + versions = []string{"1.0.1", "1.1.2", expected} + max = GetMaxVersion(versions, true) + if max != expected { + t.Errorf("GetMaxVersion returned the wrong max version, expected %s, got %s", expected, max) + } + + expected = "" + versions = []string{} + max = GetMaxVersion(versions, false) + if max != expected { + t.Errorf("GetMaxVersion returned the wrong max version, expected %s, got %s", expected, max) + } + + expected = "" + versions = []string{} + max = GetMaxVersion(versions, true) + if max != expected { + t.Errorf("GetMaxVersion returned the wrong max version, expected %s, got %s", expected, max) + } +} + +func Test_RationalizeReleaseAndVersion(t *testing.T) { + version := RationalizeReleaseAndVersion(Kubernetes, "", "", false) + if version != KubernetesDefaultVersion { + t.Errorf("It is not the default Kubernetes version") + } + + latest1Dot6Version := GetLatestPatchVersion("1.6", GetAllSupportedKubernetesVersions()) + version = RationalizeReleaseAndVersion(Kubernetes, "1.6", "", false) + if version != latest1Dot6Version { + t.Errorf("It is not Kubernetes version %s", latest1Dot6Version) + } + + expectedVersion := "1.6.11" + version = RationalizeReleaseAndVersion(Kubernetes, "", expectedVersion, false) + if version != expectedVersion { + t.Errorf("It is not Kubernetes version %s", expectedVersion) + } + + version = RationalizeReleaseAndVersion(Kubernetes, "1.6", expectedVersion, false) + if version != expectedVersion { + t.Errorf("It is not Kubernetes version %s", expectedVersion) + } + + version = RationalizeReleaseAndVersion(Kubernetes, "", "v"+expectedVersion, false) + if version != expectedVersion { + t.Errorf("It is not Kubernetes version %s", expectedVersion) + } + + version = RationalizeReleaseAndVersion(Kubernetes, "v1.6", "v"+expectedVersion, false) + if version != expectedVersion { + t.Errorf("It is not Kubernetes version %s", expectedVersion) + } + + version = RationalizeReleaseAndVersion(Kubernetes, "1.1", "", false) + if version != "" { + t.Errorf("It is not empty string") + } + + version = RationalizeReleaseAndVersion(Kubernetes, "1.1", "1.6.6", false) + if version != "" { + t.Errorf("It is not empty string") + } +} diff --git a/pkg/api/convertertoapi.go b/pkg/api/convertertoapi.go index 3e2c137c52..2f584dc09c 100644 --- a/pkg/api/convertertoapi.go +++ b/pkg/api/convertertoapi.go @@ -512,7 +512,7 @@ func convertVLabsWindowsProfile(vlabs *vlabs.WindowsProfile, api *WindowsProfile func convertV20160930OrchestratorProfile(v20160930 *v20160930.OrchestratorProfile, api *OrchestratorProfile) { api.OrchestratorType = v20160930.OrchestratorType if api.OrchestratorType == Kubernetes { - api.OrchestratorVersion = common.KubernetesVersion1Dot6Dot9 + api.OrchestratorVersion = "1.6.9" } else if api.OrchestratorType == DCOS { api.OrchestratorVersion = DCOSVersion1Dot9Dot0 } diff --git a/pkg/api/convertertoapi_test.go b/pkg/api/convertertoapi_test.go index d7a6019521..b2c9584ebe 100644 --- a/pkg/api/convertertoapi_test.go +++ b/pkg/api/convertertoapi_test.go @@ -94,12 +94,12 @@ func TestOrchestratorVersion(t *testing.T) { Properties: &v20170701.Properties{ OrchestratorProfile: &v20170701.OrchestratorProfile{ OrchestratorType: v20170701.Kubernetes, - OrchestratorVersion: common.KubernetesVersion1Dot6Dot11, + OrchestratorVersion: "1.6.11", }, }, } cs = ConvertV20170701ContainerService(v20170701cs) - if cs.Properties.OrchestratorProfile.OrchestratorVersion != common.KubernetesVersion1Dot6Dot11 { + if cs.Properties.OrchestratorProfile.OrchestratorVersion != "1.6.11" { t.Fatalf("incorrect OrchestratorVersion '%s'", cs.Properties.OrchestratorProfile.OrchestratorVersion) } // test vlabs @@ -119,12 +119,12 @@ func TestOrchestratorVersion(t *testing.T) { Properties: &vlabs.Properties{ OrchestratorProfile: &vlabs.OrchestratorProfile{ OrchestratorType: vlabs.Kubernetes, - OrchestratorVersion: common.KubernetesVersion1Dot6Dot11, + OrchestratorVersion: "1.6.11", }, }, } cs = ConvertVLabsContainerService(vlabscs) - if cs.Properties.OrchestratorProfile.OrchestratorVersion != common.KubernetesVersion1Dot6Dot11 { + if cs.Properties.OrchestratorProfile.OrchestratorVersion != "1.6.11" { t.Fatalf("incorrect OrchestratorVersion '%s'", cs.Properties.OrchestratorProfile.OrchestratorVersion) } } diff --git a/pkg/api/orchestrators.go b/pkg/api/orchestrators.go index c1bfaaf8db..a80ca3f94e 100644 --- a/pkg/api/orchestrators.go +++ b/pkg/api/orchestrators.go @@ -168,48 +168,13 @@ func kubernetesUpgrades(csOrch *OrchestratorProfile) ([]*OrchestratorProfile, er if err != nil { return nil, err } - currentMajor, currentMinor := currentVer.Major(), currentVer.Minor() - var nextMajor, nextMinor int64 - - switch { - case currentMajor == 1 && currentMinor == 5: - nextMajor = 1 - nextMinor = 6 - case currentMajor == 1 && currentMinor == 6: - nextMajor = 1 - nextMinor = 7 - case currentMajor == 1 && currentMinor == 7: - nextMajor = 1 - nextMinor = 8 - case currentMajor == 1 && currentMinor == 8: - nextMajor = 1 - nextMinor = 9 - case currentMajor == 1 && currentMinor == 9: - nextMajor = 1 - nextMinor = 10 - } - for ver, supported := range common.AllKubernetesSupportedVersions { - if !supported { - continue - } - nextVersion, err := semver.NewVersion(ver) - if err != nil { - continue - } - // add patch upgrade - if nextVersion.Major() == currentMajor && nextVersion.Minor() == currentMinor && currentVer.LessThan(nextVersion) { - ret = append(ret, &OrchestratorProfile{ - OrchestratorType: Kubernetes, - OrchestratorVersion: ver, - }) - } - // add next version - if nextVersion.Major() == nextMajor && nextVersion.Minor() == nextMinor { - ret = append(ret, &OrchestratorProfile{ - OrchestratorType: Kubernetes, - OrchestratorVersion: ver, - }) - } + nextNextMinorVersion := currentVer.IncMinor().IncMinor() + upgradeableVersions := common.GetVersionsBetween(common.GetAllSupportedKubernetesVersions(), csOrch.OrchestratorVersion, nextNextMinorVersion.String(), false, true) + for _, ver := range upgradeableVersions { + ret = append(ret, &OrchestratorProfile{ + OrchestratorType: Kubernetes, + OrchestratorVersion: ver, + }) } return ret, nil } diff --git a/pkg/api/orchestrators_test.go b/pkg/api/orchestrators_test.go index fcc60eec07..8f1079d831 100644 --- a/pkg/api/orchestrators_test.go +++ b/pkg/api/orchestrators_test.go @@ -51,82 +51,101 @@ func TestVersionCompare(t *testing.T) { func TestOrchestratorUpgradeInfo(t *testing.T) { RegisterTestingT(t) // 1.6.8 is upgradable to 1.6.x and 1.7.x + deployedVersion := "1.6.8" + nextNextMinorVersion := "1.8.0" csOrch := &OrchestratorProfile{ OrchestratorType: Kubernetes, - OrchestratorVersion: "1.6.8", + OrchestratorVersion: deployedVersion, } + v := common.GetVersionsBetween(common.GetAllSupportedKubernetesVersions(), deployedVersion, nextNextMinorVersion, false, true) orch, e := GetOrchestratorVersionProfile(csOrch) Expect(e).To(BeNil()) - // 1.6.9, 1.6.11, 1.6.12, 1.6.13, 1.7.0, 1.7.1, 1.7.2, 1.7.4, 1.7.5, 1.7.7, 1.7.9, 1.7.10, 1.7.12, 1.7.13, 1.7.14, 1.7.15 - Expect(len(orch.Upgrades)).To(Equal(16)) + Expect(len(orch.Upgrades)).To(Equal(len(v))) // 1.7.0 is upgradable to 1.7.x and 1.8.x + deployedVersion = "1.7.0" + nextNextMinorVersion = "1.9.0" csOrch = &OrchestratorProfile{ OrchestratorType: Kubernetes, - OrchestratorVersion: "1.7.0", + OrchestratorVersion: deployedVersion, } + v = common.GetVersionsBetween(common.GetAllSupportedKubernetesVersions(), deployedVersion, nextNextMinorVersion, false, true) orch, e = GetOrchestratorVersionProfile(csOrch) Expect(e).To(BeNil()) - // 1.7.1, 1.7.2, 1.7.4, 1.7.5, 1.7.7, 1.7.9, 1.7.10, 1.7.12, 1.7.13, 1.7.14, 1.7.15, 1.8.0, 1.8.1, 1.8.2, 1.8.4, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10 - Expect(len(orch.Upgrades)).To(Equal(20)) + Expect(len(orch.Upgrades)).To(Equal(len(v))) // 1.7.15 is upgradable to 1.8.x + deployedVersion = "1.7.15" + nextNextMinorVersion = "1.9.0" csOrch = &OrchestratorProfile{ OrchestratorType: Kubernetes, - OrchestratorVersion: "1.7.15", + OrchestratorVersion: deployedVersion, } + v = common.GetVersionsBetween(common.GetAllSupportedKubernetesVersions(), deployedVersion, nextNextMinorVersion, false, true) orch, e = GetOrchestratorVersionProfile(csOrch) Expect(e).To(BeNil()) - // 1.8.0, 1.8.1, 1.8.2, 1.8.4, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10 - Expect(len(orch.Upgrades)).To(Equal(9)) + Expect(len(orch.Upgrades)).To(Equal(len(v))) // 1.8.4 is upgradable to 1.8.x and 1.9.x + deployedVersion = "1.8.4" + nextNextMinorVersion = "1.10.0" csOrch = &OrchestratorProfile{ OrchestratorType: Kubernetes, - OrchestratorVersion: "1.8.4", + OrchestratorVersion: deployedVersion, } + v = common.GetVersionsBetween(common.GetAllSupportedKubernetesVersions(), deployedVersion, nextNextMinorVersion, false, true) orch, e = GetOrchestratorVersionProfile(csOrch) Expect(e).To(BeNil()) - // 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.9.5, 1.9.6 - Expect(len(orch.Upgrades)).To(Equal(12)) + Expect(len(orch.Upgrades)).To(Equal(len(v))) // 1.9.6 is upgradable to 1.10.x + deployedVersion = "1.9.6" + nextNextMinorVersion = "1.11.0" csOrch = &OrchestratorProfile{ OrchestratorType: Kubernetes, - OrchestratorVersion: "1.9.6", + OrchestratorVersion: deployedVersion, } + v = common.GetVersionsBetween(common.GetAllSupportedKubernetesVersions(), deployedVersion, nextNextMinorVersion, false, true) orch, e = GetOrchestratorVersionProfile(csOrch) Expect(e).To(BeNil()) - // 1.10.0-beta.2, 1.10.0-beta.4, 1.10.0-rc.1 - Expect(len(orch.Upgrades)).To(Equal(3)) + Expect(len(orch.Upgrades)).To(Equal(len(v))) - // 1.10.0-beta.4 is upgradable to 1.10.x + // 1.10.0-beta.2 is upgradable to newer pre-release versions in 1.10.n release channel and official 1.10.n releases + deployedVersion = "1.10.0-beta.2" + nextNextMinorVersion = "1.12.0" csOrch = &OrchestratorProfile{ OrchestratorType: Kubernetes, - OrchestratorVersion: "1.10.0-beta.4", + OrchestratorVersion: deployedVersion, } + v = common.GetVersionsBetween(common.GetAllSupportedKubernetesVersions(), deployedVersion, nextNextMinorVersion, false, true) orch, e = GetOrchestratorVersionProfile(csOrch) Expect(e).To(BeNil()) - Expect(len(orch.Upgrades)).To(Equal(1)) + Expect(len(orch.Upgrades)).To(Equal(len(v))) - // 1.10.0-rc.1 is not upgradable + // The latest version is not upgradable csOrch = &OrchestratorProfile{ OrchestratorType: Kubernetes, - OrchestratorVersion: "1.10.0-rc.1", + OrchestratorVersion: common.GetMaxVersion(common.GetAllSupportedKubernetesVersions(), true), } orch, e = GetOrchestratorVersionProfile(csOrch) Expect(e).To(BeNil()) Expect(len(orch.Upgrades)).To(Equal(0)) +} +func TestGetOrchestratorVersionProfileListV20170930(t *testing.T) { + RegisterTestingT(t) // v20170930 - all orchestrators list, e := GetOrchestratorVersionProfileListV20170930("", "") Expect(e).To(BeNil()) - Expect(len(list.Properties.Orchestrators)).To(Equal(41)) + numSwarmVersions := 1 + numDockerCEVersions := 1 + totalNumVersions := numSwarmVersions + numDockerCEVersions + len(common.GetAllSupportedKubernetesVersions()) + len(common.AllDCOSSupportedVersions) + Expect(len(list.Properties.Orchestrators)).To(Equal(totalNumVersions)) // v20170930 - kubernetes only list, e = GetOrchestratorVersionProfileListV20170930(common.Kubernetes, "") Expect(e).To(BeNil()) - Expect(len(list.Properties.Orchestrators)).To(Equal(36)) + Expect(len(list.Properties.Orchestrators)).To(Equal(len(common.GetAllSupportedKubernetesVersions()))) } func TestKubernetesInfo(t *testing.T) { diff --git a/pkg/api/v20170930/validate.go b/pkg/api/v20170930/validate.go index edba870920..0ec158838b 100644 --- a/pkg/api/v20170930/validate.go +++ b/pkg/api/v20170930/validate.go @@ -3,8 +3,6 @@ package v20170930 import ( "fmt" "strings" - - "github.com/Azure/acs-engine/pkg/api/common" ) // Validate implements APIObject @@ -31,8 +29,8 @@ func (o *OrchestratorProfile) ValidateForUpgrade() error { return fmt.Errorf("Upgrade is not supported for orchestrator %s", o.OrchestratorType) case Kubernetes: switch o.OrchestratorVersion { - case common.KubernetesVersion1Dot6Dot13: - case common.KubernetesVersion1Dot7Dot14: + case "1.6.13": + case "1.7.14": default: return fmt.Errorf("Upgrade to Kubernetes %s is not supported", o.OrchestratorVersion) } diff --git a/pkg/api/vlabs/validate.go b/pkg/api/vlabs/validate.go index 259f6f473a..d768e825b0 100644 --- a/pkg/api/vlabs/validate.go +++ b/pkg/api/vlabs/validate.go @@ -11,6 +11,7 @@ import ( "github.com/Azure/acs-engine/pkg/api/common" "github.com/Azure/acs-engine/pkg/helpers" + "github.com/Masterminds/semver" "github.com/satori/go.uuid" validator "gopkg.in/go-playground/validator.v9" ) @@ -88,9 +89,9 @@ func (o *OrchestratorProfile) Validate(isUpdate bool) error { return err } if o.KubernetesConfig.EnableAggregatedAPIs { - if o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot6 || - o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot9 || - o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot11 { + sv, _ := semver.NewVersion(o.OrchestratorVersion) + cons, _ := semver.NewConstraint("<" + "1.7.0") + if cons.Check(sv) { return fmt.Errorf("enableAggregatedAPIs is only available in Kubernetes version %s or greater; unable to validate for Kubernetes version %s", "1.7.0", o.OrchestratorVersion) } @@ -102,9 +103,9 @@ func (o *OrchestratorProfile) Validate(isUpdate bool) error { } if helpers.IsTrueBoolPointer(o.KubernetesConfig.EnableDataEncryptionAtRest) { - if o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot6 || - o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot9 || - o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot11 { + sv, _ := semver.NewVersion(o.OrchestratorVersion) + cons, _ := semver.NewConstraint("<" + "1.7.0") + if cons.Check(sv) { return fmt.Errorf("enableDataEncryptionAtRest is only available in Kubernetes version %s or greater; unable to validate for Kubernetes version %s", "1.7.0", o.OrchestratorVersion) } @@ -114,24 +115,12 @@ func (o *OrchestratorProfile) Validate(isUpdate bool) error { if !helpers.IsTrueBoolPointer(o.KubernetesConfig.EnableRbac) { return fmt.Errorf("enablePodSecurityPolicy requires the enableRbac feature as a prerequisite") } - if o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot6 || - o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot9 || - o.OrchestratorVersion == common.KubernetesVersion1Dot6Dot11 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot0 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot1 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot2 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot4 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot5 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot7 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot9 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot10 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot12 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot13 || - o.OrchestratorVersion == common.KubernetesVersion1Dot7Dot14 { + sv, _ := semver.NewVersion(o.OrchestratorVersion) + cons, _ := semver.NewConstraint("<" + "1.8.0") + if cons.Check(sv) { return fmt.Errorf("enablePodSecurityPolicy is only supported in acs-engine for Kubernetes version %s or greater; unable to validate for Kubernetes version %s", "1.8.0", o.OrchestratorVersion) } - } } @@ -235,22 +224,6 @@ func (o *OrchestratorVersionProfile) Validate() error { return o.OrchestratorProfile.Validate(false) } -// ValidateForUpgrade validates upgrade input data -func (o *OrchestratorProfile) ValidateForUpgrade() error { - switch o.OrchestratorType { - case DCOS, SwarmMode, Swarm: - return fmt.Errorf("Upgrade is not supported for orchestrator %s", o.OrchestratorType) - case Kubernetes: - switch o.OrchestratorVersion { - case common.KubernetesVersion1Dot6Dot13: - case common.KubernetesVersion1Dot7Dot14: - default: - return fmt.Errorf("Upgrade to Kubernetes version %s is not supported", o.OrchestratorVersion) - } - } - return nil -} - func validateKeyVaultSecrets(secrets []KeyVaultSecrets, requireCertificateStore bool) error { for _, s := range secrets { if len(s.VaultCertificates) == 0 { @@ -506,44 +479,13 @@ func (a *KubernetesConfig) Validate(k8sVersion string) error { // number of minimum retries allowed for kubelet to post node status const minKubeletRetries = 4 // k8s versions that have cloudprovider backoff enabled - var backoffEnabledVersions = map[string]bool{ - common.KubernetesVersion1Dot10Dot0RC1: true, - common.KubernetesVersion1Dot10Dot0Beta4: true, - common.KubernetesVersion1Dot10Dot0Beta2: true, - common.KubernetesVersion1Dot9Dot0: true, - common.KubernetesVersion1Dot9Dot1: true, - common.KubernetesVersion1Dot9Dot2: true, - common.KubernetesVersion1Dot9Dot3: true, - common.KubernetesVersion1Dot9Dot4: true, - common.KubernetesVersion1Dot9Dot5: true, - common.KubernetesVersion1Dot9Dot6: true, - common.KubernetesVersion1Dot8Dot0: true, - common.KubernetesVersion1Dot8Dot1: true, - common.KubernetesVersion1Dot8Dot2: true, - common.KubernetesVersion1Dot8Dot4: true, - common.KubernetesVersion1Dot8Dot6: true, - common.KubernetesVersion1Dot8Dot7: true, - common.KubernetesVersion1Dot8Dot8: true, - common.KubernetesVersion1Dot8Dot9: true, - common.KubernetesVersion1Dot8Dot10: true, - common.KubernetesVersion1Dot7Dot0: true, - common.KubernetesVersion1Dot7Dot1: true, - common.KubernetesVersion1Dot7Dot2: true, - common.KubernetesVersion1Dot7Dot4: true, - common.KubernetesVersion1Dot7Dot5: true, - common.KubernetesVersion1Dot7Dot7: true, - common.KubernetesVersion1Dot7Dot9: true, - common.KubernetesVersion1Dot7Dot10: true, - common.KubernetesVersion1Dot7Dot12: true, - common.KubernetesVersion1Dot7Dot13: true, - common.KubernetesVersion1Dot7Dot14: true, - common.KubernetesVersion1Dot7Dot15: true, - common.KubernetesVersion1Dot6Dot6: true, - common.KubernetesVersion1Dot6Dot9: true, - common.KubernetesVersion1Dot6Dot11: true, - common.KubernetesVersion1Dot6Dot12: true, - common.KubernetesVersion1Dot6Dot13: true, - } + var backoffEnabledVersions = common.AllKubernetesSupportedVersions + // at present all supported versions allow for cloudprovider backoff + // disallow backoff for future versions thusly: + // for version := range []string{"1.11.0", "1.11.1", "1.11.2"} { + // backoffEnabledVersions[version] = false + // } + // k8s versions that have cloudprovider rate limiting enabled (currently identical with backoff enabled versions) ratelimitEnabledVersions := backoffEnabledVersions @@ -676,30 +618,10 @@ func (a *KubernetesConfig) Validate(k8sVersion string) error { return e } - var ccmEnabledVersions = map[string]bool{ - common.KubernetesVersion1Dot8Dot0: true, - common.KubernetesVersion1Dot8Dot1: true, - common.KubernetesVersion1Dot8Dot2: true, - common.KubernetesVersion1Dot8Dot4: true, - common.KubernetesVersion1Dot8Dot6: true, - common.KubernetesVersion1Dot8Dot7: true, - common.KubernetesVersion1Dot8Dot8: true, - common.KubernetesVersion1Dot8Dot9: true, - common.KubernetesVersion1Dot8Dot10: true, - common.KubernetesVersion1Dot9Dot0: true, - common.KubernetesVersion1Dot9Dot1: true, - common.KubernetesVersion1Dot9Dot2: true, - common.KubernetesVersion1Dot9Dot3: true, - common.KubernetesVersion1Dot9Dot4: true, - common.KubernetesVersion1Dot9Dot5: true, - common.KubernetesVersion1Dot9Dot6: true, - common.KubernetesVersion1Dot10Dot0Beta2: true, - common.KubernetesVersion1Dot10Dot0Beta4: true, - common.KubernetesVersion1Dot10Dot0RC1: true, - } - if a.UseCloudControllerManager != nil && *a.UseCloudControllerManager || a.CustomCcmImage != "" { - if !ccmEnabledVersions[k8sVersion] { + sv, _ := semver.NewVersion(k8sVersion) + cons, _ := semver.NewConstraint("<" + "1.8.0") + if cons.Check(sv) { return fmt.Errorf("OrchestratorProfile.KubernetesConfig.UseCloudControllerManager and OrchestratorProfile.KubernetesConfig.CustomCcmImage not available in kubernetes version %s", k8sVersion) } } diff --git a/pkg/api/vlabs/validate_test.go b/pkg/api/vlabs/validate_test.go index a729a2ecce..a77cd9c675 100644 --- a/pkg/api/vlabs/validate_test.go +++ b/pkg/api/vlabs/validate_test.go @@ -259,10 +259,7 @@ func Test_KubernetesConfig_Validate(t *testing.T) { } // Tests that apply to 1.6 and later releases - for _, k8sVersion := range []string{common.KubernetesVersion1Dot6Dot11, common.KubernetesVersion1Dot6Dot12, common.KubernetesVersion1Dot6Dot13, - common.KubernetesVersion1Dot7Dot7, common.KubernetesVersion1Dot7Dot9, common.KubernetesVersion1Dot7Dot10, common.KubernetesVersion1Dot7Dot12, common.KubernetesVersion1Dot7Dot13, common.KubernetesVersion1Dot7Dot14, - common.KubernetesVersion1Dot8Dot1, common.KubernetesVersion1Dot8Dot2, common.KubernetesVersion1Dot8Dot4, common.KubernetesVersion1Dot8Dot6, common.KubernetesVersion1Dot8Dot7, common.KubernetesVersion1Dot8Dot8, common.KubernetesVersion1Dot8Dot9, common.KubernetesVersion1Dot8Dot10, - common.KubernetesVersion1Dot9Dot0, common.KubernetesVersion1Dot9Dot1, common.KubernetesVersion1Dot9Dot2, common.KubernetesVersion1Dot9Dot3, common.KubernetesVersion1Dot9Dot4, common.KubernetesVersion1Dot9Dot5, common.KubernetesVersion1Dot10Dot0Beta2, common.KubernetesVersion1Dot10Dot0RC1} { + for _, k8sVersion := range common.GetAllSupportedKubernetesVersions() { c := KubernetesConfig{ CloudProviderBackoff: true, CloudProviderRateLimit: true, @@ -274,7 +271,7 @@ func Test_KubernetesConfig_Validate(t *testing.T) { trueVal := true // Tests that apply to 1.8 and later releases - for _, k8sVersion := range []string{common.KubernetesVersion1Dot8Dot1} { + for _, k8sVersion := range common.GetVersionsGt(common.GetAllSupportedKubernetesVersions(), "1.8.0", true, true) { c := KubernetesConfig{ UseCloudControllerManager: &trueVal, } diff --git a/pkg/helpers/helpers.go b/pkg/helpers/helpers.go index 5e0af4827b..9affc4fac2 100644 --- a/pkg/helpers/helpers.go +++ b/pkg/helpers/helpers.go @@ -40,3 +40,9 @@ func IsTrueBoolPointer(b *bool) bool { } return false } + +// PointerToBool returns a pointer to a bool +func PointerToBool(b bool) *bool { + p := b + return &p +} diff --git a/pkg/helpers/helpers_test.go b/pkg/helpers/helpers_test.go new file mode 100644 index 0000000000..37d75cb19f --- /dev/null +++ b/pkg/helpers/helpers_test.go @@ -0,0 +1,11 @@ +package helpers + +import "testing" + +func TestPointerToBool(t *testing.T) { + boolVar := true + ret := PointerToBool(boolVar) + if *ret != boolVar { + t.Fatalf("expected PointerToBool(true) to return *true, instead returned %#v", ret) + } +} diff --git a/pkg/operations/kubernetesupgrade/upgradecluster_test.go b/pkg/operations/kubernetesupgrade/upgradecluster_test.go index 0176d4b9ff..37c44907be 100644 --- a/pkg/operations/kubernetesupgrade/upgradecluster_test.go +++ b/pkg/operations/kubernetesupgrade/upgradecluster_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/Azure/acs-engine/pkg/api" - "github.com/Azure/acs-engine/pkg/api/common" "github.com/Azure/acs-engine/pkg/armhelpers" "github.com/Azure/acs-engine/pkg/i18n" . "github.com/Azure/acs-engine/pkg/test" @@ -27,9 +26,9 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() { }) It("Should return error message when failing to list VMs during upgrade operation", func() { - cs := createContainerService("testcluster", common.KubernetesVersion1Dot6Dot9, 1, 1) + cs := createContainerService("testcluster", "1.6.9", 1, 1) - cs.Properties.OrchestratorProfile.OrchestratorVersion = common.KubernetesVersion1Dot7Dot14 + cs.Properties.OrchestratorProfile.OrchestratorVersion = "1.7.14" uc := UpgradeCluster{ Translator: &i18n.Translator{}, @@ -51,9 +50,9 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() { }) It("Should return error message when failing to detete VMs during upgrade operation", func() { - cs := createContainerService("testcluster", common.KubernetesVersion1Dot6Dot9, 1, 1) + cs := createContainerService("testcluster", "1.6.9", 1, 1) - cs.Properties.OrchestratorProfile.OrchestratorVersion = common.KubernetesVersion1Dot7Dot14 + cs.Properties.OrchestratorProfile.OrchestratorVersion = "1.7.14" uc := UpgradeCluster{ Translator: &i18n.Translator{}, Logger: log.NewEntry(log.New()), @@ -71,8 +70,8 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() { }) It("Should return error message when failing to deploy template during upgrade operation", func() { - cs := createContainerService("testcluster", common.KubernetesVersion1Dot6Dot13, 1, 1) - cs.Properties.OrchestratorProfile.OrchestratorVersion = common.KubernetesVersion1Dot6Dot13 + cs := createContainerService("testcluster", "1.6.13", 1, 1) + cs.Properties.OrchestratorProfile.OrchestratorVersion = "1.6.13" uc := UpgradeCluster{ Translator: &i18n.Translator{}, Logger: log.NewEntry(log.New()), @@ -90,8 +89,8 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() { }) It("Should return error message when failing to get a virtual machine during upgrade operation", func() { - cs := createContainerService("testcluster", common.KubernetesVersion1Dot6Dot9, 1, 6) - cs.Properties.OrchestratorProfile.OrchestratorVersion = common.KubernetesVersion1Dot7Dot14 + cs := createContainerService("testcluster", "1.6.9", 1, 6) + cs.Properties.OrchestratorProfile.OrchestratorVersion = "1.7.14" uc := UpgradeCluster{ Translator: &i18n.Translator{}, Logger: log.NewEntry(log.New()), @@ -109,8 +108,8 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() { }) It("Should return error message when failing to get storage client during upgrade operation", func() { - cs := createContainerService("testcluster", common.KubernetesVersion1Dot6Dot9, 5, 1) - cs.Properties.OrchestratorProfile.OrchestratorVersion = common.KubernetesVersion1Dot7Dot14 + cs := createContainerService("testcluster", "1.6.9", 5, 1) + cs.Properties.OrchestratorProfile.OrchestratorVersion = "1.7.14" uc := UpgradeCluster{ Translator: &i18n.Translator{}, Logger: log.NewEntry(log.New()), @@ -128,8 +127,8 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() { }) It("Should return error message when failing to delete network interface during upgrade operation", func() { - cs := createContainerService("testcluster", common.KubernetesVersion1Dot6Dot9, 3, 2) - cs.Properties.OrchestratorProfile.OrchestratorVersion = common.KubernetesVersion1Dot7Dot14 + cs := createContainerService("testcluster", "1.6.9", 3, 2) + cs.Properties.OrchestratorProfile.OrchestratorVersion = "1.7.14" uc := UpgradeCluster{ Translator: &i18n.Translator{}, Logger: log.NewEntry(log.New()), @@ -147,8 +146,8 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() { }) It("Should return error message when failing on ClusterPreflightCheck operation", func() { - cs := createContainerService("testcluster", common.KubernetesVersion1Dot6Dot9, 3, 3) - cs.Properties.OrchestratorProfile.OrchestratorVersion = common.KubernetesVersion1Dot8Dot6 + cs := createContainerService("testcluster", "1.6.9", 3, 3) + cs.Properties.OrchestratorProfile.OrchestratorVersion = "1.8.6" uc := UpgradeCluster{ Translator: &i18n.Translator{}, Logger: log.NewEntry(log.New()),