Skip to content

Commit

Permalink
move k8s/utils/pointer to k8s/utils/ptr
Browse files Browse the repository at this point in the history
Signed-off-by: cyclinder <[email protected]>
  • Loading branch information
cyclinder committed Jan 28, 2024
1 parent 44c200b commit 5081b9e
Show file tree
Hide file tree
Showing 55 changed files with 536 additions and 510 deletions.
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
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.1.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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/sasha-s/go-deadlock v0.3.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spidernet-io/e2eframework v0.0.0-20231218105341-1c8a58f971b5
github.com/spidernet-io/e2eframework v0.0.0-20240127082814-64fbda07e655
github.com/tigera/operator v1.32.4
github.com/vishvananda/netlink v1.2.1-beta.2.0.20230621221334-77712cff8739
go.opentelemetry.io/otel v1.21.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc=
github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg=
github.com/spidernet-io/e2eframework v0.0.0-20231218105341-1c8a58f971b5 h1:oKhkpiVOognuXejQ0qjzJ1goCYbtB7QALDrXcrSd4JU=
github.com/spidernet-io/e2eframework v0.0.0-20231218105341-1c8a58f971b5/go.mod h1:hfCPYyT5sIQUe22Hz1E7QiJ2ugm8fxAbN1o1AtaIaNc=
github.com/spidernet-io/e2eframework v0.0.0-20240127082814-64fbda07e655 h1:l0ZpCKTS/rj1RF0TnbtJBOMyKRt7iurvn7tHm3RUBQM=
github.com/spidernet-io/e2eframework v0.0.0-20240127082814-64fbda07e655/go.mod h1:k0KYxyNjZYyEG1bsGzSbMx5Q+Z1H6oOjEq5qz9UlBzY=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
18 changes: 9 additions & 9 deletions pkg/applicationcontroller/app_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/spidernet-io/spiderpool/pkg/applicationcontroller/applicationinformers"
Expand All @@ -49,7 +49,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {
UID: types.UID("123"),
},
Spec: appsv1.DeploymentSpec{
Replicas: pointer.Int32(1),
Replicas: ptr.To(int32(1)),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
Expand All @@ -71,7 +71,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {
UID: types.UID("123"),
},
Spec: appsv1.ReplicaSetSpec{
Replicas: pointer.Int32(1),
Replicas: ptr.To(int32(1)),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
Expand Down Expand Up @@ -114,7 +114,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {
UID: types.UID("123"),
},
Spec: appsv1.StatefulSetSpec{
Replicas: pointer.Int32(1),
Replicas: ptr.To(int32(1)),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
Expand Down Expand Up @@ -508,7 +508,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {

It("change deployment replicas with spider subnet annotation", func() {
deployment2 := deployment1.DeepCopy()
deployment2.Spec.Replicas = pointer.Int32(2)
deployment2.Spec.Replicas = ptr.To(int32(2))
err := reconcileFunc(ctx, deployment1, deployment2)
Expect(err).NotTo(HaveOccurred())
})
Expand Down Expand Up @@ -548,7 +548,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {

It("change replicaSet replicas with spider subnet annotation", func() {
replicaSet2 := replicaSet1.DeepCopy()
replicaSet2.Spec.Replicas = pointer.Int32(2)
replicaSet2.Spec.Replicas = ptr.To(int32(2))
err := reconcileFunc(ctx, replicaSet1, replicaSet2)
Expect(err).NotTo(HaveOccurred())
})
Expand Down Expand Up @@ -635,7 +635,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {

It("change statefulset replicas with spider subnet annotation", func() {
statefulSet2 := statefulSet1.DeepCopy()
statefulSet2.Spec.Replicas = pointer.Int32(2)
statefulSet2.Spec.Replicas = ptr.To(int32(2))
err := reconcileFunc(ctx, statefulSet1, statefulSet2)
Expect(err).NotTo(HaveOccurred())
})
Expand Down Expand Up @@ -675,7 +675,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {

It("change job replicas with spider subnet annotation", func() {
job2 := job1.DeepCopy()
job2.Spec.Parallelism = pointer.Int32(2)
job2.Spec.Parallelism = ptr.To(int32(2))
err := reconcileFunc(ctx, job1, job2)
Expect(err).NotTo(HaveOccurred())
})
Expand Down Expand Up @@ -722,7 +722,7 @@ var _ = Describe("AppController", Label("app_controller_test"), func() {

It("change cronJob replicas with spider subnet annotation", func() {
cronJob2 := cronJob1.DeepCopy()
cronJob2.Spec.JobTemplate.Spec.Parallelism = pointer.Int32(3)
cronJob2.Spec.JobTemplate.Spec.Parallelism = ptr.To(int32(3))
err := reconcileFunc(ctx, cronJob1, cronJob2)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/applicationcontroller/applicationinformers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
apitypes "k8s.io/apimachinery/pkg/types"
k8svalidation "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/client-go/dynamic"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"k8s.io/utils/strings/slices"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -224,13 +224,13 @@ func GetSubnetAnnoConfig(podAnnotations map[string]string, log *zap.Logger) (*ty
}

if isFlexible {
subnetAnnoConfig.FlexibleIPNum = pointer.Int(ipNum)
subnetAnnoConfig.FlexibleIPNum = ptr.To(ipNum)
} else {
subnetAnnoConfig.AssignIPNum = ipNum
}
} else {
log.Sugar().Debugf("no specified IPPool IP number, default to use cluster default subnet flexible IP number: %d", *ClusterSubnetDefaultFlexibleIPNumber)
subnetAnnoConfig.FlexibleIPNum = pointer.Int(*ClusterSubnetDefaultFlexibleIPNumber)
subnetAnnoConfig.FlexibleIPNum = ptr.To(*ClusterSubnetDefaultFlexibleIPNumber)
}

// annotation: "ipam.spidernet.io/reclaim-ippool", reclaim IPPool or not (default true)
Expand Down
Loading

0 comments on commit 5081b9e

Please sign in to comment.