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

kubernetes-sigs / external-dns / 15160711236

21 May 2025 11:14AM UTC coverage: 73.785% (-0.002%) from 73.787%
15160711236

push

github

web-flow
chore(codebase): enable errorlint (#5439)

* chore(codebase): enable errorlint

* chore(codebase): enable errorlint

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

---------

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

3 of 36 new or added lines in 14 files covered. (8.33%)

1 existing line in 1 file now uncovered.

15019 of 20355 relevant lines covered (73.79%)

693.08 hits per line

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

75.0
/source/source.go
1
/*
2
Copyright 2017 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package source
18

19
import (
20
        "context"
21
        "fmt"
22
        "reflect"
23
        "time"
24

25
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
        "k8s.io/apimachinery/pkg/labels"
27
        "k8s.io/apimachinery/pkg/runtime"
28
        "k8s.io/apimachinery/pkg/runtime/schema"
29

30
        "sigs.k8s.io/external-dns/endpoint"
31
        "sigs.k8s.io/external-dns/source/annotations"
32
)
33

34
const (
35
        controllerAnnotationKey       = annotations.ControllerKey
36
        hostnameAnnotationKey         = annotations.HostnameKey
37
        accessAnnotationKey           = annotations.AccessKey
38
        endpointsTypeAnnotationKey    = annotations.EndpointsTypeKey
39
        targetAnnotationKey           = annotations.TargetKey
40
        ttlAnnotationKey              = annotations.TtlKey
41
        aliasAnnotationKey            = annotations.AliasKey
42
        ingressHostnameSourceKey      = annotations.IngressHostnameSourceKey
43
        controllerAnnotationValue     = annotations.ControllerValue
44
        internalHostnameAnnotationKey = annotations.InternalHostnameKey
45

46
        EndpointsTypeNodeExternalIP = "NodeExternalIP"
47
        EndpointsTypeHostIP         = "HostIP"
48
)
49

50
// Source defines the interface Endpoint sources should implement.
51
type Source interface {
52
        Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error)
53
        // AddEventHandler adds an event handler that should be triggered if something in source changes
54
        AddEventHandler(context.Context, func())
55
}
56

57
type kubeObject interface {
58
        runtime.Object
59
        metav1.Object
60
}
61

62
func getAccessFromAnnotations(input map[string]string) string {
9✔
63
        return input[accessAnnotationKey]
9✔
64
}
9✔
65

66
func getEndpointsTypeFromAnnotations(annotations map[string]string) string {
26✔
67
        return annotations[endpointsTypeAnnotationKey]
26✔
68
}
26✔
69

70
func getLabelSelector(annotationFilter string) (labels.Selector, error) {
127✔
71
        labelSelector, err := metav1.ParseToLabelSelector(annotationFilter)
127✔
72
        if err != nil {
128✔
73
                return nil, err
1✔
74
        }
1✔
75
        return metav1.LabelSelectorAsSelector(labelSelector)
126✔
76
}
77

78
func matchLabelSelector(selector labels.Selector, srcAnnotations map[string]string) bool {
18✔
79
        return selector.Matches(labels.Set(srcAnnotations))
18✔
80
}
18✔
81

82
type eventHandlerFunc func()
83

84
func (fn eventHandlerFunc) OnAdd(obj interface{}, isInInitialList bool) { fn() }
×
85
func (fn eventHandlerFunc) OnUpdate(oldObj, newObj interface{})         { fn() }
×
86
func (fn eventHandlerFunc) OnDelete(obj interface{})                    { fn() }
×
87

88
type informerFactory interface {
89
        WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
90
}
91

92
func waitForCacheSync(ctx context.Context, factory informerFactory) error {
514✔
93
        ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
514✔
94
        defer cancel()
514✔
95
        for typ, done := range factory.WaitForCacheSync(ctx.Done()) {
1,496✔
96
                if !done {
984✔
97
                        select {
2✔
98
                        case <-ctx.Done():
×
NEW
99
                                return fmt.Errorf("failed to sync %v: %w", typ, ctx.Err())
×
100
                        default:
2✔
101
                                return fmt.Errorf("failed to sync %v", typ)
2✔
102
                        }
103
                }
104
        }
105
        return nil
512✔
106
}
107

108
type dynamicInformerFactory interface {
109
        WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool
110
}
111

112
func waitForDynamicCacheSync(ctx context.Context, factory dynamicInformerFactory) error {
115✔
113
        ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
115✔
114
        defer cancel()
115✔
115
        for typ, done := range factory.WaitForCacheSync(ctx.Done()) {
409✔
116
                if !done {
294✔
117
                        select {
×
118
                        case <-ctx.Done():
×
NEW
119
                                return fmt.Errorf("failed to sync %v: %w", typ, ctx.Err())
×
120
                        default:
×
121
                                return fmt.Errorf("failed to sync %v", typ)
×
122
                        }
123
                }
124
        }
125
        return nil
115✔
126
}
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