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

Azure / aks-app-routing-operator / 22185616992

19 Feb 2026 02:21PM UTC coverage: 79.077% (-0.005%) from 79.082%
22185616992

push

github

OliverMKing
add msi externaldns e2e test

4286 of 5420 relevant lines covered (79.08%)

24.39 hits per line

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

95.83
/pkg/controller/dns/util.go
1
package dns
2

3
import (
4
        "context"
5
        "strings"
6

7
        "github.com/Azure/aks-app-routing-operator/api/v1alpha1"
8
        "github.com/Azure/aks-app-routing-operator/pkg/config"
9
        "github.com/Azure/aks-app-routing-operator/pkg/manifests"
10
        "github.com/Azure/aks-app-routing-operator/pkg/util"
11
        "github.com/hashicorp/go-multierror"
12
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
        "sigs.k8s.io/controller-runtime/pkg/client"
14
)
15

16
type ExternalDNSCRDConfiguration interface {
17
        GetTenantId() *string
18
        GetInputServiceAccount() string
19
        GetResourceNamespace() string
20
        GetInputResourceName() string
21
        GetResourceTypes() []string
22
        GetDnsZoneresourceIDs() []string
23
        GetFilters() *v1alpha1.ExternalDNSFilters
24
        GetNamespaced() bool
25
        GetIdentity() v1alpha1.ExternalDNSIdentity
26
        client.Object
27
}
28

29
func buildInputDNSConfig(e ExternalDNSCRDConfiguration, config *config.Config) manifests.InputExternalDNSConfig {
17✔
30
        identity := e.GetIdentity()
17✔
31

17✔
32
        // Determine identity type
17✔
33
        var identityType manifests.IdentityType
17✔
34
        var clientId string
17✔
35
        var serviceAccount string
17✔
36

17✔
37
        switch identity.Type {
17✔
38
        case v1alpha1.IdentityTypeManagedIdentity:
×
39
                identityType = manifests.IdentityTypeMSI
×
40
                clientId = identity.ClientID
×
41
        default: // workloadIdentity is the default
17✔
42
                identityType = manifests.IdentityTypeWorkloadIdentity
17✔
43
                serviceAccount = identity.ServiceAccount
17✔
44
        }
45

46
        ret := manifests.InputExternalDNSConfig{
17✔
47
                IdentityType:        identityType,
17✔
48
                ClientId:            clientId,
17✔
49
                InputServiceAccount: serviceAccount,
17✔
50
                Namespace:           e.GetResourceNamespace(),
17✔
51
                InputResourceName:   e.GetInputResourceName(),
17✔
52
                ResourceTypes:       extractResourceTypes(e.GetResourceTypes()),
17✔
53
                DnsZoneresourceIDs:  e.GetDnsZoneresourceIDs(),
17✔
54
                Filters:             e.GetFilters(),
17✔
55
                IsNamespaced:        e.GetNamespaced(),
17✔
56
                UID:                 string(e.GetUID()),
17✔
57
        }
17✔
58

17✔
59
        switch e.GetTenantId() {
17✔
60
        case nil:
4✔
61
                ret.TenantId = config.TenantID
4✔
62
        default:
13✔
63
                ret.TenantId = *e.GetTenantId()
13✔
64
        }
65

66
        return ret
17✔
67
}
68

69
func extractResourceTypes(resourceTypes []string) map[manifests.ResourceType]struct{} {
20✔
70
        ret := map[manifests.ResourceType]struct{}{}
20✔
71
        for _, rt := range resourceTypes {
59✔
72
                if strings.EqualFold(rt, manifests.ResourceTypeIngress.String()) {
58✔
73
                        ret[manifests.ResourceTypeIngress] = struct{}{}
19✔
74
                }
19✔
75
                if strings.EqualFold(rt, manifests.ResourceTypeGateway.String()) {
58✔
76
                        ret[manifests.ResourceTypeGateway] = struct{}{}
19✔
77
                }
19✔
78
        }
79

80
        return ret
20✔
81
}
82

83
func generateManifestsConf(config *config.Config, obj ExternalDNSCRDConfiguration) (*manifests.ExternalDnsConfig, error) {
15✔
84
        inputDNSConf := buildInputDNSConfig(obj, config)
15✔
85
        manifestsConf, err := manifests.NewExternalDNSConfig(config, inputDNSConf)
15✔
86
        if err != nil {
17✔
87
                return nil, util.NewUserError(err, "failed to generate ExternalDNS resources: "+err.Error())
2✔
88
        }
2✔
89

90
        return manifestsConf, nil
13✔
91
}
92

93
func deployExternalDNSResources(ctx context.Context, client client.Client, manifestsConf *manifests.ExternalDnsConfig, owners []metav1.OwnerReference) error {
11✔
94
        // create the ExternalDNS resources
11✔
95
        multiError := &multierror.Error{}
11✔
96

11✔
97
        for _, resource := range manifestsConf.Resources() {
88✔
98
                if resource.GetObjectKind().GroupVersionKind().Kind != "Namespace" { // don't want to set owner references in case we're generating the ns
143✔
99
                        resource.SetOwnerReferences(owners)
66✔
100
                }
66✔
101
                currentResourceErr := util.Upsert(ctx, client, resource)
77✔
102
                multiError = multierror.Append(multiError, currentResourceErr)
77✔
103
        }
104

105
        return multiError.ErrorOrNil()
11✔
106
}
107

108
// verifyIdentity verifies that the identity configuration is valid for the ExternalDNS resource.
109
// For workload identity, it validates that the service account exists and has the required annotation.
110
// For managed identity, no additional verification is needed as the clientID is validated by CRD schema.
111
func verifyIdentity(ctx context.Context, k8sclient client.Client, obj ExternalDNSCRDConfiguration) error {
22✔
112
        identity := obj.GetIdentity()
22✔
113

22✔
114
        // For workload identity (or default/empty which defaults to workload identity),
22✔
115
        // verify the service account exists and has the required annotation
22✔
116
        if identity.Type != v1alpha1.IdentityTypeManagedIdentity {
43✔
117
                _, err := util.GetServiceAccountWorkloadIdentityClientId(ctx, k8sclient, identity.ServiceAccount, obj.GetResourceNamespace())
21✔
118
                return err
21✔
119
        }
21✔
120

121
        return nil
1✔
122
}
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