Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronize clusterIP CIDR from serviceCIDR to support k8s 1.29 #3132

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 6 additions & 6 deletions cmd/coordinator/cmd/cni_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/version"
"github.com/go-openapi/strfmt"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/spidernet-io/spiderpool/api/v1/agent/models"
"github.com/spidernet-io/spiderpool/pkg/logutils"
Expand Down Expand Up @@ -141,7 +141,7 @@ func ParseConfig(stdin []byte, coordinatorConfig *models.CoordinatorConfig) (*Co
}

if conf.IPConflict == nil && coordinatorConfig.DetectIPConflict {
conf.IPConflict = pointer.Bool(true)
conf.IPConflict = ptr.To(true)
}

conf.DetectOptions, err = ValidateDelectOptions(conf.DetectOptions)
Expand All @@ -150,19 +150,19 @@ func ParseConfig(stdin []byte, coordinatorConfig *models.CoordinatorConfig) (*Co
}

if conf.HostRuleTable == nil && coordinatorConfig.HostRuleTable > 0 {
conf.HostRuleTable = pointer.Int64(coordinatorConfig.HostRuleTable)
conf.HostRuleTable = ptr.To(coordinatorConfig.HostRuleTable)
}

if conf.TxQueueLen == nil {
conf.TxQueueLen = pointer.Int64(coordinatorConfig.TxQueueLen)
conf.TxQueueLen = ptr.To(coordinatorConfig.TxQueueLen)
}

if conf.HostRuleTable == nil {
conf.HostRuleTable = pointer.Int64(500)
conf.HostRuleTable = ptr.To(int64(500))
}

if conf.DetectGateway == nil {
conf.DetectGateway = pointer.Bool(coordinatorConfig.DetectGateway)
conf.DetectGateway = ptr.To(coordinatorConfig.DetectGateway)
}

if conf.TunePodRoutes == nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/spiderpool-agent/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/grafana/pyroscope-go"
apiruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/spidernet-io/spiderpool/pkg/ipam"
Expand Down Expand Up @@ -142,7 +142,7 @@ func DaemonMain() {
AgentNamespace: agentContext.Cfg.AgentPodNamespace,
}
if len(agentContext.Cfg.MultusClusterNetwork) != 0 {
ipamConfig.MultusClusterNetwork = pointer.String(agentContext.Cfg.MultusClusterNetwork)
ipamConfig.MultusClusterNetwork = ptr.To(agentContext.Cfg.MultusClusterNetwork)
}
ipam, err := ipam.NewIPAM(
ipamConfig,
Expand Down
6 changes: 3 additions & 3 deletions cmd/spiderpool-init/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/containernetworking/cni/libcni"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

coordinatorcmd "github.com/spidernet-io/spiderpool/cmd/coordinator/cmd"
"github.com/spidernet-io/spiderpool/pkg/constant"
Expand Down Expand Up @@ -363,8 +363,8 @@ func getMultusCniConfig(cniName, cniType string, ns string) *spiderpoolv2beta1.S
Annotations: annotations,
},
Spec: spiderpoolv2beta1.MultusCNIConfigSpec{
CniType: pointer.String(cniType),
EnableCoordinator: pointer.Bool(false),
CniType: ptr.To(cniType),
EnableCoordinator: ptr.To(false),
},
}
}
22 changes: 11 additions & 11 deletions cmd/spiderpool-init/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/spidernet-io/spiderpool/pkg/constant"
spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1"
Expand Down Expand Up @@ -65,13 +65,13 @@ func Execute() {
Name: config.V4SubnetName,
},
Spec: spiderpoolv2beta1.SubnetSpec{
IPVersion: pointer.Int64(constant.IPv4),
IPVersion: ptr.To(constant.IPv4),
Subnet: config.V4CIDR,
IPs: config.V4IPRanges,
},
}
if len(config.V4Gateway) != 0 {
subnet.Spec.Gateway = pointer.String(config.V4Gateway)
subnet.Spec.Gateway = ptr.To(config.V4Gateway)
}

if err := client.WaitForSubnetCreated(ctx, subnet); err != nil {
Expand All @@ -87,13 +87,13 @@ func Execute() {
Name: config.V6SubnetName,
},
Spec: spiderpoolv2beta1.SubnetSpec{
IPVersion: pointer.Int64(constant.IPv6),
IPVersion: ptr.To(constant.IPv6),
Subnet: config.V6CIDR,
IPs: config.V6IPRanges,
},
}
if len(config.V6Gateway) != 0 {
subnet.Spec.Gateway = pointer.String(config.V6Gateway)
subnet.Spec.Gateway = ptr.To(config.V6Gateway)
}

if err := client.WaitForSubnetCreated(ctx, subnet); err != nil {
Expand All @@ -109,14 +109,14 @@ func Execute() {
Name: config.V4IPPoolName,
},
Spec: spiderpoolv2beta1.IPPoolSpec{
IPVersion: pointer.Int64(constant.IPv4),
IPVersion: ptr.To(constant.IPv4),
Subnet: config.V4CIDR,
IPs: config.V4IPRanges,
Default: pointer.Bool(true),
Default: ptr.To(true),
},
}
if len(config.V4Gateway) != 0 {
ipPool.Spec.Gateway = pointer.String(config.V4Gateway)
ipPool.Spec.Gateway = ptr.To(config.V4Gateway)
}

if err := client.WaitForIPPoolCreated(ctx, ipPool); err != nil {
Expand All @@ -132,14 +132,14 @@ func Execute() {
Name: config.V6IPPoolName,
},
Spec: spiderpoolv2beta1.IPPoolSpec{
IPVersion: pointer.Int64(constant.IPv6),
IPVersion: ptr.To(constant.IPv6),
Subnet: config.V6CIDR,
IPs: config.V6IPRanges,
Default: pointer.Bool(true),
Default: ptr.To(true),
},
}
if len(config.V6Gateway) != 0 {
ipPool.Spec.Gateway = pointer.String(config.V6Gateway)
ipPool.Spec.Gateway = ptr.To(config.V6Gateway)
}

if err := client.WaitForIPPoolCreated(ctx, ipPool); err != nil {
Expand Down
28 changes: 14 additions & 14 deletions cmd/spiderpool/cmd/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/spidernet-io/spiderpool/api/v1/agent/models"
"github.com/spidernet-io/spiderpool/api/v1/agent/server/restapi/connectivity"
Expand Down Expand Up @@ -206,19 +206,19 @@ var _ = Describe("spiderpool plugin", Label("unittest", "ipam_plugin_test"), fun
},
Ips: []*models.IPConfig{
{
Address: pointer.String("1.2.3.30/24"),
Address: ptr.To("1.2.3.30/24"),
Gateway: "1.2.3.1",
Nic: pointer.String("eth0"),
Version: pointer.Int64(constant.IPv4),
Nic: ptr.To("eth0"),
Version: ptr.To(constant.IPv4),
},
{
Address: pointer.String("fc00:f853:ccd:e793:f::fc/64"),
Address: ptr.To("fc00:f853:ccd:e793:f::fc/64"),
Gateway: "fc00:f853:ccd:e793:f::2",
Nic: pointer.String("eth0"),
Version: pointer.Int64(constant.IPv6),
Nic: ptr.To("eth0"),
Version: ptr.To(constant.IPv6),
},
},
Routes: []*models.Route{{IfName: pointer.String("eth0"), Dst: pointer.String("15.5.6.0/24"), Gw: pointer.String("1.2.3.2")}},
Routes: []*models.Route{{IfName: ptr.To("eth0"), Dst: ptr.To("15.5.6.0/24"), Gw: ptr.To("1.2.3.2")}},
}

return ipamAddResp
Expand Down Expand Up @@ -262,10 +262,10 @@ var _ = Describe("spiderpool plugin", Label("unittest", "ipam_plugin_test"), fun
},
Ips: []*models.IPConfig{
{
Address: pointer.String("10.1.0.6/24"),
Address: ptr.To("10.1.0.6/24"),
Gateway: "10.1.0.2",
Nic: pointer.String(ifName),
Version: pointer.Int64(constant.IPv4),
Nic: ptr.To(ifName),
Version: ptr.To(constant.IPv4),
},
},
}
Expand Down Expand Up @@ -301,9 +301,9 @@ var _ = Describe("spiderpool plugin", Label("unittest", "ipam_plugin_test"), fun
DNS: &models.DNS{},
Ips: []*models.IPConfig{
{
Address: pointer.String("10.1.0.7/24"),
Nic: pointer.String(ifName),
Version: pointer.Int64(constant.IPv4),
Address: ptr.To("10.1.0.7/24"),
Nic: ptr.To(ifName),
Version: ptr.To(constant.IPv4),
},
},
}
Expand Down
59 changes: 59 additions & 0 deletions docs/concepts/coordinator-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,65 @@ spec:
txQueueLen: 2000
```

## 自动获取集群 Service 的 CIDR

Kubernetes 1.29 开始支持以 ServiceCIDR 资源的方式配置集群 Service 的 CIDR,更多信息参考 [KEP 1880](https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/1880-multiple-service-cidrs/README.md)。如果您的集群支持 ServiceCIDR,Spiderpool-controller 组件 自动监听 ServiceCIDR 资源的变化,将读取到的 Service 子网信息自动更新到 Spidercoordinator 的 Status 中。

```shell
~# kubectl get servicecidr kubernetes -o yaml
apiVersion: networking.k8s.io/v1alpha1
kind: ServiceCIDR
metadata:
creationTimestamp: "2024-01-25T08:36:00Z"
finalizers:
- networking.k8s.io/service-cidr-finalizer
name: kubernetes
resourceVersion: "504422"
uid: 72461b7d-fddd-409d-bdf2-83d1a2c067ca
spec:
cidrs:
- 10.233.0.0/18
- fd00:10:233::/116
status:
conditions:
- lastTransitionTime: "2024-01-28T06:38:55Z"
message: Kubernetes Service CIDR is ready
reason: ""
status: "True"
type: Ready

~# kubectl get spidercoordinators.spiderpool.spidernet.io default -o yaml
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderCoordinator
metadata:
creationTimestamp: "2024-01-25T08:41:50Z"
finalizers:
- spiderpool.spidernet.io
generation: 1
name: default
resourceVersion: "41645"
uid: d1e095db-d6e8-4413-b60e-fcf31ad2bf5e
spec:
detectGateway: false
detectIPConflict: false
hijackCIDR:
- 10.244.64.0/18
- fd00:10:244::/112
hostRPFilter: 0
hostRuleTable: 500
mode: auto
podCIDRType: auto
podDefaultRouteNIC: ""
podMACPrefix: ""
tunePodRoutes: true
txQueueLen: 0
status:
phase: Synced
serviceCIDR:
- 10.233.0.0/18
- fd00:10:233::/116
```

## 已知问题

- underlay 模式下,underlay Pod 与 Overlay Pod(calico or cilium) 进行 TCP 通信失败
Expand Down
59 changes: 59 additions & 0 deletions docs/concepts/coordinator.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,65 @@ spec:
txQueueLen: 2000
```

## Automatically get the CIDR of a clustered Service

Kubernetes 1.29 starts to support configuring the CIDR of a clustered Service as a ServiceCIDR resource, for more information refer to [KEP 1880](https://github.com/kubernetes/enhancements/blob/master/keps/ sig-network/1880-multiple-service-cidrs/README.md). If your cluster supports ServiceCIDR, the Spiderpool-controller component automatically listens for changes to the ServiceCIDR resource and automatically updates the Service subnet information it reads into the Status of the Spidercoordinator.

```shell
~# kubectl get servicecidr kubernetes -o yaml
apiVersion: networking.k8s.io/v1alpha1
kind: ServiceCIDR
metadata:
creationTimestamp: "2024-01-25T08:36:00Z"
finalizers:
- networking.k8s.io/service-cidr-finalizer
name: kubernetes
resourceVersion: "504422"
uid: 72461b7d-fddd-409d-bdf2-83d1a2c067ca
spec:
cidrs:
- 10.233.0.0/18
- fd00:10:233::/116
status:
conditions:
- lastTransitionTime: "2024-01-28T06:38:55Z"
message: Kubernetes Service CIDR is ready
reason: ""
status: "True"
type: Ready

~# kubectl get spidercoordinators.spiderpool.spidernet.io default -o yaml
apiVersion: spiderpool.spidernet.io/v2beta1
kind: SpiderCoordinator
metadata:
creationTimestamp: "2024-01-25T08:41:50Z"
finalizers:
- spiderpool.spidernet.io
generation: 1
name: default
resourceVersion: "41645"
uid: d1e095db-d6e8-4413-b60e-fcf31ad2bf5e
spec:
detectGateway: false
detectIPConflict: false
hijackCIDR:
- 10.244.64.0/18
- fd00:10:244::/112
hostRPFilter: 0
hostRuleTable: 500
mode: auto
podCIDRType: auto
podDefaultRouteNIC: ""
podMACPrefix: ""
tunePodRoutes: true
txQueueLen: 0
status:
phase: Synced
serviceCIDR:
- 10.233.0.0/18
- fd00:10:233::/116
```

## Known issues

- Underlay mode: TCP communication between underlay Pods and overlay Pods (Calico or Cilium) fails
Expand Down
3 changes: 3 additions & 0 deletions docs/develop/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
| CNI version | cni v1.0.0 | v0.4.0 | v0.5.0 | |
| ifacer | bond interface | v0.6.0 | v0.8.0 | |
| | vlan interface | v0.6.0 | v0.8.0 | |
| SpiderCoordinator | Sync podCIDR for calico | v0.6.0 | v0.8.0
| | Sync podCIDR for cilium | v0.6.0 | v0.8.0
| | sync clusterIP CIDR from serviceCIDR to support k8s 1.29 | | v0.10.0 |
| Coordinator | support underlay mode | v0.6.0 | v0.7.0 | |
| | support overlay mode | v0.6.0 | v0.8.0 | |
| | CRD spidercoordinators for multus configuration | v0.6.0 | v0.8.0 | |
Expand Down
Loading
Loading