|
7 | 7 |
|
8 | 8 | "k8s.io/apimachinery/pkg/types" |
9 | 9 | "sigs.k8s.io/controller-runtime/pkg/client" |
| 10 | + "sigs.k8s.io/controller-runtime/pkg/log" |
10 | 11 | "sigs.k8s.io/external-dns/apis/v1alpha1" |
11 | 12 | "sigs.k8s.io/external-dns/endpoint" |
12 | 13 |
|
@@ -39,15 +40,15 @@ func getDNSConfig(ctx core.Context, stack string, dnsType string) (*DNSConfig, e |
39 | 40 | return nil, err |
40 | 41 | } |
41 | 42 | if len(dnsNames) == 0 { |
42 | | - return nil, fmt.Errorf("gateway.dns.%s.dns-names is required when gateway.dns.%s.enabled is true", dnsType, dnsType) |
| 43 | + return nil, core.NewMissingSettingsError(fmt.Sprintf("gateway.dns.%s.dns-names is required when gateway.dns.%s.enabled is true", dnsType, dnsType)) |
43 | 44 | } |
44 | 45 |
|
45 | 46 | targets, err := settings.GetTrimmedStringSlice(ctx, stack, "gateway", "dns", dnsType, "targets") |
46 | 47 | if err != nil { |
47 | 48 | return nil, err |
48 | 49 | } |
49 | 50 | if len(targets) == 0 { |
50 | | - return nil, fmt.Errorf("gateway.dns.%s.targets is required when gateway.dns.%s.enabled is true", dnsType, dnsType) |
| 51 | + return nil, core.NewMissingSettingsError(fmt.Sprintf("gateway.dns.%s.targets is required when gateway.dns.%s.enabled is true", dnsType, dnsType)) |
51 | 52 | } |
52 | 53 |
|
53 | 54 | providerSpec, err := settings.GetMapOrEmpty(ctx, stack, "gateway", "dns", dnsType, "provider-specific") |
@@ -80,9 +81,12 @@ func expandDNSPattern(pattern, stack string) string { |
80 | 81 | } |
81 | 82 |
|
82 | 83 | func createDNSEndpoint(ctx core.Context, gateway v1beta1.Dependent, dnsType string, config *DNSConfig) error { |
| 84 | + logger := log.FromContext(ctx) |
83 | 85 | name := fmt.Sprintf("%s-%s", gateway.GetName(), dnsType) |
84 | 86 | stackName := gateway.GetStack() |
85 | 87 |
|
| 88 | + logger.Info("Creating DNS endpoint", "name", name, "type", dnsType, "dnsNames", config.DNSPatterns, "targets", config.Targets) |
| 89 | + |
86 | 90 | // Build endpoints array - one endpoint per DNS name |
87 | 91 | endpoints := []*endpoint.Endpoint{} |
88 | 92 | for _, dnsPattern := range config.DNSPatterns { |
@@ -173,17 +177,12 @@ func reconcileDNSEndpoints(ctx core.Context, gateway v1beta1.Dependent) error { |
173 | 177 | } |
174 | 178 |
|
175 | 179 | func deleteDNSEndpoint(ctx core.Context, namespace, name string) error { |
| 180 | + logger := log.FromContext(ctx) |
176 | 181 | dnsEndpoint := &v1alpha1.DNSEndpoint{} |
177 | 182 | dnsEndpoint.SetName(name) |
178 | 183 | dnsEndpoint.SetNamespace(namespace) |
179 | 184 |
|
180 | | - if err := ctx.GetClient().Get(ctx, types.NamespacedName{ |
181 | | - Name: name, |
182 | | - Namespace: namespace, |
183 | | - }, dnsEndpoint); err != nil { |
184 | | - // Resource doesn't exist, nothing to delete |
185 | | - return client.IgnoreNotFound(err) |
186 | | - } |
| 185 | + logger.Info("Deleting DNS endpoint if exists", "name", name, "namespace", namespace) |
187 | 186 |
|
188 | | - return ctx.GetClient().Delete(ctx, dnsEndpoint) |
| 187 | + return client.IgnoreNotFound(ctx.GetClient().Delete(ctx, dnsEndpoint)) |
189 | 188 | } |
0 commit comments