-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft for add an excludeAddresses option in DNSPolicy
Signed-off-by: craig <[email protected]> rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED fix lint
- Loading branch information
Showing
10 changed files
with
231 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: kuadrant.io/v1alpha1 | ||
kind: DNSPolicy | ||
metadata: | ||
name: prod-web | ||
namespace: ${DNSPOLICY_NAMESPACE} | ||
spec: | ||
targetRef: | ||
name: prod-web-istio | ||
group: gateway.networking.k8s.io | ||
kind: Gateway | ||
providerRefs: | ||
- name: aws-credentials | ||
loadBalancing: | ||
weight: 120 | ||
geo: EU | ||
defaultGeo: true | ||
excludeAddresses: | ||
- "10.89.0.0/16" | ||
- "some.local.domain" | ||
- "127.0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package multicluster_test | ||
|
||
import ( | ||
"testing" | ||
|
||
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
|
||
"github.com/kuadrant/kuadrant-operator/api/v1alpha1" | ||
"github.com/kuadrant/kuadrant-operator/pkg/multicluster" | ||
) | ||
|
||
func TestSetValidStatusAddresses(t *testing.T) { | ||
ipaddress := gatewayapiv1.IPAddressType | ||
hostaddress := gatewayapiv1.HostnameAddressType | ||
testCases := []struct { | ||
Name string | ||
Gateway *gatewayapiv1.Gateway | ||
DNSPolicy *v1alpha1.DNSPolicy | ||
Validate func(t *testing.T, g *gatewayapiv1.GatewayStatus) | ||
}{ | ||
{ | ||
Name: "ensure addresses in ingore are are removed from status", | ||
Gateway: &gatewayapiv1.Gateway{ | ||
Status: gatewayapiv1.GatewayStatus{ | ||
Addresses: []gatewayapiv1.GatewayStatusAddress{ | ||
{ | ||
Type: &ipaddress, | ||
Value: "1.1.1.1", | ||
}, | ||
{ | ||
Type: &hostaddress, | ||
Value: "example.com", | ||
}, | ||
}, | ||
}, | ||
}, | ||
DNSPolicy: &v1alpha1.DNSPolicy{ | ||
Spec: v1alpha1.DNSPolicySpec{ | ||
ExcludeAddresses: []string{ | ||
"1.1.1.1", | ||
}, | ||
}, | ||
}, | ||
Validate: func(t *testing.T, g *gatewayapiv1.GatewayStatus) { | ||
if len(g.Addresses) != 1 { | ||
t.Fatalf("expected a single address but got %v ", len(g.Addresses)) | ||
} | ||
for _, addr := range g.Addresses { | ||
if addr.Value == "1.1.1.1" { | ||
t.Fatalf("did not expect address %s to be present", "1.1.1.1") | ||
} | ||
} | ||
}, | ||
}, | ||
{ | ||
Name: "ensure all addresses if nothing ignored", | ||
Gateway: &gatewayapiv1.Gateway{ | ||
Status: gatewayapiv1.GatewayStatus{ | ||
Addresses: []gatewayapiv1.GatewayStatusAddress{ | ||
{ | ||
Type: &ipaddress, | ||
Value: "1.1.1.1", | ||
}, | ||
{ | ||
Type: &hostaddress, | ||
Value: "example.com", | ||
}, | ||
}, | ||
}, | ||
}, | ||
DNSPolicy: &v1alpha1.DNSPolicy{ | ||
Spec: v1alpha1.DNSPolicySpec{ | ||
ExcludeAddresses: []string{}, | ||
}, | ||
}, | ||
Validate: func(t *testing.T, g *gatewayapiv1.GatewayStatus) { | ||
if len(g.Addresses) != 2 { | ||
t.Fatalf("expected a both address but got %v ", len(g.Addresses)) | ||
} | ||
}, | ||
}, | ||
{ | ||
Name: "ensure addresses removed if CIDR is set and hostname", | ||
Gateway: &gatewayapiv1.Gateway{ | ||
Status: gatewayapiv1.GatewayStatus{ | ||
Addresses: []gatewayapiv1.GatewayStatusAddress{ | ||
{ | ||
Type: &ipaddress, | ||
Value: "1.1.1.1", | ||
}, | ||
{ | ||
Type: &hostaddress, | ||
Value: "example.com", | ||
}, | ||
{ | ||
Type: &ipaddress, | ||
Value: "81.17.21.22", | ||
}, | ||
}, | ||
}, | ||
}, | ||
DNSPolicy: &v1alpha1.DNSPolicy{ | ||
Spec: v1alpha1.DNSPolicySpec{ | ||
ExcludeAddresses: []string{ | ||
"1.1.0.0/16", | ||
"10.0.0.1/32", | ||
"example.com", | ||
}, | ||
}, | ||
}, | ||
Validate: func(t *testing.T, g *gatewayapiv1.GatewayStatus) { | ||
if len(g.Addresses) != 1 { | ||
t.Fatalf("expected only a single address but got %v %v ", len(g.Addresses), g.Addresses) | ||
} | ||
if g.Addresses[0].Value != "81.17.21.22" { | ||
t.Fatalf("expected the only remaining address to be 81.17.21.22 but got %s", g.Addresses[0].Value) | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
gw := multicluster.NewGatewayWrapper(tc.Gateway, "id") | ||
err := gw.SetValidStatusAddresses(tc.DNSPolicy) | ||
if err != nil { | ||
t.Fatalf("unexpected error %s", err) | ||
} | ||
tc.Validate(t, &gw.Status) | ||
}) | ||
} | ||
} |