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

kubeovn / kube-ovn / 21348330402

26 Jan 2026 06:24AM UTC coverage: 22.918% (+0.02%) from 22.899%
21348330402

push

github

zbb88888
fix: caching NAD CRD should before all kubeovn crds and pod (#6198)

* fix: caching NAD CRD should before all kubeovn crds and pod

---------

Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>

15 of 52 new or added lines in 3 files covered. (28.85%)

1 existing line in 1 file now uncovered.

12303 of 53683 relevant lines covered (22.92%)

0.27 hits per line

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

9.8
/pkg/controller/network_attachment.go
1
package controller
2

3
import (
4
        "context"
5
        "encoding/json"
6
        "time"
7

8
        nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
9
        "gopkg.in/k8snetworkplumbingwg/multus-cni.v4/pkg/logging"
10
        multustypes "gopkg.in/k8snetworkplumbingwg/multus-cni.v4/pkg/types"
11
        "k8s.io/client-go/tools/cache"
12
        "k8s.io/klog/v2"
13

14
        "github.com/kubeovn/kube-ovn/pkg/util"
15
)
16

17
func (c *Controller) isNetAttachCRDInstalled() (bool, error) {
×
18
        return apiResourceExists(
×
19
                c.config.AttachNetClient.Discovery(),
×
20
                nadv1.SchemeGroupVersion.String(),
×
21
                util.ObjectKind[*nadv1.NetworkAttachmentDefinition](),
×
22
        )
×
23
}
×
24

25
// startNetAttachInformer starts the NAD informer and waits for cache sync.
NEW
26
func (c *Controller) startNetAttachInformer(ctx context.Context) {
×
NEW
27
        c.netAttachInformerFactory.Start(ctx.Done())
×
NEW
28
        if !cache.WaitForCacheSync(ctx.Done(), c.netAttachSynced) {
×
NEW
29
                util.LogFatalAndExit(nil, "failed to wait for network attachment cache to sync")
×
NEW
30
        }
×
NEW
31
        klog.Info("Network attachment informer cache synced")
×
32
}
33

34
// tryStartNetAttachInformer checks if NAD CRD is installed and starts the informer if so.
35
// Returns true if informer was started, false otherwise.
NEW
36
func (c *Controller) tryStartNetAttachInformer(ctx context.Context) bool {
×
NEW
37
        exists, err := c.isNetAttachCRDInstalled()
×
NEW
38
        if err != nil {
×
NEW
39
                klog.Warningf("failed to check if network attachment CRD exists: %v", err)
×
NEW
40
                return false
×
NEW
41
        }
×
NEW
42
        if !exists {
×
NEW
43
                return false
×
NEW
44
        }
×
NEW
45
        klog.Info("Network attachment CRD found, starting informer")
×
NEW
46
        c.startNetAttachInformer(ctx)
×
NEW
47
        return true
×
48
}
49

50
// StartNetAttachInformerFactory starts the network attachment definition (NAD) informer.
51
// This MUST be called before other informers that depend on NAD cache (Pod, Subnet, VpcNatGateway, etc.)
52
//
53
// The NAD CRD is optional - if installed, we start the informer synchronously and wait for
54
// cache sync before returning. This ensures NAD cache is ready when other controllers start
55
// processing resources that reference NADs.
56
//
57
// If the CRD is not installed at startup, we start a background goroutine to periodically
58
// check and start the informer when the CRD becomes available.
59
func (c *Controller) StartNetAttachInformerFactory(ctx context.Context) {
×
NEW
60
        if c.tryStartNetAttachInformer(ctx) {
×
NEW
61
                return
×
NEW
62
        }
×
63

64
        // CRD not found at startup, start background check loop
NEW
65
        klog.Info("Network attachment CRD not found at startup, will check periodically in background")
×
66
        ticker := time.NewTicker(10 * time.Second)
×
67
        go func() {
×
68
                defer ticker.Stop()
×
69
                for {
×
70
                        select {
×
71
                        case <-ticker.C:
×
NEW
72
                                if c.tryStartNetAttachInformer(ctx) {
×
73
                                        return
×
UNCOV
74
                                }
×
75
                        case <-ctx.Done():
×
76
                                return
×
77
                        }
78
                }
79
        }()
80
}
81

82
func loadNetConf(bytes []byte) (*multustypes.DelegateNetConf, error) {
1✔
83
        delegateConf := &multustypes.DelegateNetConf{}
1✔
84
        if err := json.Unmarshal(bytes, &delegateConf.Conf); err != nil {
1✔
85
                return nil, logging.Errorf("LoadDelegateNetConf: error unmarshalling delegate config: %v", err)
×
86
        }
×
87

88
        if delegateConf.Conf.Type == "" {
1✔
89
                if err := multustypes.LoadDelegateNetConfList(bytes, delegateConf); err != nil {
×
90
                        return nil, logging.Errorf("LoadDelegateNetConf: failed with: %v", err)
×
91
                }
×
92
        }
93
        return delegateConf, nil
1✔
94
}
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

© 2026 Coveralls, Inc