Skip to content

Commit 2ade9f8

Browse files
authored
Set gateway Pod IP as GatewayStatus address (#638)
* Set gateway Pod IP as GatewayStatus address To satisfy conformance and provide the address of the gateway, we'll now set the pod IP address of the gateway on the GatewayStatus resource. Eventually we will also support other addresses.
1 parent 23b0b65 commit 2ade9f8

14 files changed

+120
-41
lines changed

cmd/gateway/gateway_suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main_test
33
import (
44
"testing"
55

6-
. "github.com/onsi/ginkgo"
6+
. "github.com/onsi/ginkgo/v2"
77
. "github.com/onsi/gomega"
88
)
99

cmd/gateway/main.go

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
6+
"net"
57
"os"
68

79
flag "github.com/spf13/pflag"
@@ -33,28 +35,49 @@ var (
3335
)
3436

3537
gatewayClassName = flag.String("gatewayclass", "", gatewayClassNameUsage)
38+
39+
// Environment variables
40+
podIP = os.Getenv("POD_IP")
3641
)
3742

43+
func validateIP(ip string) error {
44+
if ip == "" {
45+
return errors.New("IP address must be set")
46+
}
47+
if net.ParseIP(ip) == nil {
48+
return fmt.Errorf("%q must be a valid IP address", ip)
49+
}
50+
51+
return nil
52+
}
53+
3854
func main() {
3955
flag.Parse()
4056

57+
MustValidateArguments(
58+
flag.CommandLine,
59+
GatewayControllerParam(domain),
60+
GatewayClassParam(),
61+
)
62+
63+
if err := validateIP(podIP); err != nil {
64+
fmt.Printf("error validating POD_IP environment variable: %v\n", err)
65+
os.Exit(1)
66+
}
67+
4168
logger := zap.New()
4269
conf := config.Config{
4370
GatewayCtlrName: *gatewayCtlrName,
4471
Logger: logger,
4572
GatewayClassName: *gatewayClassName,
73+
PodIP: podIP,
4674
}
4775

48-
MustValidateArguments(
49-
flag.CommandLine,
50-
GatewayControllerParam(domain),
51-
GatewayClassParam(),
52-
)
53-
5476
logger.Info("Starting NGINX Kubernetes Gateway",
5577
"version", version,
5678
"commit", commit,
57-
"date", date)
79+
"date", date,
80+
)
5881

5982
err := manager.Start(conf)
6083
if err != nil {

cmd/gateway/main_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/gomega"
7+
)
8+
9+
func TestValidateIP(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
expSubMsg string
13+
ip string
14+
expErr bool
15+
}{
16+
{
17+
name: "var not set",
18+
ip: "",
19+
expErr: true,
20+
expSubMsg: "must be set",
21+
},
22+
{
23+
name: "invalid ip address",
24+
ip: "invalid",
25+
expErr: true,
26+
expSubMsg: "must be a valid",
27+
},
28+
{
29+
name: "valid ip address",
30+
ip: "1.2.3.4",
31+
expErr: false,
32+
},
33+
}
34+
35+
for _, tc := range tests {
36+
t.Run(tc.name, func(t *testing.T) {
37+
g := NewGomegaWithT(t)
38+
39+
err := validateIP(tc.ip)
40+
if !tc.expErr {
41+
g.Expect(err).ToNot(HaveOccurred())
42+
} else {
43+
g.Expect(err.Error()).To(ContainSubstring(tc.expSubMsg))
44+
}
45+
})
46+
}
47+
}

cmd/gateway/setup_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main_test
33
import (
44
"errors"
55

6-
. "github.com/onsi/ginkgo"
6+
. "github.com/onsi/ginkgo/v2"
77
. "github.com/onsi/gomega"
88
flag "github.com/spf13/pflag"
99

@@ -24,7 +24,7 @@ func MockValidator(name string, called *int, succeed bool) ValidatorContext {
2424
}
2525
}
2626

27-
var _ = Describe("Main", func() {
27+
var _ = Describe("Main Setup", func() {
2828
Describe("Generic Validator", func() {
2929
var mockFlags *flag.FlagSet
3030
BeforeEach(func() {

deploy/manifests/nginx-gateway.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ spec:
113113
# FIXME(pleshakov) - figure out which capabilities are required
114114
# dropping ALL and adding only CAP_KILL doesn't work
115115
# Note: CAP_KILL is needed for sending HUP signal to NGINX main process
116+
env:
117+
- name: POD_IP
118+
valueFrom:
119+
fieldRef:
120+
fieldPath: status.podIP
116121
args:
117122
- --gateway-ctlr-name=k8s-gateway.nginx.org/nginx-gateway-controller
118123
- --gatewayclass=nginx

docs/gateway-api-compatibility.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Fields:
6565
* `allowedRoutes` - not supported.
6666
* `addresses` - not supported.
6767
* `status`
68-
* `addresses` - not supported.
68+
* `addresses` - Pod IPAddress supported.
6969
* `conditions` - not supported.
7070
* `listeners`
7171
* `name` - supported.

go.mod

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/go-logr/logr v1.2.4
77
github.com/google/go-cmp v0.5.9
88
github.com/maxbrunsfeld/counterfeiter/v6 v6.6.1
9-
github.com/onsi/ginkgo v1.16.5
109
github.com/onsi/ginkgo/v2 v2.9.5
1110
github.com/onsi/gomega v1.27.6
1211
github.com/spf13/pflag v1.0.5
@@ -45,7 +44,6 @@ require (
4544
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4645
github.com/modern-go/reflect2 v1.0.2 // indirect
4746
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
48-
github.com/nxadm/tail v1.4.8 // indirect
4947
github.com/pkg/errors v0.9.1 // indirect
5048
github.com/prometheus/client_golang v1.14.0 // indirect
5149
github.com/prometheus/client_model v0.3.0 // indirect
@@ -66,7 +64,6 @@ require (
6664
google.golang.org/appengine v1.6.7 // indirect
6765
google.golang.org/protobuf v1.28.1 // indirect
6866
gopkg.in/inf.v0 v0.9.1 // indirect
69-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
7067
gopkg.in/yaml.v2 v2.4.0 // indirect
7168
gopkg.in/yaml.v3 v3.0.1 // indirect
7269
k8s.io/apiextensions-apiserver v0.26.1 // indirect

go.sum

-24
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCv
6969
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
7070
github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
7171
github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
72-
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
73-
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
7472
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
7573
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
7674
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@@ -99,7 +97,6 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
9997
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
10098
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
10199
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
102-
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
103100
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
104101
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
105102
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -172,7 +169,6 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
172169
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
173170
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
174171
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
175-
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
176172
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
177173
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
178174
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
@@ -223,17 +219,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
223219
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
224220
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
225221
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
226-
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
227-
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
228-
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
229-
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
230-
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
231-
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
232-
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
233222
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
234223
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
235-
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
236-
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
237224
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
238225
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
239226
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -345,7 +332,6 @@ golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
345332
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
346333
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
347334
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
348-
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
349335
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
350336
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
351337
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -368,7 +354,6 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/
368354
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
369355
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
370356
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
371-
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
372357
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
373358
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
374359
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
@@ -400,7 +385,6 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
400385
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
401386
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
402387
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
403-
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
404388
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
405389
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
406390
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -411,10 +395,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
411395
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
412396
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
413397
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
414-
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
415398
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
416-
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
417-
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
418399
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
419400
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
420401
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -435,7 +416,6 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w
435416
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
436417
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
437418
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
438-
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
439419
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
440420
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
441421
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -505,7 +485,6 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY
505485
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
506486
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
507487
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
508-
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
509488
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
510489
golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
511490
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
@@ -602,11 +581,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
602581
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
603582
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
604583
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
605-
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
606584
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
607585
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
608-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
609-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
610586
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
611587
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
612588
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

internal/config/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ type Config struct {
1313
GatewayNsName types.NamespacedName
1414
// GatewayClassName is the name of the GatewayClass resource that the Gateway will use.
1515
GatewayClassName string
16+
// PodIP is the IP address of this Pod.
17+
PodIP string
1618
}

internal/manager/manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func Start(cfg config.Config) error {
136136
GatewayCtlrName: cfg.GatewayCtlrName,
137137
GatewayClassName: cfg.GatewayClassName,
138138
Client: mgr.GetClient(),
139+
PodIP: cfg.PodIP,
139140
// FIXME(pleshakov) Make sure each component:
140141
// (1) Has a dedicated named logger.
141142
// (2) Get it from the Manager (the WithName is done here for all components).

internal/status/gateway.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ const (
2323
// FIXME(pleshakov): Be compliant with in the Gateway API.
2424
// Currently, we only support simple valid/invalid status per each listener.
2525
// Extend support to cover more cases.
26-
func prepareGatewayStatus(gatewayStatus state.GatewayStatus, transitionTime metav1.Time) v1beta1.GatewayStatus {
26+
func prepareGatewayStatus(
27+
gatewayStatus state.GatewayStatus,
28+
podIP string,
29+
transitionTime metav1.Time,
30+
) v1beta1.GatewayStatus {
2731
listenerStatuses := make([]v1beta1.ListenerStatus, 0, len(gatewayStatus.ListenerStatuses))
2832

2933
// FIXME(pleshakov) Maintain the order from the Gateway resource
@@ -48,8 +52,15 @@ func prepareGatewayStatus(gatewayStatus state.GatewayStatus, transitionTime meta
4852
})
4953
}
5054

55+
ipAddrType := v1beta1.IPAddressType
56+
gwPodIP := v1beta1.GatewayAddress{
57+
Type: &ipAddrType,
58+
Value: podIP,
59+
}
60+
5161
return v1beta1.GatewayStatus{
5262
Listeners: listenerStatuses,
63+
Addresses: []v1beta1.GatewayAddress{gwPodIP},
5364
Conditions: nil, // FIXME(pleshakov) Create conditions for the Gateway resource.
5465
}
5566
}

internal/status/gateway_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import (
1414
)
1515

1616
func TestPrepareGatewayStatus(t *testing.T) {
17+
ipAddrType := v1beta1.IPAddressType
18+
podIP := v1beta1.GatewayAddress{
19+
Type: &ipAddrType,
20+
Value: "1.2.3.4",
21+
}
22+
1723
status := state.GatewayStatus{
1824
ListenerStatuses: state.ListenerStatuses{
1925
"listener": {
@@ -39,11 +45,12 @@ func TestPrepareGatewayStatus(t *testing.T) {
3945
Conditions: CreateExpectedAPIConditions(1, transitionTime),
4046
},
4147
},
48+
Addresses: []v1beta1.GatewayAddress{podIP},
4249
}
4350

4451
g := NewGomegaWithT(t)
4552

46-
result := prepareGatewayStatus(status, transitionTime)
53+
result := prepareGatewayStatus(status, "1.2.3.4", transitionTime)
4754
g.Expect(helpers.Diff(expected, result)).To(BeEmpty())
4855
}
4956

internal/status/updater.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type UpdaterConfig struct {
3232
GatewayCtlrName string
3333
// GatewayClassName is the name of the GatewayClass resource.
3434
GatewayClassName string
35+
// PodIP is the IP address of this Pod.
36+
PodIP string
3537
}
3638

3739
// updaterImpl updates statuses of the Gateway API resources.
@@ -101,7 +103,7 @@ func (upd *updaterImpl) Update(ctx context.Context, statuses state.Statuses) {
101103
if statuses.GatewayStatus != nil {
102104
upd.update(ctx, statuses.GatewayStatus.NsName, &v1beta1.Gateway{}, func(object client.Object) {
103105
gw := object.(*v1beta1.Gateway)
104-
gw.Status = prepareGatewayStatus(*statuses.GatewayStatus, upd.cfg.Clock.Now())
106+
gw.Status = prepareGatewayStatus(*statuses.GatewayStatus, upd.cfg.PodIP, upd.cfg.Clock.Now())
105107
})
106108
}
107109

0 commit comments

Comments
 (0)