Skip to content

Commit

Permalink
change ipv4ip to ipv4
Browse files Browse the repository at this point in the history
  • Loading branch information
j1m-ryan committed Sep 10, 2024
1 parent 5238930 commit 9932dd4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions charts/nginx-ingress/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -995,15 +995,15 @@
"dns-tcp"
]
},
"ipv4ip": {
"ipv4": {
"type": "string",
"default": "",
"title": "The ipv4 ip",
"examples": [
"127.0.0.1"
]
},
"ipv6ip": {
"ipv6": {
"type": "string",
"default": "",
"title": "The ipv6 ip",
Expand Down
12 changes: 6 additions & 6 deletions internal/k8s/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ func (vsc *VirtualServerConfiguration) IsEqual(resource Resource) bool {
// TransportServerConfiguration holds a TransportServer resource.
type TransportServerConfiguration struct {
ListenerPort int
IPv4IP string
IPv6IP string
IPv4 string
IPv6 string
TransportServer *conf_v1.TransportServer
Warnings []string
}
Expand Down Expand Up @@ -797,8 +797,8 @@ func (c *Configuration) buildListenersAndTSConfigurations() (newListeners map[st
}

tsc.ListenerPort = listener.Port
tsc.IPv4IP = listener.IPv4IP
tsc.IPv6IP = listener.IPv6IP
tsc.IPv4 = listener.IPv4
tsc.IPv6 = listener.IPv6

holder, exists := newListeners[listener.Name]
if !exists {
Expand Down Expand Up @@ -828,8 +828,8 @@ func (c *Configuration) buildListenersForVSConfiguration(vsc *VirtualServerConfi
assignListener := func(listenerName string, isSSL bool, port *int, ipv4 *string, ipv6 *string) {
if gcListener, ok := c.listenerMap[listenerName]; ok && gcListener.Protocol == conf_v1.HTTPProtocol && gcListener.Ssl == isSSL {
*port = gcListener.Port
*ipv4 = gcListener.IPv4IP
*ipv6 = gcListener.IPv6IP
*ipv4 = gcListener.IPv4
*ipv6 = gcListener.IPv6
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ func (lbc *LoadBalancerController) createExtendedResources(resources []Resource)
result.IngressExes = append(result.IngressExes, ingEx)
}
case *TransportServerConfiguration:
tsEx := lbc.createTransportServerEx(impl.TransportServer, impl.ListenerPort, impl.IPv4IP, impl.IPv6IP)
tsEx := lbc.createTransportServerEx(impl.TransportServer, impl.ListenerPort, impl.IPv4, impl.IPv6)
result.TransportServerExes = append(result.TransportServerExes, tsEx)
}
}
Expand Down Expand Up @@ -1363,7 +1363,7 @@ func (lbc *LoadBalancerController) processChanges(changes []ResourceChange) {
lbc.updateRegularIngressStatusAndEvents(impl, warnings, addOrUpdateErr)
}
case *TransportServerConfiguration:
tsEx := lbc.createTransportServerEx(impl.TransportServer, impl.ListenerPort, impl.IPv4IP, impl.IPv6IP)
tsEx := lbc.createTransportServerEx(impl.TransportServer, impl.ListenerPort, impl.IPv4, impl.IPv6)
warnings, addOrUpdateErr := lbc.configurator.AddOrUpdateTransportServer(tsEx)
lbc.updateTransportServerStatusAndEvents(impl, warnings, addOrUpdateErr)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/k8s/global_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (lbc *LoadBalancerController) processChangesFromGlobalConfiguration(changes
}
case *TransportServerConfiguration:
if c.Op == AddOrUpdate {
tsEx := lbc.createTransportServerEx(impl.TransportServer, impl.ListenerPort, impl.IPv4IP, impl.IPv6IP)
tsEx := lbc.createTransportServerEx(impl.TransportServer, impl.ListenerPort, impl.IPv4, impl.IPv6)

updatedTSExes = append(updatedTSExes, tsEx)
updatedResources = append(updatedResources, impl)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/configuration/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ type GlobalConfigurationSpec struct {
type Listener struct {
Name string `json:"name"`
Port int `json:"port"`
IPv4IP string `json:"ipv4"`
IPv6IP string `json:"ipv6"`
IPv4 string `json:"ipv4"`
IPv6 string `json:"ipv6"`
Protocol string `json:"protocol"`
Ssl bool `json:"ssl"`
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/apis/configuration/validation/globalconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ func (gcv *GlobalConfigurationValidator) updatePortProtocolCombinations(combinat
// getIP returns the appropriate IP address for the given ipType and listener.
func getIP(ipType ipType, listener conf_v1.Listener) string {
if ipType == ipv4 {
if listener.IPv4IP == "" {
if listener.IPv4 == "" {
return "0.0.0.0"
}
return listener.IPv4IP
return listener.IPv4
}
if listener.IPv6IP == "" {
if listener.IPv6 == "" {
return "::"
}
return listener.IPv6IP
return listener.IPv6
}

func generatePortProtocolKey(port int, protocol string) string {
Expand All @@ -148,8 +148,8 @@ func (gcv *GlobalConfigurationValidator) validateListener(listener conf_v1.Liste
allErrs := validateGlobalConfigurationListenerName(listener.Name, fieldPath.Child("name"))
allErrs = append(allErrs, gcv.validateListenerPort(listener.Name, listener.Port, fieldPath.Child("port"))...)
allErrs = append(allErrs, validateListenerProtocol(listener.Protocol, fieldPath.Child("protocol"))...)
allErrs = append(allErrs, validateListenerIPv4IP(listener.IPv4IP, fieldPath.Child("ipv4ip"))...)
allErrs = append(allErrs, validateListenerIPv6IP(listener.IPv6IP, fieldPath.Child("ipv6ip"))...)
allErrs = append(allErrs, validateListenerIPv4(listener.IPv4, fieldPath.Child("ipv4"))...)
allErrs = append(allErrs, validateListenerIPv6(listener.IPv6, fieldPath.Child("ipv6"))...)

return allErrs
}
Expand Down Expand Up @@ -185,16 +185,16 @@ func validateListenerProtocol(protocol string, fieldPath *field.Path) field.Erro
}
}

func validateListenerIPv4IP(ipv4ip string, fieldPath *field.Path) field.ErrorList {
if ipv4ip != "" {
return validation.IsValidIPv4Address(fieldPath, ipv4ip)
func validateListenerIPv4(ipv4 string, fieldPath *field.Path) field.ErrorList {
if ipv4 != "" {
return validation.IsValidIPv4Address(fieldPath, ipv4)
}
return field.ErrorList{}
}

func validateListenerIPv6IP(ipv6ip string, fieldPath *field.Path) field.ErrorList {
if ipv6ip != "" {
return validation.IsValidIPv6Address(fieldPath, ipv6ip)
func validateListenerIPv6(ipv6 string, fieldPath *field.Path) field.ErrorList {
if ipv6 != "" {
return validation.IsValidIPv6Address(fieldPath, ipv6)
}
return field.ErrorList{}
}
Expand Down
54 changes: 27 additions & 27 deletions pkg/apis/configuration/validation/globalconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func TestValidateListeners(t *testing.T) {
},
{
Name: "test-listener-ip",
IPv4IP: "127.0.0.1",
IPv6IP: "::1",
IPv4: "127.0.0.1",
IPv6: "::1",
Port: 8080,
Protocol: "HTTP",
},
Expand All @@ -101,38 +101,38 @@ func TestValidateListeners_FailsOnInvalidIP(t *testing.T) {
{
name: "Invalid IPv4 IP",
listeners: []conf_v1.Listener{
{Name: "test-listener-1", IPv4IP: "267.0.0.1", Port: 8082, Protocol: "HTTP"},
{Name: "test-listener-1", IPv4: "267.0.0.1", Port: 8082, Protocol: "HTTP"},
},
},
{
name: "Invalid IPv4 IP with missing octet",
listeners: []conf_v1.Listener{
{Name: "test-listener-2", IPv4IP: "127.0.0", Port: 8080, Protocol: "HTTP"},
{Name: "test-listener-2", IPv4: "127.0.0", Port: 8080, Protocol: "HTTP"},
},
},
{
name: "Invalid IPv6 IP",
listeners: []conf_v1.Listener{
{Name: "test-listener-3", IPv6IP: "1200::AB00::1234", Port: 8080, Protocol: "HTTP"},
{Name: "test-listener-3", IPv6: "1200::AB00::1234", Port: 8080, Protocol: "HTTP"},
},
},
{
name: "Valid and invalid IPs",
listeners: []conf_v1.Listener{
{Name: "test-listener-4", IPv4IP: "192.168.1.1", IPv6IP: "2001:0db1234123123", Port: 8080, Protocol: "HTTP"},
{Name: "test-listener-5", IPv4IP: "256.256.256.256", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8081, Protocol: "HTTP"},
{Name: "test-listener-4", IPv4: "192.168.1.1", IPv6: "2001:0db1234123123", Port: 8080, Protocol: "HTTP"},
{Name: "test-listener-5", IPv4: "256.256.256.256", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8081, Protocol: "HTTP"},
},
},
{
name: "Valid IPv4 and Invalid IPv6",
listeners: []conf_v1.Listener{
{Name: "test-listener-6", IPv4IP: "192.168.1.1", IPv6IP: "2001::85a3::8a2e:370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "test-listener-6", IPv4: "192.168.1.1", IPv6: "2001::85a3::8a2e:370:7334", Port: 8080, Protocol: "HTTP"},
},
},
{
name: "Invalid IPv4 and Valid IPv6",
listeners: []conf_v1.Listener{
{Name: "test-listener-8", IPv4IP: "300.168.1.1", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "test-listener-8", IPv4: "300.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
},
},
}
Expand Down Expand Up @@ -163,29 +163,29 @@ func TestValidateListeners_FailsOnPortProtocolConflictsSameIP(t *testing.T) {
{
name: "Same port used with the same protocol",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "192.168.1.1", IPv6IP: "::1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4IP: "192.168.1.1", IPv6IP: "::1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-1", IPv4: "192.168.1.1", IPv6: "::1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4: "192.168.1.1", IPv6: "::1", Port: 8080, Protocol: "HTTP"},
},
},
{
name: "Same port used with different protocols",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "192.168.1.1", IPv6IP: "::1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4IP: "192.168.1.1", Port: 8080, Protocol: "TCP"},
{Name: "listener-1", IPv4: "192.168.1.1", IPv6: "::1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4: "192.168.1.1", Port: 8080, Protocol: "TCP"},
},
},
{
name: "Same port used with the same protocol (IPv6)",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "192.168.1.1", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-1", IPv4: "192.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
},
},
{
name: "Same port used with different protocols (IPv6)",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4IP: "192.168.1.1", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "TCP"},
{Name: "listener-1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4: "192.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "TCP"},
},
},
}
Expand Down Expand Up @@ -216,22 +216,22 @@ func TestValidateListeners_PassesOnValidIPListeners(t *testing.T) {
{
name: "Different Ports and IPs",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "192.168.1.1", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4IP: "192.168.1.2", IPv6IP: "::1", Port: 9090, Protocol: "HTTP"},
{Name: "listener-1", IPv4: "192.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4: "192.168.1.2", IPv6: "::1", Port: 9090, Protocol: "HTTP"},
},
},
{
name: "Same IPs, Same Protocol and Different Port",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "192.168.1.1", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4IP: "192.168.1.1", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 9090, Protocol: "HTTP"},
{Name: "listener-1", IPv4: "192.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv4: "192.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 9090, Protocol: "HTTP"},
},
},
{
name: "Different Types of IPs",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "192.168.1.1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
{Name: "listener-1", IPv4: "192.168.1.1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 8080, Protocol: "HTTP"},
},
},
}
Expand All @@ -258,15 +258,15 @@ func TestValidateListeners_FailsOnMixedInvalidIPs(t *testing.T) {
{
name: "Valid IPv4 and Invalid IPv6",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "192.168.1.1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6IP: "2001::85a3::8a2e:370:7334", Port: 9090, Protocol: "TCP"},
{Name: "listener-1", IPv4: "192.168.1.1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6: "2001::85a3::8a2e:370:7334", Port: 9090, Protocol: "TCP"},
},
},
{
name: "Invalid IPv4 and Valid IPv6",
listeners: []conf_v1.Listener{
{Name: "listener-1", IPv4IP: "300.168.1.1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6IP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 9090, Protocol: "TCP"},
{Name: "listener-1", IPv4: "300.168.1.1", Port: 8080, Protocol: "HTTP"},
{Name: "listener-2", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", Port: 9090, Protocol: "TCP"},
},
},
}
Expand Down

0 comments on commit 9932dd4

Please sign in to comment.