8000 feat: Report Hostname in ExternalEndpoint for VS and VSR resources (#… · nginx/kubernetes-ingress@f27f7db · GitHub
[go: up one dir, main page]

Skip to content

Commit f27f7db

Browse files
authored
feat: Report Hostname in ExternalEndpoint for VS and VSR resources (#2781)
Report Hostname in ExternalEndpoint for VS and VSR resources
1 parent 56c756d commit f27f7db

File tree

7 files changed

+66
-19
lines changed

7 files changed

+66
-19
lines changed

deployments/common/crds/k8s.nginx.org_virtualserverroutes.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ spec:
2727
- jsonPath: .status.externalEndpoints[*].ip
2828
name: IP
2929
type: string
30+
- jsonPath: .status.externalEndpoints[*].hostname
31+
name: ExternalHostname
32+
priority: 1
33+
type: string
3034
- jsonPath: .status.externalEndpoints[*].ports
3135
name: Ports
3236
type: string
@@ -608,9 +612,11 @@ spec:
608612
externalEndpoints:
609613
type: array
610614
items:
611-
description: ExternalEndpoint defines the IP and ports used to connect to this resource.
615+
description: ExternalEndpoint defines the IP/ Hostname and ports used to connect to this resource.
612616
type: object
613617
properties:
618+
hostname:
619+
type: string
614620
ip:
615621
type: string
616622
ports:

deployments/common/crds/k8s.nginx.org_virtualservers.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ spec:
2727
- jsonPath: .status.externalEndpoints[*].ip
2828
name: IP
2929
type: string
30+
- jsonPath: .status.externalEndpoints[*].hostname
31+
name: ExternalHostname
32+
priority: 1
33+
type: string
3034
- jsonPath: .status.externalEndpoints[*].ports
3135
name: Ports
3236
type: string
@@ -660,9 +664,11 @@ spec:
660664
externalEndpoints:
661665
type: array
662666
items:
663-
description: ExternalEndpoint defines the IP and ports used to connect to this resource.
667+
description: ExternalEndpoint defines the IP/ Hostname and ports used to connect to this resource.
664668
type: object
665669
properties:
670+
hostname:
671+
type: string
666672
ip:
667673
type: string
668674
ports:

deployments/helm-chart/crds/k8s.nginx.org_virtualserverroutes.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ spec:
2727
- jsonPath: .status.externalEndpoints[*].ip
2828
name: IP
2929
type: string
30+
- jsonPath: .status.externalEndpoints[*].hostname
31+
name: ExternalHostname
32+
priority: 1
33+
type: string
3034
- jsonPath: .status.externalEndpoints[*].ports
3135
name: Ports
3236
type: string
@@ -608,9 +612,11 @@ spec:
608612
externalEndpoints:
609613
type: array
610614
items:
611-
description: ExternalEndpoint defines the IP and ports used to connect to this resource.
615+
description: ExternalEndpoint defines the IP/ Hostname and ports used to connect to this resource.
612616
type: object
613617
properties:
618+
hostname:
619+
type: string
614620
ip:
615621
type: string
616622
ports:

deployments/helm-chart/crds/k8s.nginx.org_virtualservers.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ spec:
2727
- jsonPath: .status.externalEndpoints[*].ip
2828
name: IP
2929
type: string
30+
- jsonPath: .status.externalEndpoints[*].hostname
31+
name: ExternalHostname
32+
priority: 1
33+
type: string
3034
- jsonPath: .status.externalEndpoints[*].ports
3135
name: Ports
3236
type: string
@@ -660,9 +664,11 @@ spec:
660664
externalEndpoints:
661665
type: array
662666
items:
663-
description: ExternalEndpoint defines the IP and ports used to connect to this resource.
667+
description: ExternalEndpoint defines the IP/ Hostname and ports used to connect to this resource.
664668
type: object
665669
properties:
670+
hostname:
671+
type: string
666672
ip:
667673
type: string
668674
ports:

internal/k8s/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ func (su *statusUpdater) generateExternalEndpointsFromStatus(status []api_v1.Loa
624624
ports = su.bigIPPorts
625625
}
626626

627-
endpoint := conf_v1.ExternalEndpoint{IP: lb.IP, Ports: ports}
627+
endpoint := conf_v1.ExternalEndpoint{IP: lb.IP, Hostname: lb.Hostname, Ports: ports}
628628
externalEndpoints = append(externalEndpoints, endpoint)
629629
}
630630

internal/k8s/status_test.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,22 +390,42 @@ func checkStatus(expected string, actual networking.Ingress) bool {
390390
}
391391

392392
func TestGenerateExternalEndpointsFromStatus(t *testing.T) {
393-
su := statusUpdater{
394-
status: []v1.LoadBalancerIngress{
395-
{
396-
IP: "8.8.8.8",
393+
tests := []struct {
394+
su statusUpdater
395+
expectedEndpoints []conf_v1.ExternalEndpoint
396+
}{
397+
{
398+
su: statusUpdater{
399+
status: []v1.LoadBalancerIngress{
400+
{
401+
IP: "8.8.8.8",
402+
},
403+
},
404+
},
405+
expectedEndpoints: []conf_v1.ExternalEndpoint{
406+
{IP: "8.8.8.8", Ports: ""},
407+
},
408+
},
409+
{
410+
su: statusUpdater{
411+
status: []v1.LoadBalancerIngress{
412+
{
413+
Hostname: "my-loadbalancer.example.com",
414+
},
415+
},
416+
},
417+
expectedEndpoints: []conf_v1.ExternalEndpoint{
418+
{Hostname: "my-loadbalancer.example.com", Ports: ""},
397419
},
398420
},
399421
}
422+
for _, test := range tests {
423+
endpoints := test.su.generateExternalEndpointsFromStatus(test.su.status)
400424

401-
expectedEndpoints := []conf_v1.ExternalEndpoint{
402-
{IP: "8.8.8.8", Ports: ""},
403-
}
404-
405-
endpoints := su.generateExternalEndpointsFromStatus(su.status)
425+
if !reflect.DeepEqual(endpoints, test.expectedEndpoints) {
426+
t.Errorf("generateExternalEndpointsFromStatus(%v) returned %v but expected %v", test.su.status, endpoints, test.expectedEndpoints)
427+
}
406428

407-
if !reflect.DeepEqual(endpoints, expectedEndpoints) {
408-
t.Errorf("generateExternalEndpointsFromStatus(%v) returned %v but expected %v", su.status, endpoints, expectedEndpoints)
409429
}
410430
}
411431

pkg/apis/configuration/v1/types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`,description="Current state of the VirtualServer. If the resource has a valid status, it means it has been validated and accepted by the Ingress Controller."
2222
// +kubebuilder:printcolumn:name="Host",type=string,JSONPath=`.spec.host`
2323
// +kubebuilder:printcolumn:name="IP",type=string,JSONPath=`.status.externalEndpoints[*].ip`
24+
// +kubebuilder:printcolumn:name="ExternalHostname",priority=1,type=string,JSONPath=`.status.externalEndpoints[*].hostname`
2425
// +kubebuilder:printcolumn:name="Ports",type=string,JSONPath=`.status.externalEndpoints[*].ports`
2526
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
2627

@@ -268,10 +269,11 @@ type VirtualServerStatus struct {
268269
ExternalEndpoints []ExternalEndpoint `json:"externalEndpoints,omitempty"`
269270
}
270271

271-
// ExternalEndpoint defines the IP and ports used to connect to this resource.
272+
// ExternalEndpoint defines the IP/ Hostname and ports used to connect to this resource.
272273
type ExternalEndpoint struct {
273-
IP string `json:"ip"`
274-
Ports string `json:"ports"`
274+
IP string `json:"ip,omitempty"`
275+
Hostname string `json:"hostname,omitempty"`
276+
Ports string `json:"ports"`
275277
}
276278

277279
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -292,6 +294,7 @@ type VirtualServerList struct {
292294
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`,description="Current state of the VirtualServerRoute. If the resource has a valid status, it means it has been validated and accepted by the Ingress Controller."
293295
// +kubebuilder:printcolumn:name="Host",type=string,JSONPath=`.spec.host`
294296
// +kubebuilder:printcolumn:name="IP",type=string,JSONPath=`.status.externalEndpoints[*].ip`
297+
// +kubebuilder:printcolumn:name="ExternalHostname",type=string,priority=1,JSONPath=`.status.externalEndpoints[*].hostname`
295298
// +kubebuilder:print 4354 column:name="Ports",type=string,JSONPath=`.status.externalEndpoints[*].ports`
296299
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
297300

0 commit comments

Comments
 (0)
0