Skip to content

Commit

Permalink
Merge pull request #967 from Miciah/OCPBUGS-15978-check-public-DNS-zo…
Browse files Browse the repository at this point in the history
…ne-when-reporting-status

OCPBUGS-15978: Check public DNS zone when reporting status
  • Loading branch information
openshift-merge-robot committed Aug 16, 2023
2 parents be01a22 + 5578044 commit cd97771
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
26 changes: 15 additions & 11 deletions pkg/operator/controller/ingress/status.go
Expand Up @@ -1059,19 +1059,23 @@ func computeDNSStatus(ic *operatorv1.IngressController, wildcardRecord *iov1.DNS

// checkZoneInConfig - private utility to check for a zone in the current config
func checkZoneInConfig(dnsConfig *configv1.DNS, zone configv1.DNSZone) bool {
// check PrivateZone settings only
// check for private zone ID
if dnsConfig.Spec.PrivateZone != nil && dnsConfig.Spec.PrivateZone.ID != "" && zone.ID != "" {
if dnsConfig.Spec.PrivateZone.ID == zone.ID {
return true
}
return zonesMatch(&zone, dnsConfig.Spec.PublicZone) || zonesMatch(&zone, dnsConfig.Spec.PrivateZone)
}

// zonesMatch returns a Boolean value indicating whether two DNS zones have the
// matching ID or "Name" tag. If either or both zones are nil, this function
// returns false.
func zonesMatch(a, b *configv1.DNSZone) bool {
if a == nil || b == nil {
return false
}

// check for private zone Tags
if dnsConfig.Spec.PrivateZone != nil && dnsConfig.Spec.PrivateZone.Tags["Name"] != "" && zone.Tags["Name"] != "" {
if dnsConfig.Spec.PrivateZone.Tags["Name"] == zone.Tags["Name"] {
return true
}
if a.ID != "" && b.ID != "" && a.ID == b.ID {
return true
}

if a.Tags["Name"] != "" && b.Tags["Name"] != "" && a.Tags["Name"] == b.Tags["Name"] {
return true
}

return false
Expand Down
22 changes: 14 additions & 8 deletions pkg/operator/controller/ingress/status_test.go
Expand Up @@ -2128,56 +2128,56 @@ func Test_checkZoneInConfig(t *testing.T) {
in, zone, zoneType string
}{
{
description: "[PrivateZone] empty strings (should fail)",
description: "empty strings (should fail)",
expected: false,
in: "",
zone: "",
zoneType: "ID",
},
{
description: "[PrivateZone] zone.ID empty string (should fail)",
description: "zone.ID empty string (should fail)",
expected: false,
in: "test",
zone: "",
zoneType: "ID",
},
{
description: "[PrivateZone] zone.ID with value (not equal should fail)",
description: "zone.ID with value (not equal should fail)",
expected: false,
in: "test",
zone: "notest",
zoneType: "ID",
},
{
description: "[PrivateZone] zone.ID with value (equal should pass)",
description: "zone.ID with value (equal should pass)",
expected: true,
in: "test",
zone: "test",
zoneType: "ID",
},
{
description: "[PrivateZone] empty strings (should fail)",
description: "empty strings (should fail)",
expected: false,
in: "",
zone: "",
zoneType: "TAG",
},
{
description: "[PrivateZone] zone.Tags['Name'] empty string (should fail)",
description: "zone.Tags['Name'] empty string (should fail)",
expected: false,
in: "test",
zone: "",
zoneType: "TAG",
},
{
description: "[PrivateZone] zone.Tags['Name'] with value (not equal should fail)",
description: "zone.Tags['Name'] with value (not equal should fail)",
expected: false,
in: "test",
zone: "notest",
zoneType: "TAG",
},
{
description: "[PrivateZone] zone.tags['Name'] with value (equal should pass)",
description: "zone.tags['Name'] with value (equal should pass)",
expected: true,
in: "test",
zone: "test",
Expand All @@ -2202,6 +2202,12 @@ func Test_checkZoneInConfig(t *testing.T) {
if actual != test.expected {
t.Errorf("expected:%v actual:%v\n", test.expected, actual)
}
dnsSpec = configv1.DNSSpec{PublicZone: z}
dnsConfig = &configv1.DNS{Spec: dnsSpec}
actual = checkZoneInConfig(dnsConfig, dnsZone)
if actual != test.expected {
t.Errorf("expected:%v actual:%v\n", test.expected, actual)
}
})
}
}
Expand Down

0 comments on commit cd97771

Please sign in to comment.