• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubeovn / kube-ovn / 19527788804

20 Nov 2025 06:25AM UTC coverage: 21.99% (+0.08%) from 21.909%
19527788804

Pull #5543

github

zbb88888
fix: 使用 any 替换 interface{} (Go 1.18+)

- 修复 golangci-lint modernize 检查
- 在 subnet_bigint_test.go 中替换 3 处 interface{}
- 在 subnet_bigint_e2e_test.go 中替换 4 处 interface{}
- 保持测试逻辑不变

Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
Pull Request #5543: Controller gen

66 of 123 new or added lines in 9 files covered. (53.66%)

2 existing lines in 1 file now uncovered.

11187 of 50873 relevant lines covered (21.99%)

0.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/webhook/subnet.go
1
package webhook
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7
        "net/http"
8
        "slices"
9

10
        ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
11
        "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
12

13
        ovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
14
        "github.com/kubeovn/kube-ovn/pkg/util"
15
)
16

17
func (v *ValidatingHook) SubnetCreateHook(ctx context.Context, req admission.Request) admission.Response {
×
18
        o := ovnv1.Subnet{}
×
19
        if err := v.decoder.Decode(req, &o); err != nil {
×
20
                return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
21
        }
×
22

23
        if err := util.ValidateSubnet(o); err != nil {
×
24
                return ctrlwebhook.Denied(err.Error())
×
25
        }
×
26

27
        subnetList := &ovnv1.SubnetList{}
×
28
        if err := v.cache.List(ctx, subnetList); err != nil {
×
29
                return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
30
        }
×
31
        if err := util.ValidateCidrConflict(o, subnetList.Items); err != nil {
×
32
                return admission.Errored(http.StatusConflict, err)
×
33
        }
×
34

35
        vpcList := &ovnv1.VpcList{}
×
36
        if err := v.cache.List(ctx, vpcList); err != nil {
×
37
                return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
38
        }
×
39
        for _, item := range vpcList.Items {
×
40
                if item.Name == o.Name {
×
41
                        err := errors.New("vpc and subnet cannot have the same name")
×
42
                        return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
43
                }
×
44

45
                if o.Spec.Vpc == item.Name && item.Status.Standby && !item.Status.Default {
×
46
                        for _, ns := range o.Spec.Namespaces {
×
47
                                if !slices.Contains(item.Spec.Namespaces, ns) {
×
48
                                        err := fmt.Errorf("namespace '%s' is out of range to custom vpc '%s'", ns, item.Name)
×
49
                                        return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
50
                                }
×
51
                        }
52
                }
53
        }
54

55
        return ctrlwebhook.Allowed("by pass")
×
56
}
57

58
func (v *ValidatingHook) SubnetUpdateHook(ctx context.Context, req admission.Request) admission.Response {
×
59
        o := ovnv1.Subnet{}
×
60
        if err := v.decoder.Decode(req, &o); err != nil {
×
61
                return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
62
        }
×
63

64
        oldSubnet := ovnv1.Subnet{}
×
65
        if err := v.decoder.DecodeRaw(req.OldObject, &oldSubnet); err != nil {
×
66
                return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
67
        }
×
NEW
68
        if (o.Spec.Gateway != oldSubnet.Spec.Gateway) && (!o.Status.V4UsingIPs.EqualInt64(0) || !o.Status.V6UsingIPs.EqualInt64(0)) {
×
69
                return ctrlwebhook.Denied("can't update gateway of cidr when any IPs in Using")
×
70
        }
×
71

72
        if err := util.ValidateSubnet(o); err != nil {
×
73
                return ctrlwebhook.Denied(err.Error())
×
74
        }
×
75

76
        subnetList := &ovnv1.SubnetList{}
×
77
        if err := v.cache.List(ctx, subnetList); err != nil {
×
78
                return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
79
        }
×
80
        if err := util.ValidateCidrConflict(o, subnetList.Items); err != nil {
×
81
                return admission.Errored(http.StatusConflict, err)
×
82
        }
×
83

84
        return ctrlwebhook.Allowed("by pass")
×
85
}
86

87
func (v *ValidatingHook) SubnetDeleteHook(_ context.Context, req admission.Request) admission.Response {
×
88
        subnet := ovnv1.Subnet{}
×
89
        if err := v.decoder.DecodeRaw(req.OldObject, &subnet); err != nil {
×
90
                return ctrlwebhook.Errored(http.StatusBadRequest, err)
×
91
        }
×
NEW
92
        if !subnet.Status.V4UsingIPs.EqualInt64(0) || !subnet.Status.V6UsingIPs.EqualInt64(0) {
×
93
                return ctrlwebhook.Denied("can't delete subnet when any IPs in Using")
×
94
        }
×
95
        return ctrlwebhook.Allowed("by pass")
×
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc