Skip to content

Commit c28a52b

Browse files
author
Kate Osborn
committed
Addition does not need to be a pointer
1 parent f25e9fd commit c28a52b

File tree

6 files changed

+32
-42
lines changed

6 files changed

+32
-42
lines changed

internal/mode/static/nginx/config/servers.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,11 @@ func createAdditionFileResults(conf dataplane.Configuration) []executeResult {
123123
return results
124124
}
125125

126-
func createAdditionFileName(addition *dataplane.Addition) string {
127-
if addition == nil {
128-
panic("addition is nil")
129-
}
130-
126+
func createAdditionFileName(addition dataplane.Addition) string {
131127
return fmt.Sprintf("%s/%s.conf", includesFolder, addition.Identifier)
132128
}
133129

134-
func createIncludes(additions []*dataplane.Addition) []string {
130+
func createIncludes(additions []dataplane.Addition) []string {
135131
if len(additions) == 0 {
136132
return nil
137133
}

internal/mode/static/nginx/config/servers_test.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestExecuteServers(t *testing.T) {
2828
{
2929
Hostname: "cafe.example.com",
3030
Port: 8080,
31-
Additions: []*dataplane.Addition{
31+
Additions: []dataplane.Addition{
3232
{
3333
Bytes: []byte("addition-1"),
3434
Identifier: "addition-1",
@@ -80,7 +80,7 @@ func TestExecuteServers(t *testing.T) {
8080
},
8181
},
8282
},
83-
Additions: []*dataplane.Addition{
83+
Additions: []dataplane.Addition{
8484
{
8585
Bytes: []byte("addition-1"),
8686
Identifier: "addition-1", // duplicate
@@ -590,7 +590,7 @@ func TestCreateServers(t *testing.T) {
590590
{
591591
Match: dataplane.Match{},
592592
BackendGroup: fooGroup,
593-
Additions: []*dataplane.Addition{
593+
Additions: []dataplane.Addition{
594594
{
595595
Bytes: []byte("path-only-match-addition"),
596596
Identifier: "path-only-match-addition",
@@ -608,7 +608,7 @@ func TestCreateServers(t *testing.T) {
608608
Method: helpers.GetPointer("GET"),
609609
},
610610
BackendGroup: fooGroup,
611-
Additions: []*dataplane.Addition{
611+
Additions: []dataplane.Addition{
612612
{
613613
Bytes: []byte("match-addition"),
614614
Identifier: "match-addition",
@@ -628,7 +628,7 @@ func TestCreateServers(t *testing.T) {
628628
Hostname: "cafe.example.com",
629629
PathRules: cafePathRules,
630630
Port: 8080,
631-
Additions: []*dataplane.Addition{
631+
Additions: []dataplane.Addition{
632632
{
633633
Bytes: []byte("server-addition-1"),
634634
Identifier: "server-addition-1",
@@ -651,7 +651,7 @@ func TestCreateServers(t *testing.T) {
651651
SSL: &dataplane.SSL{KeyPairID: sslKeyPairID},
652652
PathRules: cafePathRules,
653653
Port: 8443,
654-
Additions: []*dataplane.Addition{
654+
Additions: []dataplane.Addition{
655655
{
656656
Bytes: []byte("server-addition-1"),
657657
Identifier: "server-addition-1",
@@ -2349,7 +2349,7 @@ func TestGenerateResponseHeaders(t *testing.T) {
23492349
func TestCreateIncludes(t *testing.T) {
23502350
tests := []struct {
23512351
name string
2352-
additions []*dataplane.Addition
2352+
additions []dataplane.Addition
23532353
includes []string
23542354
}{
23552355
{
@@ -2359,7 +2359,7 @@ func TestCreateIncludes(t *testing.T) {
23592359
},
23602360
{
23612361
name: "additions",
2362-
additions: []*dataplane.Addition{
2362+
additions: []dataplane.Addition{
23632363
{
23642364
Bytes: []byte("one"),
23652365
Identifier: "one",
@@ -2395,7 +2395,7 @@ func TestCreateAdditionFileResults(t *testing.T) {
23952395
conf := dataplane.Configuration{
23962396
HTTPServers: []dataplane.VirtualServer{
23972397
{
2398-
Additions: []*dataplane.Addition{
2398+
Additions: []dataplane.Addition{
23992399
{
24002400
Identifier: "include-1",
24012401
Bytes: []byte("include-1"),
@@ -2409,7 +2409,7 @@ func TestCreateAdditionFileResults(t *testing.T) {
24092409
{
24102410
MatchRules: []dataplane.MatchRule{
24112411
{
2412-
Additions: []*dataplane.Addition{
2412+
Additions: []dataplane.Addition{
24132413
{
24142414
Identifier: "include-3",
24152415
Bytes: []byte("include-3"),
@@ -2425,7 +2425,7 @@ func TestCreateAdditionFileResults(t *testing.T) {
24252425
},
24262426
},
24272427
{
2428-
Additions: []*dataplane.Addition{
2428+
Additions: []dataplane.Addition{
24292429
{
24302430
Identifier: "include-1", // dupe
24312431
Bytes: []byte("include-1"),
@@ -2439,7 +2439,7 @@ func TestCreateAdditionFileResults(t *testing.T) {
24392439
},
24402440
SSLServers: []dataplane.VirtualServer{
24412441
{
2442-
Additions: []*dataplane.Addition{
2442+
Additions: []dataplane.Addition{
24432443
{
24442444
Identifier: "include-1", // dupe
24452445
Bytes: []byte("include-1"),
@@ -2453,7 +2453,7 @@ func TestCreateAdditionFileResults(t *testing.T) {
24532453
{
24542454
MatchRules: []dataplane.MatchRule{
24552455
{
2456-
Additions: []*dataplane.Addition{
2456+
Additions: []dataplane.Addition{
24572457
{
24582458
Identifier: "include-3",
24592459
Bytes: []byte("include-3"), // dupe
@@ -2512,12 +2512,6 @@ func TestCreateAdditionFileResults(t *testing.T) {
25122512
func TestAdditionFilename(t *testing.T) {
25132513
g := NewWithT(t)
25142514

2515-
name := createAdditionFileName(&dataplane.Addition{Identifier: "my-addition"})
2515+
name := createAdditionFileName(dataplane.Addition{Identifier: "my-addition"})
25162516
g.Expect(name).To(Equal(includesFolder + "/" + "my-addition.conf"))
2517-
2518-
create := func() {
2519-
_ = createAdditionFileName(nil)
2520-
}
2521-
2522-
g.Expect(create).To(Panic())
25232517
}

internal/mode/static/state/dataplane/configuration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,19 +657,19 @@ func buildBaseHTTPConfig(g *graph.Graph) BaseHTTPConfig {
657657
return baseConfig
658658
}
659659

660-
func buildAdditions(policies []*graph.Policy, generator policies.ConfigGenerator) []*Addition {
660+
func buildAdditions(policies []*graph.Policy, generator policies.ConfigGenerator) []Addition {
661661
if len(policies) == 0 {
662662
return nil
663663
}
664664

665-
additions := make([]*Addition, 0, len(policies))
665+
additions := make([]Addition, 0, len(policies))
666666

667667
for _, policy := range policies {
668668
if !policy.Valid {
669669
continue
670670
}
671671

672-
additions = append(additions, &Addition{
672+
additions = append(additions, Addition{
673673
Bytes: generator.Generate(policy.Source),
674674
Identifier: fmt.Sprintf(
675675
"%s_%s_%s",

internal/mode/static/state/dataplane/configuration_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@ func TestBuildConfiguration(t *testing.T) {
21202120
{
21212121
IsDefault: true,
21222122
Port: 80,
2123-
Additions: []*Addition{
2123+
Additions: []Addition{
21242124
{
21252125
Bytes: []byte("apple"),
21262126
Identifier: "ApplePolicy_default_attach-gw",
@@ -2141,7 +2141,7 @@ func TestBuildConfiguration(t *testing.T) {
21412141
{
21422142
Source: &hrWithPolicy.ObjectMeta,
21432143
BackendGroup: expHRWithPolicyGroups[0],
2144-
Additions: []*Addition{
2144+
Additions: []Addition{
21452145
{
21462146
Bytes: []byte("lemon"),
21472147
Identifier: "LemonPolicy_default_attach-hr",
@@ -2152,7 +2152,7 @@ func TestBuildConfiguration(t *testing.T) {
21522152
},
21532153
},
21542154
Port: 80,
2155-
Additions: []*Addition{
2155+
Additions: []Addition{
21562156
{
21572157
Bytes: []byte("apple"),
21582158
Identifier: "ApplePolicy_default_attach-gw",
@@ -2168,7 +2168,7 @@ func TestBuildConfiguration(t *testing.T) {
21682168
{
21692169
IsDefault: true,
21702170
Port: 443,
2171-
Additions: []*Addition{
2171+
Additions: []Addition{
21722172
{
21732173
Bytes: []byte("apple"),
21742174
Identifier: "ApplePolicy_default_attach-gw",
@@ -2189,7 +2189,7 @@ func TestBuildConfiguration(t *testing.T) {
21892189
{
21902190
BackendGroup: expHTTPSHRWithPolicyGroups[0],
21912191
Source: &httpsHRWithPolicy.ObjectMeta,
2192-
Additions: []*Addition{
2192+
Additions: []Addition{
21932193
{
21942194
Bytes: []byte("lime"),
21952195
Identifier: "LimePolicy_default_attach-hr",
@@ -2201,7 +2201,7 @@ func TestBuildConfiguration(t *testing.T) {
22012201
},
22022202
SSL: &SSL{KeyPairID: "ssl_keypair_test_secret-1"},
22032203
Port: 443,
2204-
Additions: []*Addition{
2204+
Additions: []Addition{
22052205
{
22062206
Bytes: []byte("apple"),
22072207
Identifier: "ApplePolicy_default_attach-gw",
@@ -2216,7 +2216,7 @@ func TestBuildConfiguration(t *testing.T) {
22162216
Hostname: wildcardHostname,
22172217
SSL: &SSL{KeyPairID: "ssl_keypair_test_secret-1"},
22182218
Port: 443,
2219-
Additions: []*Addition{
2219+
Additions: []Addition{
22202220
{
22212221
Bytes: []byte("apple"),
22222222
Identifier: "ApplePolicy_default_attach-gw",
@@ -3056,7 +3056,7 @@ func TestBuildAdditions(t *testing.T) {
30563056
tests := []struct {
30573057
name string
30583058
policies []*graph.Policy
3059-
expAdditions []*Addition
3059+
expAdditions []Addition
30603060
}{
30613061
{
30623062
name: "nil policies",
@@ -3087,7 +3087,7 @@ func TestBuildAdditions(t *testing.T) {
30873087
Valid: true,
30883088
},
30893089
},
3090-
expAdditions: []*Addition{
3090+
expAdditions: []Addition{
30913091
{
30923092
Identifier: "Kind1_test_valid1",
30933093
Bytes: []byte("valid1"),

internal/mode/static/state/dataplane/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type VirtualServer struct {
6969
// PathRules is a collection of routing rules.
7070
PathRules []PathRule
7171
// Additions is a list of config additions for the server.
72-
Additions []*Addition
72+
Additions []Addition
7373
// Port is the port of the server.
7474
Port int32
7575
// IsDefault indicates whether the server is the default server.
@@ -215,7 +215,7 @@ type MatchRule struct {
215215
// Match holds the match for the rule.
216216
Match Match
217217
// Additions holds the config additions for the rule.
218-
Additions []*Addition
218+
Additions []Addition
219219
// BackendGroup is the group of Backends that the rule routes to.
220220
BackendGroup BackendGroup
221221
}

internal/mode/static/state/graph/graph.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ func (g *Graph) IsNGFPolicyRelevant(
142142

143143
switch ref.Group {
144144
case gatewayv1.GroupName:
145-
return g.gatewayResourceExist(ref, policy.GetNamespace())
145+
return g.gatewayAPIResourceExist(ref, policy.GetNamespace())
146146
default:
147147
return false
148148
}
149149
}
150150

151-
func (g *Graph) gatewayResourceExist(ref v1alpha2.LocalPolicyTargetReference, policyNs string) bool {
151+
func (g *Graph) gatewayAPIResourceExist(ref v1alpha2.LocalPolicyTargetReference, policyNs string) bool {
152152
refNsName := types.NamespacedName{Name: string(ref.Name), Namespace: policyNs}
153153

154154
switch kind := ref.Kind; kind {

0 commit comments

Comments
 (0)