From 9932dd439f568550e3e62544fe4fc16066fd7939 Mon Sep 17 00:00:00 2001 From: Jim Ryan Date: Tue, 10 Sep 2024 17:17:57 +0100 Subject: [PATCH] change ipv4ip to ipv4 --- charts/nginx-ingress/values.schema.json | 4 +- internal/k8s/configuration.go | 12 ++--- internal/k8s/controller.go | 4 +- internal/k8s/global_configuration.go | 2 +- pkg/apis/configuration/v1/types.go | 4 +- .../validation/globalconfiguration.go | 24 ++++----- .../validation/globalconfiguration_test.go | 54 +++++++++---------- 7 files changed, 52 insertions(+), 52 deletions(-) diff --git a/charts/nginx-ingress/values.schema.json b/charts/nginx-ingress/values.schema.json index 4679145193..423dd014c5 100644 --- a/charts/nginx-ingress/values.schema.json +++ b/charts/nginx-ingress/values.schema.json @@ -995,7 +995,7 @@ "dns-tcp" ] }, - "ipv4ip": { + "ipv4": { "type": "string", "default": "", "title": "The ipv4 ip", @@ -1003,7 +1003,7 @@ "127.0.0.1" ] }, - "ipv6ip": { + "ipv6": { "type": "string", "default": "", "title": "The ipv6 ip", diff --git a/internal/k8s/configuration.go b/internal/k8s/configuration.go index 7b239c0a9b..b600213754 100644 --- a/internal/k8s/configuration.go +++ b/internal/k8s/configuration.go @@ -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 } @@ -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 { @@ -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 } } diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index a4ca6cbaa6..ccd62a8f6c 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -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) } } @@ -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) } diff --git a/internal/k8s/global_configuration.go b/internal/k8s/global_configuration.go index b552dca003..7d64c86a78 100644 --- a/internal/k8s/global_configuration.go +++ b/internal/k8s/global_configuration.go @@ -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) diff --git a/pkg/apis/configuration/v1/types.go b/pkg/apis/configuration/v1/types.go index 76c5261980..cac87569ab 100644 --- a/pkg/apis/configuration/v1/types.go +++ b/pkg/apis/configuration/v1/types.go @@ -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"` } diff --git a/pkg/apis/configuration/validation/globalconfiguration.go b/pkg/apis/configuration/validation/globalconfiguration.go index 689fa625ef..ca3b5bce18 100644 --- a/pkg/apis/configuration/validation/globalconfiguration.go +++ b/pkg/apis/configuration/validation/globalconfiguration.go @@ -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 { @@ -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 } @@ -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{} } diff --git a/pkg/apis/configuration/validation/globalconfiguration_test.go b/pkg/apis/configuration/validation/globalconfiguration_test.go index 709967db71..45ccd5d05c 100644 --- a/pkg/apis/configuration/validation/globalconfiguration_test.go +++ b/pkg/apis/configuration/validation/globalconfiguration_test.go @@ -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", }, @@ -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"}, }, }, } @@ -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"}, }, }, } @@ -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"}, }, }, } @@ -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"}, }, }, }