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

kubernetes-sigs / external-dns / 14989750420

13 May 2025 06:27AM UTC coverage: 72.931% (+0.06%) from 72.867%
14989750420

Pull #5304

github

ivankatliarchuk
chore(source): code cleanup

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
Pull Request #5304: chore(source): code cleanup

323 of 333 new or added lines in 23 files covered. (97.0%)

1 existing line in 1 file now uncovered.

14905 of 20437 relevant lines covered (72.93%)

690.06 hits per line

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

92.86
/source/utils.go
1
/*
2
Copyright 2025 The Kubernetes Authors.
3
Licensed under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License.
5
You may obtain a copy of the License at
6
    http://www.apache.org/licenses/LICENSE-2.0
7
Unless required by applicable law or agreed to in writing, software
8
distributed under the License is distributed on an "AS IS" BASIS,
9
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
See the License for the specific language governing permissions and
11
limitations under the License.
12
*/
13

14
package source
15

16
import (
17
        "fmt"
18
        "net/netip"
19
        "strings"
20

21
        "sigs.k8s.io/external-dns/endpoint"
22
)
23

24
// suitableType returns the DNS resource record type suitable for the target.
25
// In this case type A/AAAA for IPs and type CNAME for everything else.
26
func suitableType(target string) string {
818✔
27
        netIP, err := netip.ParseAddr(target)
818✔
28
        if err != nil {
1,060✔
29
                return endpoint.RecordTypeCNAME
242✔
30
        }
242✔
31
        switch {
576✔
32
        case netIP.Is4():
464✔
33
                return endpoint.RecordTypeA
464✔
34
        case netIP.Is6():
112✔
35
                return endpoint.RecordTypeAAAA
112✔
NEW
36
        default:
×
NEW
37
                return endpoint.RecordTypeCNAME
×
38
        }
39
}
40

41
// ParseIngress parses an ingress string in the format "namespace/name" or "name".
42
// It returns the namespace and name extracted from the string, or an error if the format is invalid.
43
// If the namespace is not provided, it defaults to an empty string.
44
func ParseIngress(ingress string) (namespace, name string, err error) {
17✔
45
        parts := strings.Split(ingress, "/")
17✔
46
        if len(parts) == 2 {
22✔
47
                namespace, name = parts[0], parts[1]
5✔
48
        } else if len(parts) == 1 {
28✔
49
                name = parts[0]
11✔
50
        } else {
12✔
51
                err = fmt.Errorf("invalid ingress name (name or namespace/name) found %q", ingress)
1✔
52
        }
1✔
53

54
        return
17✔
55
}
56

57
// MatchesServiceSelector checks if all key-value pairs in the selector map
58
// are present and match the corresponding key-value pairs in the svcSelector map.
59
// It returns true if all pairs match, otherwise it returns false.
60
func MatchesServiceSelector(selector, svcSelector map[string]string) bool {
39✔
61
        for k, v := range selector {
50✔
62
                if lbl, ok := svcSelector[k]; !ok || lbl != v {
15✔
63
                        return false
4✔
64
                }
4✔
65
        }
66
        return true
35✔
67
}
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