sigs.k8s.io/external-dns@v0.14.1/pkg/apis/externaldns/types_test.go (about) 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 externaldns 18 19 import ( 20 "os" 21 "regexp" 22 "strings" 23 "testing" 24 "time" 25 26 "sigs.k8s.io/external-dns/endpoint" 27 28 "github.com/sirupsen/logrus" 29 "github.com/stretchr/testify/assert" 30 "github.com/stretchr/testify/require" 31 ) 32 33 var ( 34 minimalConfig = &Config{ 35 APIServerURL: "", 36 KubeConfig: "", 37 RequestTimeout: time.Second * 30, 38 GlooNamespaces: []string{"gloo-system"}, 39 SkipperRouteGroupVersion: "zalando.org/v1", 40 Sources: []string{"service"}, 41 Namespace: "", 42 FQDNTemplate: "", 43 Compatibility: "", 44 Provider: "google", 45 GoogleProject: "", 46 GoogleBatchChangeSize: 1000, 47 GoogleBatchChangeInterval: time.Second, 48 GoogleZoneVisibility: "", 49 DomainFilter: []string{""}, 50 ExcludeDomains: []string{""}, 51 RegexDomainFilter: regexp.MustCompile(""), 52 RegexDomainExclusion: regexp.MustCompile(""), 53 ZoneNameFilter: []string{""}, 54 ZoneIDFilter: []string{""}, 55 AlibabaCloudConfigFile: "/etc/kubernetes/alibaba-cloud.json", 56 AWSZoneType: "", 57 AWSZoneTagFilter: []string{""}, 58 AWSZoneMatchParent: false, 59 AWSAssumeRole: "", 60 AWSAssumeRoleExternalID: "", 61 AWSBatchChangeSize: 1000, 62 AWSBatchChangeSizeBytes: 32000, 63 AWSBatchChangeSizeValues: 1000, 64 AWSBatchChangeInterval: time.Second, 65 AWSEvaluateTargetHealth: true, 66 AWSAPIRetries: 3, 67 AWSPreferCNAME: false, 68 AWSZoneCacheDuration: 0 * time.Second, 69 AWSSDServiceCleanup: false, 70 AWSDynamoDBTable: "external-dns", 71 AzureConfigFile: "/etc/kubernetes/azure.json", 72 AzureResourceGroup: "", 73 AzureSubscriptionID: "", 74 BluecatDNSConfiguration: "", 75 BluecatDNSServerName: "", 76 BluecatConfigFile: "/etc/kubernetes/bluecat.json", 77 BluecatDNSView: "", 78 BluecatGatewayHost: "", 79 BluecatRootZone: "", 80 BluecatDNSDeployType: defaultConfig.BluecatDNSDeployType, 81 BluecatSkipTLSVerify: false, 82 CloudflareProxied: false, 83 CloudflareDNSRecordsPerPage: 100, 84 CoreDNSPrefix: "/skydns/", 85 AkamaiServiceConsumerDomain: "", 86 AkamaiClientToken: "", 87 AkamaiClientSecret: "", 88 AkamaiAccessToken: "", 89 AkamaiEdgercPath: "", 90 AkamaiEdgercSection: "", 91 InfobloxGridHost: "", 92 InfobloxWapiPort: 443, 93 InfobloxWapiUsername: "admin", 94 InfobloxWapiPassword: "", 95 InfobloxWapiVersion: "2.3.1", 96 InfobloxView: "", 97 InfobloxSSLVerify: true, 98 InfobloxMaxResults: 0, 99 OCIConfigFile: "/etc/kubernetes/oci.yaml", 100 OCIZoneScope: "GLOBAL", 101 OCIZoneCacheDuration: 0 * time.Second, 102 InMemoryZones: []string{""}, 103 OVHEndpoint: "ovh-eu", 104 OVHApiRateLimit: 20, 105 PDNSServer: "http://localhost:8081", 106 PDNSAPIKey: "", 107 Policy: "sync", 108 Registry: "txt", 109 TXTOwnerID: "default", 110 TXTPrefix: "", 111 TXTCacheInterval: 0, 112 Interval: time.Minute, 113 MinEventSyncInterval: 5 * time.Second, 114 Once: false, 115 DryRun: false, 116 UpdateEvents: false, 117 LogFormat: "text", 118 MetricsAddress: ":7979", 119 LogLevel: logrus.InfoLevel.String(), 120 ConnectorSourceServer: "localhost:8080", 121 ExoscaleAPIEnvironment: "api", 122 ExoscaleAPIZone: "ch-gva-2", 123 ExoscaleAPIKey: "", 124 ExoscaleAPISecret: "", 125 CRDSourceAPIVersion: "externaldns.k8s.io/v1alpha1", 126 CRDSourceKind: "DNSEndpoint", 127 RcodezeroTXTEncrypt: false, 128 TransIPAccountName: "", 129 TransIPPrivateKeyFile: "", 130 DigitalOceanAPIPageSize: 50, 131 ManagedDNSRecordTypes: []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME}, 132 RFC2136BatchChangeSize: 50, 133 OCPRouterName: "default", 134 IBMCloudProxied: false, 135 IBMCloudConfigFile: "/etc/kubernetes/ibmcloud.json", 136 TencentCloudConfigFile: "/etc/kubernetes/tencent-cloud.json", 137 TencentCloudZoneType: "", 138 WebhookProviderURL: "http://localhost:8888", 139 WebhookProviderReadTimeout: 5 * time.Second, 140 WebhookProviderWriteTimeout: 10 * time.Second, 141 } 142 143 overriddenConfig = &Config{ 144 APIServerURL: "http://127.0.0.1:8080", 145 KubeConfig: "/some/path", 146 RequestTimeout: time.Second * 77, 147 GlooNamespaces: []string{"gloo-not-system", "gloo-second-system"}, 148 SkipperRouteGroupVersion: "zalando.org/v2", 149 Sources: []string{"service", "ingress", "connector"}, 150 Namespace: "namespace", 151 IgnoreHostnameAnnotation: true, 152 IgnoreIngressTLSSpec: true, 153 IgnoreIngressRulesSpec: true, 154 FQDNTemplate: "{{.Name}}.service.example.com", 155 Compatibility: "mate", 156 Provider: "google", 157 GoogleProject: "project", 158 GoogleBatchChangeSize: 100, 159 GoogleBatchChangeInterval: time.Second * 2, 160 GoogleZoneVisibility: "private", 161 DomainFilter: []string{"example.org", "company.com"}, 162 ExcludeDomains: []string{"xapi.example.org", "xapi.company.com"}, 163 RegexDomainFilter: regexp.MustCompile("(example\\.org|company\\.com)$"), 164 RegexDomainExclusion: regexp.MustCompile("xapi\\.(example\\.org|company\\.com)$"), 165 ZoneNameFilter: []string{"yapi.example.org", "yapi.company.com"}, 166 ZoneIDFilter: []string{"/hostedzone/ZTST1", "/hostedzone/ZTST2"}, 167 TargetNetFilter: []string{"10.0.0.0/9", "10.1.0.0/9"}, 168 ExcludeTargetNets: []string{"1.0.0.0/9", "1.1.0.0/9"}, 169 AlibabaCloudConfigFile: "/etc/kubernetes/alibaba-cloud.json", 170 AWSZoneType: "private", 171 AWSZoneTagFilter: []string{"tag=foo"}, 172 AWSZoneMatchParent: true, 173 AWSAssumeRole: "some-other-role", 174 AWSAssumeRoleExternalID: "pg2000", 175 AWSBatchChangeSize: 100, 176 AWSBatchChangeSizeBytes: 16000, 177 AWSBatchChangeSizeValues: 100, 178 AWSBatchChangeInterval: time.Second * 2, 179 AWSEvaluateTargetHealth: false, 180 AWSAPIRetries: 13, 181 AWSPreferCNAME: true, 182 AWSZoneCacheDuration: 10 * time.Second, 183 AWSSDServiceCleanup: true, 184 AWSDynamoDBTable: "custom-table", 185 AzureConfigFile: "azure.json", 186 AzureResourceGroup: "arg", 187 AzureSubscriptionID: "arg", 188 BluecatDNSConfiguration: "arg", 189 BluecatDNSServerName: "arg", 190 BluecatConfigFile: "bluecat.json", 191 BluecatDNSView: "arg", 192 BluecatGatewayHost: "arg", 193 BluecatRootZone: "arg", 194 BluecatDNSDeployType: "full-deploy", 195 BluecatSkipTLSVerify: true, 196 CloudflareProxied: true, 197 CloudflareDNSRecordsPerPage: 5000, 198 CoreDNSPrefix: "/coredns/", 199 AkamaiServiceConsumerDomain: "oooo-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net", 200 AkamaiClientToken: "o184671d5307a388180fbf7f11dbdf46", 201 AkamaiClientSecret: "o184671d5307a388180fbf7f11dbdf46", 202 AkamaiAccessToken: "o184671d5307a388180fbf7f11dbdf46", 203 AkamaiEdgercPath: "/home/test/.edgerc", 204 AkamaiEdgercSection: "default", 205 InfobloxGridHost: "127.0.0.1", 206 InfobloxWapiPort: 8443, 207 InfobloxWapiUsername: "infoblox", 208 InfobloxWapiPassword: "infoblox", 209 InfobloxWapiVersion: "2.6.1", 210 InfobloxView: "internal", 211 InfobloxSSLVerify: false, 212 InfobloxMaxResults: 2000, 213 OCIConfigFile: "oci.yaml", 214 OCIZoneScope: "PRIVATE", 215 OCIZoneCacheDuration: 30 * time.Second, 216 InMemoryZones: []string{"example.org", "company.com"}, 217 OVHEndpoint: "ovh-ca", 218 OVHApiRateLimit: 42, 219 PDNSServer: "http://ns.example.com:8081", 220 PDNSAPIKey: "some-secret-key", 221 PDNSSkipTLSVerify: true, 222 TLSCA: "/path/to/ca.crt", 223 TLSClientCert: "/path/to/cert.pem", 224 TLSClientCertKey: "/path/to/key.pem", 225 Policy: "upsert-only", 226 Registry: "noop", 227 TXTOwnerID: "owner-1", 228 TXTPrefix: "associated-txt-record", 229 TXTCacheInterval: 12 * time.Hour, 230 Interval: 10 * time.Minute, 231 MinEventSyncInterval: 50 * time.Second, 232 Once: true, 233 DryRun: true, 234 UpdateEvents: true, 235 LogFormat: "json", 236 MetricsAddress: "127.0.0.1:9099", 237 LogLevel: logrus.DebugLevel.String(), 238 ConnectorSourceServer: "localhost:8081", 239 ExoscaleAPIEnvironment: "api1", 240 ExoscaleAPIZone: "zone1", 241 ExoscaleAPIKey: "1", 242 ExoscaleAPISecret: "2", 243 CRDSourceAPIVersion: "test.k8s.io/v1alpha1", 244 CRDSourceKind: "Endpoint", 245 RcodezeroTXTEncrypt: true, 246 NS1Endpoint: "https://api.example.com/v1", 247 NS1IgnoreSSL: true, 248 TransIPAccountName: "transip", 249 TransIPPrivateKeyFile: "/path/to/transip.key", 250 DigitalOceanAPIPageSize: 100, 251 ManagedDNSRecordTypes: []string{endpoint.RecordTypeA, endpoint.RecordTypeAAAA, endpoint.RecordTypeCNAME, endpoint.RecordTypeNS}, 252 RFC2136BatchChangeSize: 100, 253 IBMCloudProxied: true, 254 IBMCloudConfigFile: "ibmcloud.json", 255 TencentCloudConfigFile: "tencent-cloud.json", 256 TencentCloudZoneType: "private", 257 WebhookProviderURL: "http://localhost:8888", 258 WebhookProviderReadTimeout: 5 * time.Second, 259 WebhookProviderWriteTimeout: 10 * time.Second, 260 } 261 ) 262 263 func TestParseFlags(t *testing.T) { 264 for _, ti := range []struct { 265 title string 266 args []string 267 envVars map[string]string 268 expected *Config 269 }{ 270 { 271 title: "default config with minimal flags defined", 272 args: []string{ 273 "--source=service", 274 "--provider=google", 275 "--openshift-router-name=default", 276 }, 277 envVars: map[string]string{}, 278 expected: minimalConfig, 279 }, 280 { 281 title: "override everything via flags", 282 args: []string{ 283 "--server=http://127.0.0.1:8080", 284 "--kubeconfig=/some/path", 285 "--request-timeout=77s", 286 "--gloo-namespace=gloo-not-system", 287 "--gloo-namespace=gloo-second-system", 288 "--skipper-routegroup-groupversion=zalando.org/v2", 289 "--source=service", 290 "--source=ingress", 291 "--source=connector", 292 "--namespace=namespace", 293 "--fqdn-template={{.Name}}.service.example.com", 294 "--ignore-hostname-annotation", 295 "--ignore-ingress-tls-spec", 296 "--ignore-ingress-rules-spec", 297 "--compatibility=mate", 298 "--provider=google", 299 "--google-project=project", 300 "--google-batch-change-size=100", 301 "--google-batch-change-interval=2s", 302 "--google-zone-visibility=private", 303 "--azure-config-file=azure.json", 304 "--azure-resource-group=arg", 305 "--azure-subscription-id=arg", 306 "--bluecat-dns-configuration=arg", 307 "--bluecat-config-file=bluecat.json", 308 "--bluecat-dns-view=arg", 309 "--bluecat-dns-server-name=arg", 310 "--bluecat-gateway-host=arg", 311 "--bluecat-root-zone=arg", 312 "--bluecat-dns-deploy-type=full-deploy", 313 "--bluecat-skip-tls-verify", 314 "--cloudflare-proxied", 315 "--cloudflare-dns-records-per-page=5000", 316 "--coredns-prefix=/coredns/", 317 "--akamai-serviceconsumerdomain=oooo-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net", 318 "--akamai-client-token=o184671d5307a388180fbf7f11dbdf46", 319 "--akamai-client-secret=o184671d5307a388180fbf7f11dbdf46", 320 "--akamai-access-token=o184671d5307a388180fbf7f11dbdf46", 321 "--akamai-edgerc-path=/home/test/.edgerc", 322 "--akamai-edgerc-section=default", 323 "--infoblox-grid-host=127.0.0.1", 324 "--infoblox-wapi-port=8443", 325 "--infoblox-wapi-username=infoblox", 326 "--infoblox-wapi-password=infoblox", 327 "--infoblox-wapi-version=2.6.1", 328 "--infoblox-view=internal", 329 "--infoblox-max-results=2000", 330 "--inmemory-zone=example.org", 331 "--inmemory-zone=company.com", 332 "--ovh-endpoint=ovh-ca", 333 "--ovh-api-rate-limit=42", 334 "--pdns-server=http://ns.example.com:8081", 335 "--pdns-api-key=some-secret-key", 336 "--pdns-skip-tls-verify", 337 "--oci-config-file=oci.yaml", 338 "--oci-zone-scope=PRIVATE", 339 "--oci-zones-cache-duration=30s", 340 "--tls-ca=/path/to/ca.crt", 341 "--tls-client-cert=/path/to/cert.pem", 342 "--tls-client-cert-key=/path/to/key.pem", 343 "--no-infoblox-ssl-verify", 344 "--domain-filter=example.org", 345 "--domain-filter=company.com", 346 "--exclude-domains=xapi.example.org", 347 "--exclude-domains=xapi.company.com", 348 "--regex-domain-filter=(example\\.org|company\\.com)$", 349 "--regex-domain-exclusion=xapi\\.(example\\.org|company\\.com)$", 350 "--zone-name-filter=yapi.example.org", 351 "--zone-name-filter=yapi.company.com", 352 "--zone-id-filter=/hostedzone/ZTST1", 353 "--zone-id-filter=/hostedzone/ZTST2", 354 "--target-net-filter=10.0.0.0/9", 355 "--target-net-filter=10.1.0.0/9", 356 "--exclude-target-net=1.0.0.0/9", 357 "--exclude-target-net=1.1.0.0/9", 358 "--aws-zone-type=private", 359 "--aws-zone-tags=tag=foo", 360 "--aws-zone-match-parent", 361 "--aws-assume-role=some-other-role", 362 "--aws-assume-role-external-id=pg2000", 363 "--aws-batch-change-size=100", 364 "--aws-batch-change-size-bytes=16000", 365 "--aws-batch-change-size-values=100", 366 "--aws-batch-change-interval=2s", 367 "--aws-api-retries=13", 368 "--aws-prefer-cname", 369 "--aws-zones-cache-duration=10s", 370 "--aws-sd-service-cleanup", 371 "--no-aws-evaluate-target-health", 372 "--policy=upsert-only", 373 "--registry=noop", 374 "--txt-owner-id=owner-1", 375 "--txt-prefix=associated-txt-record", 376 "--txt-cache-interval=12h", 377 "--dynamodb-table=custom-table", 378 "--interval=10m", 379 "--min-event-sync-interval=50s", 380 "--once", 381 "--dry-run", 382 "--events", 383 "--log-format=json", 384 "--metrics-address=127.0.0.1:9099", 385 "--log-level=debug", 386 "--connector-source-server=localhost:8081", 387 "--exoscale-apienv=api1", 388 "--exoscale-apizone=zone1", 389 "--exoscale-apikey=1", 390 "--exoscale-apisecret=2", 391 "--crd-source-apiversion=test.k8s.io/v1alpha1", 392 "--crd-source-kind=Endpoint", 393 "--rcodezero-txt-encrypt", 394 "--ns1-endpoint=https://api.example.com/v1", 395 "--ns1-ignoressl", 396 "--transip-account=transip", 397 "--transip-keyfile=/path/to/transip.key", 398 "--digitalocean-api-page-size=100", 399 "--managed-record-types=A", 400 "--managed-record-types=AAAA", 401 "--managed-record-types=CNAME", 402 "--managed-record-types=NS", 403 "--rfc2136-batch-change-size=100", 404 "--ibmcloud-proxied", 405 "--ibmcloud-config-file=ibmcloud.json", 406 "--tencent-cloud-config-file=tencent-cloud.json", 407 "--tencent-cloud-zone-type=private", 408 }, 409 envVars: map[string]string{}, 410 expected: overriddenConfig, 411 }, 412 { 413 title: "override everything via environment variables", 414 args: []string{}, 415 envVars: map[string]string{ 416 "EXTERNAL_DNS_SERVER": "http://127.0.0.1:8080", 417 "EXTERNAL_DNS_KUBECONFIG": "/some/path", 418 "EXTERNAL_DNS_REQUEST_TIMEOUT": "77s", 419 "EXTERNAL_DNS_CONTOUR_LOAD_BALANCER": "heptio-contour-other/contour-other", 420 "EXTERNAL_DNS_GLOO_NAMESPACE": "gloo-not-system\ngloo-second-system", 421 "EXTERNAL_DNS_SKIPPER_ROUTEGROUP_GROUPVERSION": "zalando.org/v2", 422 "EXTERNAL_DNS_SOURCE": "service\ningress\nconnector", 423 "EXTERNAL_DNS_NAMESPACE": "namespace", 424 "EXTERNAL_DNS_FQDN_TEMPLATE": "{{.Name}}.service.example.com", 425 "EXTERNAL_DNS_IGNORE_HOSTNAME_ANNOTATION": "1", 426 "EXTERNAL_DNS_IGNORE_INGRESS_TLS_SPEC": "1", 427 "EXTERNAL_DNS_IGNORE_INGRESS_RULES_SPEC": "1", 428 "EXTERNAL_DNS_COMPATIBILITY": "mate", 429 "EXTERNAL_DNS_PROVIDER": "google", 430 "EXTERNAL_DNS_GOOGLE_PROJECT": "project", 431 "EXTERNAL_DNS_GOOGLE_BATCH_CHANGE_SIZE": "100", 432 "EXTERNAL_DNS_GOOGLE_BATCH_CHANGE_INTERVAL": "2s", 433 "EXTERNAL_DNS_GOOGLE_ZONE_VISIBILITY": "private", 434 "EXTERNAL_DNS_AZURE_CONFIG_FILE": "azure.json", 435 "EXTERNAL_DNS_AZURE_RESOURCE_GROUP": "arg", 436 "EXTERNAL_DNS_AZURE_SUBSCRIPTION_ID": "arg", 437 "EXTERNAL_DNS_BLUECAT_DNS_CONFIGURATION": "arg", 438 "EXTERNAL_DNS_BLUECAT_DNS_SERVER_NAME": "arg", 439 "EXTERNAL_DNS_BLUECAT_DNS_DEPLOY_TYPE": "full-deploy", 440 "EXTERNAL_DNS_BLUECAT_CONFIG_FILE": "bluecat.json", 441 "EXTERNAL_DNS_BLUECAT_DNS_VIEW": "arg", 442 "EXTERNAL_DNS_BLUECAT_GATEWAY_HOST": "arg", 443 "EXTERNAL_DNS_BLUECAT_ROOT_ZONE": "arg", 444 "EXTERNAL_DNS_BLUECAT_SKIP_TLS_VERIFY": "1", 445 "EXTERNAL_DNS_CLOUDFLARE_PROXIED": "1", 446 "EXTERNAL_DNS_CLOUDFLARE_DNS_RECORDS_PER_PAGE": "5000", 447 "EXTERNAL_DNS_COREDNS_PREFIX": "/coredns/", 448 "EXTERNAL_DNS_AKAMAI_SERVICECONSUMERDOMAIN": "oooo-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx.luna.akamaiapis.net", 449 "EXTERNAL_DNS_AKAMAI_CLIENT_TOKEN": "o184671d5307a388180fbf7f11dbdf46", 450 "EXTERNAL_DNS_AKAMAI_CLIENT_SECRET": "o184671d5307a388180fbf7f11dbdf46", 451 "EXTERNAL_DNS_AKAMAI_ACCESS_TOKEN": "o184671d5307a388180fbf7f11dbdf46", 452 "EXTERNAL_DNS_AKAMAI_EDGERC_PATH": "/home/test/.edgerc", 453 "EXTERNAL_DNS_AKAMAI_EDGERC_SECTION": "default", 454 "EXTERNAL_DNS_INFOBLOX_GRID_HOST": "127.0.0.1", 455 "EXTERNAL_DNS_INFOBLOX_WAPI_PORT": "8443", 456 "EXTERNAL_DNS_INFOBLOX_WAPI_USERNAME": "infoblox", 457 "EXTERNAL_DNS_INFOBLOX_WAPI_PASSWORD": "infoblox", 458 "EXTERNAL_DNS_INFOBLOX_WAPI_VERSION": "2.6.1", 459 "EXTERNAL_DNS_INFOBLOX_VIEW": "internal", 460 "EXTERNAL_DNS_INFOBLOX_SSL_VERIFY": "0", 461 "EXTERNAL_DNS_INFOBLOX_MAX_RESULTS": "2000", 462 "EXTERNAL_DNS_OCI_CONFIG_FILE": "oci.yaml", 463 "EXTERNAL_DNS_OCI_ZONE_SCOPE": "PRIVATE", 464 "EXTERNAL_DNS_OCI_ZONES_CACHE_DURATION": "30s", 465 "EXTERNAL_DNS_INMEMORY_ZONE": "example.org\ncompany.com", 466 "EXTERNAL_DNS_OVH_ENDPOINT": "ovh-ca", 467 "EXTERNAL_DNS_OVH_API_RATE_LIMIT": "42", 468 "EXTERNAL_DNS_DOMAIN_FILTER": "example.org\ncompany.com", 469 "EXTERNAL_DNS_EXCLUDE_DOMAINS": "xapi.example.org\nxapi.company.com", 470 "EXTERNAL_DNS_REGEX_DOMAIN_FILTER": "(example\\.org|company\\.com)$", 471 "EXTERNAL_DNS_REGEX_DOMAIN_EXCLUSION": "xapi\\.(example\\.org|company\\.com)$", 472 "EXTERNAL_DNS_TARGET_NET_FILTER": "10.0.0.0/9\n10.1.0.0/9", 473 "EXTERNAL_DNS_EXCLUDE_TARGET_NET": "1.0.0.0/9\n1.1.0.0/9", 474 "EXTERNAL_DNS_PDNS_SERVER": "http://ns.example.com:8081", 475 "EXTERNAL_DNS_PDNS_API_KEY": "some-secret-key", 476 "EXTERNAL_DNS_PDNS_SKIP_TLS_VERIFY": "1", 477 "EXTERNAL_DNS_RDNS_ROOT_DOMAIN": "lb.rancher.cloud", 478 "EXTERNAL_DNS_TLS_CA": "/path/to/ca.crt", 479 "EXTERNAL_DNS_TLS_CLIENT_CERT": "/path/to/cert.pem", 480 "EXTERNAL_DNS_TLS_CLIENT_CERT_KEY": "/path/to/key.pem", 481 "EXTERNAL_DNS_ZONE_NAME_FILTER": "yapi.example.org\nyapi.company.com", 482 "EXTERNAL_DNS_ZONE_ID_FILTER": "/hostedzone/ZTST1\n/hostedzone/ZTST2", 483 "EXTERNAL_DNS_AWS_ZONE_TYPE": "private", 484 "EXTERNAL_DNS_AWS_ZONE_TAGS": "tag=foo", 485 "EXTERNAL_DNS_AWS_ZONE_MATCH_PARENT": "true", 486 "EXTERNAL_DNS_AWS_ASSUME_ROLE": "some-other-role", 487 "EXTERNAL_DNS_AWS_ASSUME_ROLE_EXTERNAL_ID": "pg2000", 488 "EXTERNAL_DNS_AWS_BATCH_CHANGE_SIZE": "100", 489 "EXTERNAL_DNS_AWS_BATCH_CHANGE_SIZE_BYTES": "16000", 490 "EXTERNAL_DNS_AWS_BATCH_CHANGE_SIZE_VALUES": "100", 491 "EXTERNAL_DNS_AWS_BATCH_CHANGE_INTERVAL": "2s", 492 "EXTERNAL_DNS_AWS_EVALUATE_TARGET_HEALTH": "0", 493 "EXTERNAL_DNS_AWS_API_RETRIES": "13", 494 "EXTERNAL_DNS_AWS_PREFER_CNAME": "true", 495 "EXTERNAL_DNS_AWS_ZONES_CACHE_DURATION": "10s", 496 "EXTERNAL_DNS_AWS_SD_SERVICE_CLEANUP": "true", 497 "EXTERNAL_DNS_DYNAMODB_TABLE": "custom-table", 498 "EXTERNAL_DNS_POLICY": "upsert-only", 499 "EXTERNAL_DNS_REGISTRY": "noop", 500 "EXTERNAL_DNS_TXT_OWNER_ID": "owner-1", 501 "EXTERNAL_DNS_TXT_PREFIX": "associated-txt-record", 502 "EXTERNAL_DNS_TXT_CACHE_INTERVAL": "12h", 503 "EXTERNAL_DNS_INTERVAL": "10m", 504 "EXTERNAL_DNS_MIN_EVENT_SYNC_INTERVAL": "50s", 505 "EXTERNAL_DNS_ONCE": "1", 506 "EXTERNAL_DNS_DRY_RUN": "1", 507 "EXTERNAL_DNS_EVENTS": "1", 508 "EXTERNAL_DNS_LOG_FORMAT": "json", 509 "EXTERNAL_DNS_METRICS_ADDRESS": "127.0.0.1:9099", 510 "EXTERNAL_DNS_LOG_LEVEL": "debug", 511 "EXTERNAL_DNS_CONNECTOR_SOURCE_SERVER": "localhost:8081", 512 "EXTERNAL_DNS_EXOSCALE_APIENV": "api1", 513 "EXTERNAL_DNS_EXOSCALE_APIZONE": "zone1", 514 "EXTERNAL_DNS_EXOSCALE_APIKEY": "1", 515 "EXTERNAL_DNS_EXOSCALE_APISECRET": "2", 516 "EXTERNAL_DNS_CRD_SOURCE_APIVERSION": "test.k8s.io/v1alpha1", 517 "EXTERNAL_DNS_CRD_SOURCE_KIND": "Endpoint", 518 "EXTERNAL_DNS_RCODEZERO_TXT_ENCRYPT": "1", 519 "EXTERNAL_DNS_NS1_ENDPOINT": "https://api.example.com/v1", 520 "EXTERNAL_DNS_NS1_IGNORESSL": "1", 521 "EXTERNAL_DNS_TRANSIP_ACCOUNT": "transip", 522 "EXTERNAL_DNS_TRANSIP_KEYFILE": "/path/to/transip.key", 523 "EXTERNAL_DNS_DIGITALOCEAN_API_PAGE_SIZE": "100", 524 "EXTERNAL_DNS_MANAGED_RECORD_TYPES": "A\nAAAA\nCNAME\nNS", 525 "EXTERNAL_DNS_RFC2136_BATCH_CHANGE_SIZE": "100", 526 "EXTERNAL_DNS_IBMCLOUD_PROXIED": "1", 527 "EXTERNAL_DNS_IBMCLOUD_CONFIG_FILE": "ibmcloud.json", 528 "EXTERNAL_DNS_TENCENT_CLOUD_CONFIG_FILE": "tencent-cloud.json", 529 "EXTERNAL_DNS_TENCENT_CLOUD_ZONE_TYPE": "private", 530 }, 531 expected: overriddenConfig, 532 }, 533 } { 534 t.Run(ti.title, func(t *testing.T) { 535 originalEnv := setEnv(t, ti.envVars) 536 defer func() { restoreEnv(t, originalEnv) }() 537 538 cfg := NewConfig() 539 require.NoError(t, cfg.ParseFlags(ti.args)) 540 assert.Equal(t, ti.expected, cfg) 541 }) 542 } 543 } 544 545 // helper functions 546 547 func setEnv(t *testing.T, env map[string]string) map[string]string { 548 originalEnv := map[string]string{} 549 550 for k, v := range env { 551 originalEnv[k] = os.Getenv(k) 552 require.NoError(t, os.Setenv(k, v)) 553 } 554 555 return originalEnv 556 } 557 558 func restoreEnv(t *testing.T, originalEnv map[string]string) { 559 for k, v := range originalEnv { 560 require.NoError(t, os.Setenv(k, v)) 561 } 562 } 563 564 func TestPasswordsNotLogged(t *testing.T) { 565 cfg := Config{ 566 DynPassword: "dyn-pass", 567 InfobloxWapiPassword: "infoblox-pass", 568 PDNSAPIKey: "pdns-api-key", 569 RFC2136TSIGSecret: "tsig-secret", 570 } 571 572 s := cfg.String() 573 574 assert.False(t, strings.Contains(s, "dyn-pass")) 575 assert.False(t, strings.Contains(s, "infoblox-pass")) 576 assert.False(t, strings.Contains(s, "pdns-api-key")) 577 assert.False(t, strings.Contains(s, "tsig-secret")) 578 }