Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
Allow addings zones for AWS infra
Browse files Browse the repository at this point in the history
  • Loading branch information
timuthy committed Nov 15, 2019
1 parent b333930 commit d0ef532
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,27 @@ func ValidateInfrastructureConfig(infra *apisaws.InfrastructureConfig, nodesCIDR
func ValidateInfrastructureConfigUpdate(oldConfig, newConfig *apisaws.InfrastructureConfig, nodesCIDR, podsCIDR, servicesCIDR *string) field.ErrorList {
allErrs := field.ErrorList{}

allErrs = append(allErrs, apivalidation.ValidateImmutableField(newConfig.Networks, oldConfig.Networks, field.NewPath("networks"))...)
allErrs = append(allErrs, apivalidation.ValidateImmutableField(newConfig.Networks.VPC, oldConfig.Networks.VPC, field.NewPath("networks.vpc"))...)

var (
oldZones = oldConfig.Networks.Zones
newZones = newConfig.Networks.Zones
missingZones = sets.NewString()
)

for i, oldZone := range oldZones {
missingZones.Insert(oldZone.Name)
for j, newZone := range newZones {
if newZone.Name == oldZone.Name {
missingZones.Delete(newZone.Name)
allErrs = append(allErrs, apivalidation.ValidateImmutableField(newConfig.Networks.Zones[j], oldConfig.Networks.Zones[j], field.NewPath("networks.zones").Index(i))...)
}
}
}

for zone := range missingZones {
allErrs = append(allErrs, field.Invalid(field.NewPath("networks.zones"), zone, "zone is missing - removing a zone is not supported"))
}

return allErrs
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var _ = Describe("InfrastructureConfig validation", func() {
vpc = "10.0.0.0/8"
invalidCIDR = "invalid-cidr"
zone = "zone1"
zone2 = "zone2"
)

BeforeEach(func() {
Expand All @@ -62,7 +63,6 @@ var _ = Describe("InfrastructureConfig validation", func() {
shoot *gardencorev1alpha1.Shoot
region = "eu-west"
region2 = "us-west"
zone2 = "zone2"
)
Context("zones validation", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -298,11 +298,28 @@ var _ = Describe("InfrastructureConfig validation", func() {
})

Describe("#ValidateInfrastructureConfigUpdate", func() {
var zone2 = apisaws.Zone{
Name: zone2,
Internal: "10.250.4.0/24",
Public: "10.250.5.0/24",
Workers: "10.250.6.0/24",
}

It("should return no errors for an unchanged config", func() {
Expect(ValidateInfrastructureConfigUpdate(infrastructureConfig, infrastructureConfig, &nodes, &pods, &services)).To(BeEmpty())
})

It("should forbid changing the network section", func() {
It("should allow adding a zone", func() {

newInfrastructureConfig := infrastructureConfig.DeepCopy()
newInfrastructureConfig.Networks.Zones = append(newInfrastructureConfig.Networks.Zones, zone2)

errorList := ValidateInfrastructureConfigUpdate(infrastructureConfig, newInfrastructureConfig, &nodes, &pods, &services)

Expect(errorList).To(BeEmpty())
})

It("should forbid changing the VPC", func() {
newInfrastructureConfig := infrastructureConfig.DeepCopy()
newCIDR := "1.2.3.4/5"
newInfrastructureConfig.Networks.VPC.CIDR = &newCIDR
Expand All @@ -311,7 +328,31 @@ var _ = Describe("InfrastructureConfig validation", func() {

Expect(errorList).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Type": Equal(field.ErrorTypeInvalid),
"Field": Equal("networks"),
"Field": Equal("networks.vpc"),
}))))
})

It("should forbid changing the zone information", func() {
newInfrastructureConfig := infrastructureConfig.DeepCopy()
newInfrastructureConfig.Networks.Zones[0].Internal = "10.250.2.0/24"

errorList := ValidateInfrastructureConfigUpdate(infrastructureConfig, newInfrastructureConfig, &nodes, &pods, &services)

Expect(errorList).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Type": Equal(field.ErrorTypeInvalid),
"Field": Equal("networks.zones[0]"),
}))))
})

It("should forbid removing a zone", func() {
newInfrastructureConfig := infrastructureConfig.DeepCopy()
newInfrastructureConfig.Networks.Zones[0] = zone2

errorList := ValidateInfrastructureConfigUpdate(infrastructureConfig, newInfrastructureConfig, &nodes, &pods, &services)

Expect(errorList).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Type": Equal(field.ErrorTypeInvalid),
"Field": Equal("networks.zones"),
}))))
})
})
Expand Down

0 comments on commit d0ef532

Please sign in to comment.