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 30, 2024
1 parent 7fd26d8 commit e1183b4
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 191 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
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
6 changes: 4 additions & 2 deletions test/e2e/spidercoordinator/spidercoordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,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 e1183b4

Please sign in to comment.