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

Commit

Permalink
feat: add "get-versions --azure-env" flag to list custom clouds suppo…
Browse files Browse the repository at this point in the history
…rted versions (#3394)
  • Loading branch information
haofan-ms authored Jun 4, 2020
1 parent f167e41 commit aa2973a
Show file tree
Hide file tree
Showing 22 changed files with 333 additions and 157 deletions.
4 changes: 3 additions & 1 deletion cmd/get_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type getVersionsCmd struct {
orchestrator string
version string
windows bool
azureEnv string
output string
}

Expand All @@ -44,6 +45,7 @@ func newGetVersionsCmd() *cobra.Command {
gvc.orchestrator = "Kubernetes" // orchestrator is always Kubernetes
f.StringVar(&gvc.version, "version", "", "Kubernetes version (optional)")
f.BoolVar(&gvc.windows, "windows", false, "Kubernetes cluster with Windows nodes (optional)")
f.StringVar(&gvc.azureEnv, "azure-env", "AzurePublicCloud", "The target Azure cloud")
getVersionsCmdDescription := fmt.Sprintf("Output format. Allowed values: %s",
strings.Join(outputFormatOptions, ", "))
f.StringVarP(&gvc.output, "output", "o", "human", getVersionsCmdDescription)
Expand All @@ -52,7 +54,7 @@ func newGetVersionsCmd() *cobra.Command {
}

func (gvc *getVersionsCmd) run(cmd *cobra.Command, args []string) error {
orchs, err := api.GetOrchestratorVersionProfileListVLabs(gvc.orchestrator, gvc.version, gvc.windows)
orchs, err := api.GetOrchestratorVersionProfileListVLabs(gvc.orchestrator, gvc.version, gvc.windows, gvc.azureEnv)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (uc *upgradeCmd) loadCluster() error {

func (uc *upgradeCmd) validateTargetVersion() error {
// Get available upgrades for container service.
orchestratorInfo, err := api.GetOrchestratorVersionProfile(uc.containerService.Properties.OrchestratorProfile, uc.containerService.Properties.HasWindows())
orchestratorInfo, err := api.GetOrchestratorVersionProfile(uc.containerService.Properties.OrchestratorProfile, uc.containerService.Properties.HasWindows(), uc.containerService.Properties.IsAzureStackCloud())
if err != nil {
return errors.Wrap(err, "error getting list of available upgrades")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/agentPoolOnlyApi/v20180331/apiloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var _ = Describe("v20180331 test suite", func() {
locale := gotext.NewLocale(path.Join("../../..", "../../..", "translations"), "en_US")
_ = i18n.Initialize(locale)
apiloader := &api.Apiloader{}
k8sVersions := common.GetAllSupportedKubernetesVersions(false, false)
defaultK8sVersion := common.GetDefaultKubernetesVersion(false)
k8sVersions := common.GetAllSupportedKubernetesVersions(false, false, false)
defaultK8sVersion := common.GetDefaultKubernetesVersion(false, false)

Context("when networkprofile is nil, enable the addon profile", func() {
It("should merge fields properly", func() {
Expand Down
9 changes: 5 additions & 4 deletions pkg/api/apiloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(
hasExistingCS := existingContainerService != nil
IsSSHAutoGenerated := false
hasWindows := false
isAzureStackCloud := false
switch version {
case v20170831.APIVersion:
managedCluster := &v20170831.ManagedCluster{}
Expand All @@ -168,14 +169,14 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(

// use defaultKubernetesVersion arg if no version was supplied in the request contents
if managedCluster.Properties.KubernetesVersion == "" && defaultKubernetesVersion != "" {
if !common.IsSupportedKubernetesVersion(defaultKubernetesVersion, isUpdate, hasWindows) {
if !common.IsSupportedKubernetesVersion(defaultKubernetesVersion, isUpdate, hasWindows, isAzureStackCloud) {
return nil, IsSSHAutoGenerated, a.Translator.Errorf("The selected orchestrator version '%s' is not supported", defaultKubernetesVersion)
}
managedCluster.Properties.KubernetesVersion = defaultKubernetesVersion
}

// verify orchestrator version
if len(managedCluster.Properties.KubernetesVersion) > 0 && !common.IsSupportedKubernetesVersion(managedCluster.Properties.KubernetesVersion, isUpdate, hasWindows) {
if len(managedCluster.Properties.KubernetesVersion) > 0 && !common.IsSupportedKubernetesVersion(managedCluster.Properties.KubernetesVersion, isUpdate, hasWindows, isAzureStackCloud) {
return nil, IsSSHAutoGenerated, a.Translator.Errorf("The selected orchestrator version '%s' is not supported", managedCluster.Properties.KubernetesVersion)
}

Expand Down Expand Up @@ -208,7 +209,7 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(

// use defaultKubernetesVersion arg if no version was supplied in the request contents
if managedCluster.Properties.KubernetesVersion == "" && defaultKubernetesVersion != "" {
if !common.IsSupportedKubernetesVersion(defaultKubernetesVersion, isUpdate, hasWindows) {
if !common.IsSupportedKubernetesVersion(defaultKubernetesVersion, isUpdate, hasWindows, isAzureStackCloud) {
return nil, IsSSHAutoGenerated, a.Translator.Errorf("The selected orchestrator version '%s' is not supported", defaultKubernetesVersion)
}
if hasExistingCS {
Expand All @@ -219,7 +220,7 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(
}

// verify orchestrator version
if len(managedCluster.Properties.KubernetesVersion) > 0 && !common.IsSupportedKubernetesVersion(managedCluster.Properties.KubernetesVersion, isUpdate, hasWindows) {
if len(managedCluster.Properties.KubernetesVersion) > 0 && !common.IsSupportedKubernetesVersion(managedCluster.Properties.KubernetesVersion, isUpdate, hasWindows, isAzureStackCloud) {
return nil, IsSSHAutoGenerated, a.Translator.Errorf("The selected orchestrator version '%s' is not supported", managedCluster.Properties.KubernetesVersion)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/apiloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestLoadContainerServiceForAgentPoolOnlyCluster(t *testing.T) {
Locale: locale,
},
}
k8sVersions := common.GetAllSupportedKubernetesVersions(true, false)
defaultK8sVersion := common.GetDefaultKubernetesVersion(false)
k8sVersions := common.GetAllSupportedKubernetesVersions(true, false, false)
defaultK8sVersion := common.GetDefaultKubernetesVersion(false, false)

Context("v20180331", func() {
It("it should return error if managed cluster body is empty", func() {
Expand Down
6 changes: 5 additions & 1 deletion pkg/api/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ const (
const (
// KubernetesDefaultRelease is the default Kubernetes release
KubernetesDefaultRelease string = "1.18"
// KubernetesDefaultReleaseWindows is the default Kubernetes release
// KubernetesDefaultReleaseWindows is the default Kubernetes release for Windows
KubernetesDefaultReleaseWindows string = "1.18"
// KubernetesDefaultReleaseAzureStack is the default Kubernetes release on Azure Stack
KubernetesDefaultReleaseAzureStack string = "1.17"
// KubernetesDefaultReleaseWindowsAzureStack is the default Kubernetes release for Windows on Azure Stack
KubernetesDefaultReleaseWindowsAzureStack string = "1.17"
)

const (
Expand Down
88 changes: 73 additions & 15 deletions pkg/api/common/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,53 @@ var AllKubernetesSupportedVersions = map[string]bool{
"1.19.0-beta.0": true,
}

// AllKubernetesSupportedVersionsAzureStack is a whitelist map of all supported Kubernetes version strings on Azure Stack
// The bool value indicates if creating new clusters with this version is allowed
var AllKubernetesSupportedVersionsAzureStack = map[string]bool{
"1.14.7": false,
"1.14.8": false, // disabled because of https://github.com/Azure/aks-engine/issues/2312
"1.15.4": false,
"1.15.5": false, // disabled because of https://github.com/Azure/aks-engine/issues/2312
"1.15.10": false,
"1.15.11": true,
"1.15.12": true,
"1.16.9": true,
"1.16.10": true,
"1.17.4": false,
"1.17.5": true,
"1.17.6": true,
}

// AllKubernetesWindowsSupportedVersionsAzureStack maintain a set of available k8s Windows versions in aks-engine on Azure Stack
var AllKubernetesWindowsSupportedVersionsAzureStack = map[string]bool{
"1.15.10": false,
"1.15.11": true,
"1.15.12": true,
"1.16.9": true,
"1.16.10": true,
"1.17.4": false,
"1.17.5": true,
"1.17.6": true,
}

// GetDefaultKubernetesVersion returns the default Kubernetes version, that is the latest patch of the default release
func GetDefaultKubernetesVersion(hasWindows bool) string {
func GetDefaultKubernetesVersion(hasWindows bool, isAzureStackCloud bool) string {
defaultRelease := KubernetesDefaultRelease
if hasWindows {
defaultRelease = KubernetesDefaultReleaseWindows
}
return GetLatestPatchVersion(defaultRelease, GetAllSupportedKubernetesVersions(false, hasWindows))
if isAzureStackCloud && hasWindows {
defaultRelease = KubernetesDefaultReleaseWindowsAzureStack
}
if isAzureStackCloud && !hasWindows {
defaultRelease = KubernetesDefaultReleaseAzureStack
}
return GetLatestPatchVersion(defaultRelease, GetAllSupportedKubernetesVersions(false, hasWindows, isAzureStackCloud))
}

// GetSupportedKubernetesVersion verifies that a passed-in version string is supported, or returns a default version string if not
func GetSupportedKubernetesVersion(version string, hasWindows bool) string {
k8sVersion := GetDefaultKubernetesVersion(hasWindows)
func GetSupportedKubernetesVersion(version string, hasWindows bool, isAzureStackCloud bool) string {
k8sVersion := GetDefaultKubernetesVersion(hasWindows, isAzureStackCloud)
if hasWindows {
if AllKubernetesWindowsSupportedVersions[version] {
k8sVersion = version
Expand All @@ -219,16 +254,35 @@ func GetSupportedKubernetesVersion(version string, hasWindows bool) string {
k8sVersion = version
}
}
if isAzureStackCloud {
if hasWindows {
if AllKubernetesWindowsSupportedVersionsAzureStack[version] {
k8sVersion = version
}
} else {
if AllKubernetesSupportedVersionsAzureStack[version] {
k8sVersion = version
}
}
}
return k8sVersion
}

// GetAllSupportedKubernetesVersions returns a slice of all supported Kubernetes versions
func GetAllSupportedKubernetesVersions(isUpdate, hasWindows bool) []string {
func GetAllSupportedKubernetesVersions(isUpdate, hasWindows bool, isAzureStackCloud bool) []string {
var versions []string
allSupportedVersions := AllKubernetesSupportedVersions
if hasWindows {
allSupportedVersions = AllKubernetesWindowsSupportedVersions
}

if isAzureStackCloud && hasWindows {
allSupportedVersions = AllKubernetesWindowsSupportedVersionsAzureStack
}
if isAzureStackCloud && !hasWindows {
allSupportedVersions = AllKubernetesSupportedVersionsAzureStack
}

for ver, supported := range allSupportedVersions {
if isUpdate || supported {
versions = append(versions, ver)
Expand Down Expand Up @@ -362,10 +416,10 @@ func getAllKubernetesWindowsSupportedVersionsMap() map[string]bool {
}

// GetSupportedVersions get supported version list for a certain orchestrator
func GetSupportedVersions(orchType string, isUpdate, hasWindows bool) (versions []string, defaultVersion string) {
func GetSupportedVersions(orchType string, isUpdate, hasWindows bool, isAzureStackCloud bool) (versions []string, defaultVersion string) {
switch orchType {
case Kubernetes:
return GetAllSupportedKubernetesVersions(isUpdate, hasWindows), GetDefaultKubernetesVersion(hasWindows)
return GetAllSupportedKubernetesVersions(isUpdate, hasWindows, isAzureStackCloud), GetDefaultKubernetesVersion(hasWindows, isAzureStackCloud)
case DCOS:
return AllDCOSSupportedVersions, DCOSDefaultVersion
default:
Expand All @@ -374,14 +428,15 @@ func GetSupportedVersions(orchType string, isUpdate, hasWindows bool) (versions
}

//GetValidPatchVersion gets the current valid patch version for the minor version of the passed in version
func GetValidPatchVersion(orchType, orchVer string, isUpdate, hasWindows bool) string {
func GetValidPatchVersion(orchType, orchVer string, isUpdate, hasWindows bool, isAzureStackCloud bool) string {
if orchVer == "" {
return RationalizeReleaseAndVersion(
orchType,
"",
"",
isUpdate,
hasWindows)
hasWindows,
isAzureStackCloud)
}

// check if the current version is valid, this allows us to have multiple supported patch versions in the future if we need it
Expand All @@ -390,7 +445,8 @@ func GetValidPatchVersion(orchType, orchVer string, isUpdate, hasWindows bool) s
"",
orchVer,
isUpdate,
hasWindows)
hasWindows,
isAzureStackCloud)

if version == "" {
sv, err := semver.Make(orchVer)
Expand All @@ -404,17 +460,18 @@ func GetValidPatchVersion(orchType, orchVer string, isUpdate, hasWindows bool) s
sr,
"",
isUpdate,
hasWindows)
hasWindows,
isAzureStackCloud)
}
return version
}

// RationalizeReleaseAndVersion return a version when it can be rationalized from the input, otherwise ""
func RationalizeReleaseAndVersion(orchType, orchRel, orchVer string, isUpdate, hasWindows bool) (version string) {
func RationalizeReleaseAndVersion(orchType, orchRel, orchVer string, isUpdate, hasWindows bool, isAzureStackCloud 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, isUpdate, hasWindows)
supportedVersions, defaultVersion := GetSupportedVersions(orchType, isUpdate, hasWindows, isAzureStackCloud)
if supportedVersions == nil {
return ""
}
Expand Down Expand Up @@ -457,6 +514,7 @@ func IsValidMinVersion(orchType, orchRelease, orchVersion, minVersion string) (b
orchRelease,
orchVersion,
false,
false,
false)
if version == "" {
return false, errors.Errorf("the following user supplied OrchestratorProfile configuration is not supported: OrchestratorType: %s, OrchestratorRelease: %s, OrchestratorVersion: %s. Please check supported Release or Version for this build of aks-engine",
Expand Down Expand Up @@ -510,8 +568,8 @@ func GetLatestPatchVersion(majorMinor string, versionsList []string) (version st
}

// IsSupportedKubernetesVersion return true if the provided Kubernetes version is supported
func IsSupportedKubernetesVersion(version string, isUpdate, hasWindows bool) bool {
for _, ver := range GetAllSupportedKubernetesVersions(isUpdate, hasWindows) {
func IsSupportedKubernetesVersion(version string, isUpdate, hasWindows bool, isAzureStackCloud bool) bool {
for _, ver := range GetAllSupportedKubernetesVersions(isUpdate, hasWindows, isAzureStackCloud) {
if ver == version {
return true
}
Expand Down
Loading

0 comments on commit aa2973a

Please sign in to comment.