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

Commit

Permalink
acs-engine orchestrators should thrown an error when an invalid/unsup…
Browse files Browse the repository at this point in the history
…ported version is provided
  • Loading branch information
tariq1890 committed May 31, 2018
1 parent c5a958b commit 174915e
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 9 deletions.
17 changes: 17 additions & 0 deletions pkg/api/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,24 @@ const (
OpenShiftDefaultVersion string = OpenShiftVersion3Dot9Dot0
)

const (
// SwarmVersion is the Swarm orchestrator version
SwarmVersion = "swarm:1.1.0"
// DockerCEVersion is the DockerCE orchestrator version
DockerCEVersion = "17.03.*"
)

// GetAllSupportedOpenShiftVersions returns a slice of all supported OpenShift versions.
func GetAllSupportedOpenShiftVersions() []string {
return []string{OpenShiftVersion3Dot9Dot0, OpenShiftVersionUnstable}
}

// GetAllSupportedSwarmVersions returns a slice of all supported Swarm versions.
func GetAllSupportedSwarmVersions() []string {
return []string{SwarmVersion}
}

// GetAllSupportedDockerCEVersions returns a slice of all supported Docker CE versions.
func GetAllSupportedDockerCEVersions() []string {
return []string{DockerCEVersion}
}
87 changes: 85 additions & 2 deletions pkg/api/orchestrators.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ func kubernetesInfo(csOrch *OrchestratorProfile) ([]*OrchestratorVersionProfile,
return nil, fmt.Errorf("Kubernetes version %s is not supported", csOrch.OrchestratorVersion)
}

isVersionSupported := false
for _, version := range common.GetAllSupportedKubernetesVersions() {

if version == csOrch.OrchestratorVersion {
isVersionSupported = true
break
}

}

if !isVersionSupported {
return nil, fmt.Errorf("Kubernetes version %s is not supported", csOrch.OrchestratorVersion)
}
upgrades, err := kubernetesUpgrades(csOrch)
if err != nil {
return nil, err
Expand Down Expand Up @@ -204,6 +217,19 @@ func dcosInfo(csOrch *OrchestratorProfile) ([]*OrchestratorVersionProfile, error
})
}
} else {
isVersionSupported := false
for _, version := range common.AllDCOSSupportedVersions {
if version == csOrch.OrchestratorVersion {
isVersionSupported = true
break
}

}

if !isVersionSupported {
return nil, fmt.Errorf("DCOS version %s is not supported", csOrch.OrchestratorVersion)
}

// get info for the specified version
upgrades, err := dcosUpgrades(csOrch)
if err != nil {
Expand Down Expand Up @@ -236,22 +262,67 @@ func dcosUpgrades(csOrch *OrchestratorProfile) ([]*OrchestratorProfile, error) {
}

func swarmInfo(csOrch *OrchestratorProfile) ([]*OrchestratorVersionProfile, error) {
if csOrch.OrchestratorVersion == "" {
return []*OrchestratorVersionProfile{
{
OrchestratorProfile: OrchestratorProfile{
OrchestratorType: Swarm,
OrchestratorVersion: SwarmVersion,
},
},
}, nil
}
isVersionSupported := false
for _, version := range common.GetAllSupportedSwarmVersions() {

if version == csOrch.OrchestratorVersion {
isVersionSupported = true
break
}
}

if !isVersionSupported {
return nil, fmt.Errorf("Swarm version %s is not supported", csOrch.OrchestratorVersion)
}
return []*OrchestratorVersionProfile{
{
OrchestratorProfile: OrchestratorProfile{
OrchestratorType: Swarm,
OrchestratorVersion: SwarmVersion,
OrchestratorVersion: csOrch.OrchestratorVersion,
},
},
}, nil
}

func dockerceInfo(csOrch *OrchestratorProfile) ([]*OrchestratorVersionProfile, error) {

if csOrch.OrchestratorVersion == "" {
return []*OrchestratorVersionProfile{
{
OrchestratorProfile: OrchestratorProfile{
OrchestratorType: SwarmMode,
OrchestratorVersion: DockerCEVersion,
},
},
}, nil
}
isVersionSupported := false
for _, version := range common.GetAllSupportedDockerCEVersions() {

if version == csOrch.OrchestratorVersion {
isVersionSupported = true
break
}
}

if !isVersionSupported {
return nil, fmt.Errorf("Docker CE version %s is not supported", csOrch.OrchestratorVersion)
}
return []*OrchestratorVersionProfile{
{
OrchestratorProfile: OrchestratorProfile{
OrchestratorType: SwarmMode,
OrchestratorVersion: DockerCEVersion,
OrchestratorVersion: csOrch.OrchestratorVersion,
},
},
}, nil
Expand Down Expand Up @@ -288,6 +359,18 @@ func openShiftInfo(csOrch *OrchestratorProfile) ([]*OrchestratorVersionProfile,
return nil, fmt.Errorf("OpenShift version %s is not supported", csOrch.OrchestratorVersion)
}

isVersionSupported := false
for _, version := range common.GetAllSupportedOpenShiftVersions() {

if version == csOrch.OrchestratorVersion {
isVersionSupported = true
}
}

if !isVersionSupported {
return nil, fmt.Errorf("OpenShift version %s is not supported", csOrch.OrchestratorVersion)
}

// TODO: populate OrchestratorVersionProfile.Upgrades
orchs = append(orchs,
&OrchestratorVersionProfile{
Expand Down
97 changes: 93 additions & 4 deletions pkg/api/orchestrators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ 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"
// 1.6.9 is upgradable to 1.6.x and 1.7.x
deployedVersion := "1.6.9"
nextNextMinorVersion := "1.8.0"
csOrch := &OrchestratorProfile{
OrchestratorType: Kubernetes,
Expand Down Expand Up @@ -164,7 +164,9 @@ func TestKubernetesInfo(t *testing.T) {
"31.29.",
".17.02",
"43.156.89.",
"1.2.a"}
"1.2.a",
"1.5.9",
"1.6.8"}

for _, v := range invalid {
csOrch := &OrchestratorProfile{
Expand All @@ -188,7 +190,9 @@ func TestOpenshiftInfo(t *testing.T) {
"31.29.",
".17.02",
"43.156.89.",
"1.2.a"}
"1.2.a",
"3.8.9",
"3.9.2"}

for _, v := range invalid {
csOrch := &OrchestratorProfile{
Expand All @@ -209,3 +213,88 @@ func TestOpenshiftInfo(t *testing.T) {
_, e := openShiftInfo(csOrch)
Expect(e).To(BeNil())
}

func TestDcosInfo(t *testing.T) {
RegisterTestingT(t)
invalid := []string{
"invalid number",
"invalid.number",
"a4.b7.c3",
"31.29.",
".17.02",
"43.156.89.",
"1.2.a"}

for _, v := range invalid {
csOrch := &OrchestratorProfile{
OrchestratorType: DCOS,
OrchestratorVersion: v,
}

_, e := dcosInfo(csOrch)
Expect(e).NotTo(BeNil())
}

// test good value
csOrch := &OrchestratorProfile{
OrchestratorType: DCOS,
OrchestratorVersion: common.DCOSDefaultVersion,
}

_, e := dcosInfo(csOrch)
Expect(e).To(BeNil())
}

func TestSwarmInfo(t *testing.T) {
RegisterTestingT(t)
invalid := []string{
"swarm:1.1.1",
"swarm:1.1.2",
}

for _, v := range invalid {
csOrch := &OrchestratorProfile{
OrchestratorType: Swarm,
OrchestratorVersion: v,
}

_, e := swarmInfo(csOrch)
Expect(e).NotTo(BeNil())
}

// test good value
csOrch := &OrchestratorProfile{
OrchestratorType: Swarm,
OrchestratorVersion: common.SwarmVersion,
}

_, e := swarmInfo(csOrch)
Expect(e).To(BeNil())
}

func TestDockerceInfoInfo(t *testing.T) {
RegisterTestingT(t)
invalid := []string{
"17.02.1",
"43.156.89",
}

for _, v := range invalid {
csOrch := &OrchestratorProfile{
OrchestratorType: SwarmMode,
OrchestratorVersion: v,
}

_, e := dockerceInfo(csOrch)
Expect(e).NotTo(BeNil())
}

// test good value
csOrch := &OrchestratorProfile{
OrchestratorType: SwarmMode,
OrchestratorVersion: common.DockerCEVersion,
}

_, e := dockerceInfo(csOrch)
Expect(e).To(BeNil())
}
4 changes: 2 additions & 2 deletions pkg/armhelpers/mockclients.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (mc *MockACSEngineClient) ListVirtualMachines(resourceGroup string) (comput
poolnameString := "poolName"

creationSource := "acsengine-k8s-agentpool1-12345678-0"
orchestrator := "Kubernetes:1.6.8"
orchestrator := "Kubernetes:1.6.9"
resourceNameSuffix := "12345678"
poolname := "agentpool1"

Expand Down Expand Up @@ -272,7 +272,7 @@ func (mc *MockACSEngineClient) GetVirtualMachine(resourceGroup, name string) (co
poolnameString := "poolName"

creationSource := "acsengine-k8s-agentpool1-12345678-0"
orchestrator := "Kubernetes:1.6.8"
orchestrator := "Kubernetes:1.6.9"
resourceNameSuffix := "12345678"
poolname := "agentpool1"

Expand Down
2 changes: 1 addition & 1 deletion pkg/operations/kubernetesupgrade/upgradecluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ var _ = Describe("Upgrade Kubernetes cluster tests", func() {

err := uc.UpgradeCluster(subID, "kubeConfig", "TestRg", cs, "12345678", []string{"agentpool1"}, TestACSEngineVersion)
Expect(err).NotTo(BeNil())
Expect(err.Error()).To(Equal("Error while querying ARM for resources: Kubernetes:1.6.8 cannot be upgraded to 1.8.6"))
Expect(err.Error()).To(Equal("Error while querying ARM for resources: Kubernetes:1.6.9 cannot be upgraded to 1.8.6"))
})

It("Should return error message when failing to delete role assignment during upgrade operation", func() {
Expand Down

0 comments on commit 174915e

Please sign in to comment.