Skip to content

Commit

Permalink
Fix controller panic in cilium ipam is multi-pool
Browse files Browse the repository at this point in the history
Signed-off-by: Cyclinder Kuo <[email protected]>
  • Loading branch information
cyclinder committed Dec 27, 2024
1 parent 7fd26d8 commit 124a63a
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 186 deletions.
10 changes: 8 additions & 2 deletions pkg/coordinatormanager/coordinator_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,18 +704,24 @@ func (cc *CoordinatorController) fetchCiliumIPPools(coordinator *spiderpoolv2bet

podCIDR := make([]string, 0, len(ipPoolList))
for _, p := range ipPoolList {
if p.DeletionTimestamp == nil {
if p.DeletionTimestamp != nil {
continue
}

if p.Spec.IPv4 != nil {
for _, cidr := range p.Spec.IPv4.CIDRs {
podCIDR = append(podCIDR, string(cidr))
}
}

if p.Spec.IPv6 != nil {
for _, cidr := range p.Spec.IPv6.CIDRs {
podCIDR = append(podCIDR, string(cidr))
}
}
}

InformerLogger.Sugar().Debugf("Cilium IPPools CIDR: %v", ipPoolList)
InformerLogger.Sugar().Debugf("Cilium IPPools CIDR: %v", podCIDR)
if coordinator.Status.Phase == Synced && reflect.DeepEqual(coordinator.Status.OverlayPodCIDR, podCIDR) {
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ setup_kruise:
HELM_OPTION=" --wait --timeout 20m --debug --set manager.image.repository=$(E2E_OPENKRUISE_IMAGE) " ; \
HELM_OPTION+=" --version $(E2E_OPENKRUISE_VERSION) " ; \
helm upgrade --install kruise openkruise/kruise $${HELM_OPTION} \
--kubeconfig $(E2E_KUBECONFIG) || { KIND_CLUSTER_NAME=$(E2E_CLUSTER_NAME) ./scripts/debugEnv.sh $(E2E_KUBECONFIG) "detail" "$(E2E_LOG_FILE)" ; exit 1 ; } ; \
--kubeconfig $(E2E_KUBECONFIG) || { \
kubectl describe pod -n kruise-system --kubeconfig $(E2E_KUBECONFIG) ; \
KIND_CLUSTER_NAME=$(E2E_CLUSTER_NAME) ./scripts/debugEnv.sh $(E2E_KUBECONFIG) "detail" "$(E2E_LOG_FILE)" ; exit 1 ; \
} ; \

.PHONY: setup_spiderpool
setup_spiderpool:
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ K8S_IPV4_SERVICE_CIDR = 10.233.0.0/18
K8S_IPV6_SERVICE_CIDR = fd00:10:233::/116

CLUSTER_POD_SUBNET_V4 = 10.233.64.0/18
CLUSTER_POD_SUBNET_V6 = fd00:10:233:64::/64
CLUSTER_POD_SUBNET_V6 = fd00:10:233:64::/60
CALICO_CLUSTER_POD_SUBNET_V4 = 10.243.64.0/18
CALICO_CLUSTER_POD_SUBNET_V6 = fd00:10:243::/112
CILIUM_CLUSTER_POD_SUBNET_V4 = 10.244.64.0/18
Expand Down
1 change: 1 addition & 0 deletions test/doc/spidercoodinator.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
| V00009 | it can get the clusterCIDR from kubeadmConfig or kube-controller-manager pod | p3 | | done | |
| V00010 | It can get service cidr from k8s serviceCIDR resoures | p3 | | done | |
| V00011 | status should be NotReady if neither kubeadm-config configMap nor kube-controller-manager pod can be found | p3 | | done | |
| V00012 | tesing the switch of cilium ipam mode: multi-pool to cluster-pool | p3 | | done | |
13 changes: 12 additions & 1 deletion test/e2e/common/spiderpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/spidernet-io/spiderpool/pkg/constant"
ip "github.com/spidernet-io/spiderpool/pkg/ip"
"github.com/spidernet-io/spiderpool/pkg/types"

corev1 "k8s.io/api/core/v1"

api_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -469,6 +469,17 @@ func GenerateExampleIpv4poolObject(ipNum int) (string, *v1.SpiderIPPool) {
return v4PoolName, iPv4PoolObj
}

func PatchConfigMap(f *frame.Framework, oldcm, newcm *corev1.ConfigMap, opts ...client.PatchOption) error {
mergePatch := client.MergeFrom(oldcm)
d, err := mergePatch.Data(newcm)
GinkgoWriter.Printf("patch configMap: %v. \n", string(d))
if err != nil {
return fmt.Errorf("failed to generate patch, err is %v", err)
}

return f.PatchResource(newcm, mergePatch, opts...)
}

func GenerateExampleIpv6poolObject(ipNum int) (string, *v1.SpiderIPPool) {
if ipNum < 1 || ipNum > 65533 {
GinkgoWriter.Println("the IP range should be between 1 and 65533")
Expand Down
63 changes: 61 additions & 2 deletions test/e2e/spidercoordinator/spidercoordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,63 @@ var _ = Describe("SpiderCoordinator", Label("spidercoordinator", "overlay"), Ser
})
})

Context("tesing the switch of cilium ipam mode: multi-pool to cluster-pool", func() {
var cm *corev1.ConfigMap
var err error
var clusterIPv4CIDR, clusterIPv6CIDR string
BeforeEach(func() {
if !common.CheckRunOverlayCNI() && !common.CheckCalicoFeatureOn() && !common.CheckCiliumFeatureOn() {
GinkgoWriter.Println("This environment is in underlay mode.")
Skip("This case don't need to run for underlay")
}

if common.CheckCalicoFeatureOn() && !common.CheckCiliumFeatureOn() {
GinkgoWriter.Println("The environment is calico mode.")
Skip("This case don't need to run for calico")
}

if common.CheckCiliumFeatureOn() && !common.CheckCalicoFeatureOn() {
GinkgoWriter.Println("The environment is cilium mode.")
}

cm, err = frame.GetConfigmap("cilium-config", "kube-system")
Expect(err).NotTo(HaveOccurred(), "error to get cilium configmap: %v\n", err)

ipam := cm.Data["ipam"]
GinkgoWriter.Println("cilium ipam mode is: ", ipam)

// update cilim ipam mode to cluster-pool
})

It("tesing the switch of cilium ipam mode: multi-pool to cluster-pool", Label("V00012"), func() {
Eventually(func() bool {
spc, err := GetSpiderCoordinator(common.SpidercoodinatorDefaultName)
Expect(err).NotTo(HaveOccurred(), "failed to get SpiderCoordinator, error is %v", err)
GinkgoWriter.Printf("Display the default spider coordinator information, podCIDRType: %v, status: %v \n", *spc.Spec.PodCIDRType, spc.Status)

if len(spc.Status.OverlayPodCIDR) == 0 || spc.Status.Phase != coordinatormanager.Synced {
GinkgoWriter.Printf("status.overlayPodCIDR status is still synchronizing, status %+v \n", spc.Status.OverlayPodCIDR)
return false
}

for _, cidr := range spc.Status.OverlayPodCIDR {
if ip.IsIPv4CIDR(cidr) {
if cidr != clusterIPv4CIDR {
return false
}
GinkgoWriter.Printf("ipv4 podCIDR is as expected, value %v=%v \n", cidr, clusterIPv4CIDR)
} else {
if cidr != clusterIPv6CIDR {
return false
}
GinkgoWriter.Printf("ipv6 podCIDR is as expected, value %v=%v \n", cidr, clusterIPv6CIDR)
}
}
return true
}, common.ExecCommandTimeout, common.EventOccurTimeout*2).Should(BeTrue())
})
})

Context("It can get the clusterCIDR from kubeadmConfig and kube-controller-manager pod", func() {

var spc *spiderpoolv2beta1.SpiderCoordinator
Expand Down Expand Up @@ -729,8 +786,10 @@ var _ = Describe("SpiderCoordinator", Label("spidercoordinator", "overlay"), Ser
spcCopy.Spec.HostRuleTable = ptr.To(500)
Expect(PatchSpiderCoordinator(spcCopy, spc)).NotTo(HaveOccurred())

GinkgoWriter.Println("delete namespace: ", nsName)
Expect(frame.DeleteNamespace(nsName)).NotTo(HaveOccurred())
if !CurrentSpecReport().Failed() {
GinkgoWriter.Println("delete namespace: ", nsName)
Expect(frame.DeleteNamespace(nsName)).NotTo(HaveOccurred())
}
})
})

Expand Down
Loading

0 comments on commit 124a63a

Please sign in to comment.