Skip to content

Commit

Permalink
Fix ExternalCIDR set before PodCIDR and ServiceCIDR
Browse files Browse the repository at this point in the history
  • Loading branch information
davidefalcone1 committed May 24, 2021
1 parent 8476758 commit 25099b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Expand Up @@ -19,10 +19,6 @@ import (
func (tec *TunnelEndpointCreator) setNetParameters(config *configv1alpha1.ClusterConfig) {
podCIDR := config.Spec.LiqonetConfig.PodCIDR
serviceCIDR := config.Spec.LiqonetConfig.ServiceCIDR
externalCIDR, err := tec.IPManager.GetExternalCIDR(liqonet.GetMask(podCIDR))
if err != nil {
klog.Error(err)
}
if tec.PodCIDR != podCIDR {
if err := tec.IPManager.SetPodCIDR(podCIDR); err != nil {
klog.Error(err)
Expand All @@ -37,6 +33,10 @@ func (tec *TunnelEndpointCreator) setNetParameters(config *configv1alpha1.Cluste
klog.Infof("ServiceCIDR set to %s", serviceCIDR)
tec.ServiceCIDR = serviceCIDR
}
externalCIDR, err := tec.IPManager.GetExternalCIDR(liqonet.GetMask(podCIDR))
if err != nil {
klog.Error(err)
}
if tec.ExternalCIDR != externalCIDR {
klog.Infof("ExternalCIDR set to %s", externalCIDR)
tec.ExternalCIDR = externalCIDR
Expand Down
18 changes: 18 additions & 0 deletions pkg/liqonet/ipam_test.go
Expand Up @@ -510,6 +510,24 @@ var _ = Describe("Ipam", func() {
Expect(err).ToNot(BeNil())
})
})
Context("Call after SetPodCIDR", func() {
It("should return no errors", func() {
err := ipam.SetPodCIDR("10.0.0.0/24")
Expect(err).To(BeNil())
_, err = ipam.GetExternalCIDR(24)
Expect(err).To(BeNil())
})
})
Context("Call before SetPodCIDR", func() {
It("should produce an error in SetPodCIDR", func() {
_, err := ipam.GetExternalCIDR(24)
Expect(err).To(BeNil())
// ExternalCIDR has been assigned "10.0.0.0/24", so the network
// is not available anymore.
err = ipam.SetPodCIDR("10.0.0.0/24")
Expect(err).ToNot(BeNil())
})
})
})

Describe("SetPodCIDR", func() {
Expand Down

0 comments on commit 25099b3

Please sign in to comment.