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

Azure / aks-app-routing-operator / 13994063215

21 Mar 2025 02:30PM UTC coverage: 81.634%. Remained the same
13994063215

push

github

web-flow
Merge branch 'main' into kingoliver/cleanup

107 of 158 new or added lines in 11 files covered. (67.72%)

73 existing lines in 6 files now uncovered.

3778 of 4628 relevant lines covered (81.63%)

20.35 hits per line

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

89.13
/pkg/controller/crd.go
1
package controller
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7
        "os"
8
        "path/filepath"
9

10
        "github.com/Azure/aks-app-routing-operator/pkg/config"
11
        "github.com/Azure/aks-app-routing-operator/pkg/util"
12
        "github.com/go-logr/logr"
13
        apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
14
        "sigs.k8s.io/controller-runtime/pkg/client"
15
        "sigs.k8s.io/yaml"
16
)
17

18
var (
19
        // should match the names in root config/crd/bases directory
20
        externalDnsCrdFilename        = "approuting.kubernetes.azure.com_externaldnses.yaml"
21
        clusterExternalDnsCrdFilename = "approuting.kubernetes.azure.com_clusterexternaldnses.yaml"
22
        managedCertificateCrdFilename = "approuting.kubernetes.azure.com_managedcertificates.yaml"
23
)
24

25
// loadCRDs loads the CRDs from the specified path into the cluster
26
func loadCRDs(c client.Client, cfg *config.Config, log logr.Logger) error {
7✔
27
        if cfg == nil {
8✔
28
                return errors.New("config cannot be nil")
1✔
29
        }
1✔
30

31
        log = log.WithValues("crdPath", cfg.CrdPath)
6✔
32
        log.Info("reading crd directory")
6✔
33
        files, err := os.ReadDir(cfg.CrdPath)
6✔
34
        if err != nil {
7✔
35
                return fmt.Errorf("reading crd directory %s: %w", cfg.CrdPath, err)
1✔
36
        }
1✔
37

38
        log.Info("applying crds")
5✔
39
        for _, file := range files {
35✔
40
                if file.IsDir() {
30✔
UNCOV
41
                        continue
×
42
                }
43

44
                filename := file.Name()
30✔
45
                if !shouldLoadCRD(cfg, filename) {
40✔
46
                        continue
10✔
47
                }
48

49
                path := filepath.Join(cfg.CrdPath, filename)
20✔
50
                log := log.WithValues("path", path)
20✔
51
                log.Info("reading crd file")
20✔
52
                var content []byte
20✔
53
                content, err := os.ReadFile(path)
20✔
54
                if err != nil {
20✔
UNCOV
55
                        return fmt.Errorf("reading crd file %s: %w", path, err)
×
56
                }
×
57

58
                log.Info("unmarshalling crd file")
20✔
59
                crd := &apiextensionsv1.CustomResourceDefinition{}
20✔
60
                if err := yaml.UnmarshalStrict(content, crd); err != nil {
21✔
61
                        return fmt.Errorf("unmarshalling crd file %s: %w", path, err)
1✔
62
                }
1✔
63

64
                log.Info("upserting crd")
19✔
65
                if err := util.Upsert(context.Background(), c, crd); err != nil {
19✔
UNCOV
66
                        return fmt.Errorf("upserting crd %s: %w", crd.Name, err)
×
67
                }
×
68
        }
69

70
        log.Info("crds loaded")
4✔
71
        return nil
4✔
72
}
73

74
func shouldLoadCRD(cfg *config.Config, filename string) bool {
36✔
75
        switch filename {
36✔
76
        case externalDnsCrdFilename:
6✔
77
                return cfg.EnableGateway
6✔
78
        case clusterExternalDnsCrdFilename:
6✔
79
                return cfg.EnableGateway
6✔
80
        case managedCertificateCrdFilename: // temporary, implementation of managed certificates is in progress
4✔
81
                return false
4✔
82

83
        default:
20✔
84
                return true
20✔
85
        }
86
}
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