Skip to content

Commit 3177e93

Browse files
authored
modernize: simplify code by using modern constructs (#5163)
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent 9987f55 commit 3177e93

File tree

169 files changed

+702
-750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+702
-750
lines changed

build.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ lint:
147147
ifeq ($(CI),true)
148148
@echo "Running in GitHub Actions"
149149
golangci-lint run -v
150+
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
150151
else
151152
@echo "Running in local environment"
152153
golangci-lint run -v --fix
154+
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test --fix ./...
153155
endif
154156

155157
.PHONY: lint-windows

cmd/cni/cni.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
Add: cmdAdd,
3030
Del: cmdDel,
3131
}
32-
about := fmt.Sprintf("CNI kube-ovn plugin %s", versions.VERSION)
32+
about := "CNI kube-ovn plugin " + versions.VERSION
3333
skel.PluginMainFuncs(funcs, version.All, about)
3434
}
3535

@@ -111,7 +111,7 @@ func generateCNIResult(cniResponse *request.CniResponse, netns string) current.R
111111
var netMask *net.IPNet
112112
var gwStr string
113113
addRoutes := len(result.Routes) == 0
114-
for _, cidrBlock := range strings.Split(cniResponse.CIDR, ",") {
114+
for cidrBlock := range strings.SplitSeq(cniResponse.CIDR, ",") {
115115
_, netMask, _ = net.ParseCIDR(cidrBlock)
116116
gwStr = ""
117117
if util.CheckProtocol(cidrBlock) == kubeovnv1.ProtocolIPv4 {
@@ -227,16 +227,16 @@ func parseValueFromArgs(key, argString string) (string, error) {
227227
if argString == "" {
228228
return "", types.NewError(types.ErrInvalidNetworkConfig, "Invalid Configuration", "CNI_ARGS is required")
229229
}
230-
args := strings.Split(argString, ";")
231-
for _, arg := range args {
232-
if strings.HasPrefix(arg, fmt.Sprintf("%s=", key)) {
233-
value := strings.TrimPrefix(arg, fmt.Sprintf("%s=", key))
230+
args := strings.SplitSeq(argString, ";")
231+
for arg := range args {
232+
if strings.HasPrefix(arg, key+"=") {
233+
value := strings.TrimPrefix(arg, key+"=")
234234
if len(value) > 0 {
235235
return value, nil
236236
}
237237
}
238238
}
239-
return "", types.NewError(types.ErrInvalidNetworkConfig, "Invalid Configuration", fmt.Sprintf("%s is required in CNI_ARGS", key))
239+
return "", types.NewError(types.ErrInvalidNetworkConfig, "Invalid Configuration", key+" is required in CNI_ARGS")
240240
}
241241

242242
func assignV4Address(ipAddress, gateway string, mask *net.IPNet) (*current.IPConfig, *types.Route) {

cmd/daemon/cniserver.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"errors"
5-
"fmt"
65
"net"
76
"net/http"
87
"net/http/pprof"
@@ -81,7 +80,7 @@ func main() {
8180
stopCh := ctx.Done()
8281
podInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeClient, 0,
8382
kubeinformers.WithTweakListOptions(func(listOption *v1.ListOptions) {
84-
listOption.FieldSelector = fmt.Sprintf("spec.nodeName=%s", config.NodeName)
83+
listOption.FieldSelector = "spec.nodeName=" + config.NodeName
8584
listOption.AllowWatchBookmarks = true
8685
}))
8786
nodeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(config.KubeClient, 0,

pkg/apis/kubeovn/v1/condition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ type Condition struct {
4141
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
4242
// Last time the condition was probed
4343
// +optional
44-
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
44+
LastUpdateTime metav1.Time `json:"lastUpdateTime"`
4545
// Last time the condition transitioned from one status to another.
4646
// +optional
47-
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
47+
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
4848
}
4949

5050
type Conditions []Condition

pkg/apis/kubeovn/v1/ip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type IPList struct {
1818
// +genclient:nonNamespaced
1919
type IP struct {
2020
metav1.TypeMeta `json:",inline"`
21-
metav1.ObjectMeta `json:"metadata,omitempty"`
21+
metav1.ObjectMeta `json:"metadata"`
2222

2323
Spec IPSpec `json:"spec"`
2424
}

pkg/apis/kubeovn/v1/ippool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ type IPPoolList struct {
2424
// +genclient:nonNamespaced
2525
type IPPool struct {
2626
metav1.TypeMeta `json:",inline"`
27-
metav1.ObjectMeta `json:"metadata,omitempty"`
27+
metav1.ObjectMeta `json:"metadata"`
2828

2929
Spec IPPoolSpec `json:"spec"`
30-
Status IPPoolStatus `json:"status,omitempty"`
30+
Status IPPoolStatus `json:"status"`
3131
}
3232

3333
type IPPoolSpec struct {

pkg/apis/kubeovn/v1/iptables-dnat-rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ type IptablesDnatRuleList struct {
2222
// +resourceName=iptables-dnat-rules
2323
type IptablesDnatRule struct {
2424
metav1.TypeMeta `json:",inline"`
25-
metav1.ObjectMeta `json:"metadata,omitempty"`
25+
metav1.ObjectMeta `json:"metadata"`
2626

2727
Spec IptablesDnatRuleSpec `json:"spec"`
28-
Status IptablesDnatRuleStatus `json:"status,omitempty"`
28+
Status IptablesDnatRuleStatus `json:"status"`
2929
}
3030

3131
type IptablesDnatRuleSpec struct {

pkg/apis/kubeovn/v1/iptables-eip.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ type IptablesEIPList struct {
2222
// +resourceName=iptables-eips
2323
type IptablesEIP struct {
2424
metav1.TypeMeta `json:",inline"`
25-
metav1.ObjectMeta `json:"metadata,omitempty"`
25+
metav1.ObjectMeta `json:"metadata"`
2626

2727
Spec IptablesEIPSpec `json:"spec"`
28-
Status IptablesEIPStatus `json:"status,omitempty"`
28+
Status IptablesEIPStatus `json:"status"`
2929
}
3030
type IptablesEIPSpec struct {
3131
V4ip string `json:"v4ip"`

pkg/apis/kubeovn/v1/iptables-fip-rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ type IptablesFIPRuleList struct {
2222
// +resourceName=iptables-fip-rules
2323
type IptablesFIPRule struct {
2424
metav1.TypeMeta `json:",inline"`
25-
metav1.ObjectMeta `json:"metadata,omitempty"`
25+
metav1.ObjectMeta `json:"metadata"`
2626

2727
Spec IptablesFIPRuleSpec `json:"spec"`
28-
Status IptablesFIPRuleStatus `json:"status,omitempty"`
28+
Status IptablesFIPRuleStatus `json:"status"`
2929
}
3030
type IptablesFIPRuleSpec struct {
3131
EIP string `json:"eip"`

pkg/apis/kubeovn/v1/iptables-snat-rule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ type IptablesSnatRuleList struct {
2222
// +resourceName=iptables-snat-rules
2323
type IptablesSnatRule struct {
2424
metav1.TypeMeta `json:",inline"`
25-
metav1.ObjectMeta `json:"metadata,omitempty"`
25+
metav1.ObjectMeta `json:"metadata"`
2626

2727
Spec IptablesSnatRuleSpec `json:"spec"`
28-
Status IptablesSnatRuleStatus `json:"status,omitempty"`
28+
Status IptablesSnatRuleStatus `json:"status"`
2929
}
3030

3131
type IptablesSnatRuleSpec struct {

0 commit comments

Comments
 (0)