Skip to content

Commit

Permalink
update based on reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Dec 16, 2024
1 parent 896e315 commit d6673fb
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 94 deletions.
37 changes: 24 additions & 13 deletions tests/framework/crossplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,15 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
continue
}

for _, serverName := range expFieldCfg.Servers {
if directive.Directive == "server" && getServerName(directive.Block) == serverName {
for _, serverDirective := range directive.Block {
if expFieldCfg.Location == "" && expFieldCfg.fieldFound(serverDirective) {
return nil
} else if serverDirective.Directive == "location" &&
fieldExistsInLocation(serverDirective, expFieldCfg) {
return nil
}
}
}
err := validateServerBlockDirectives(expFieldCfg, *directive)
if err != nil {
return err
}

return validateUpstreamDirectives(expFieldCfg, directive)
err = validateUpstreamDirectives(expFieldCfg, directive)
if err != nil {
return err
}
}
}

Expand All @@ -79,6 +74,22 @@ func ValidateNginxFieldExists(conf *Payload, expFieldCfg ExpectedNginxField) err
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, string(b))
}

func validateServerBlockDirectives(expFieldCfg ExpectedNginxField, directive Directive) error {
for _, serverName := range expFieldCfg.Servers {
if directive.Directive == "server" && getServerName(directive.Block) == serverName {
for _, serverDirective := range directive.Block {
if expFieldCfg.Location == "" && expFieldCfg.fieldFound(serverDirective) {
return nil
} else if serverDirective.Directive == "location" &&
fieldExistsInLocation(serverDirective, expFieldCfg) {
return nil
}
}
}
}
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
}

func validateUpstreamDirectives(expFieldCfg ExpectedNginxField, directive *Directive) error {
for _, upstreamName := range expFieldCfg.Upstreams {
if directive.Directive == "upstream" && directive.Args[0] == upstreamName {
Expand All @@ -89,7 +100,7 @@ func validateUpstreamDirectives(expFieldCfg ExpectedNginxField, directive *Direc
}
}
}
return nil
return fmt.Errorf("field not found; expected: %+v\nNGINX conf: %s", expFieldCfg, directive.Directive)
}

func getServerName(serverBlock Directives) string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: gateway.nginx.org/v1alpha1
kind: UpstreamSettingsPolicy
metadata:
name: latte-svc-usp
spec:
zoneSize: 512k
targetRefs:
- group: core
kind: Service
name: latte
keepAlive:
connections: 10
requests: 3
time: 10s
timeout: 50s
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway-httproute-allowed
name: gateway-not-valid
spec:
gatewayClassName: nginx
addresses: "10.0.0.1"
listeners:
- name: http
port: 80
protocol: HTTP
hostname: "soda.example.com"
allowedRoutes:
namespaces:
from: All
kinds:
kind: GRPCRoute
---
apiVersion: apps/v1
kind: Deployment
Expand Down
24 changes: 4 additions & 20 deletions tests/suite/manifests/upstream-settings-policy/valid-usps.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
apiVersion: gateway.nginx.org/v1alpha1
kind: UpstreamSettingsPolicy
metadata:
name: coffee-svc-usp
name: multiple-http-svc-usp
spec:
zoneSize: 512k
targetRefs:
- group: core
kind: Service
name: coffee
- group: core
kind: Service
name: tea
keepAlive:
connections: 10
requests: 3
Expand All @@ -16,25 +19,6 @@ spec:
---
apiVersion: gateway.nginx.org/v1alpha1
kind: UpstreamSettingsPolicy
metadata:
name: tea-multiple-svc-usp
spec:
zoneSize: 128k
targetRefs:
- group: core
kind: Service
name: tea
- group: core
kind: Service
name: coffee
keepAlive:
connections: 12
requests: 31
time: 20s
timeout: 40s
---
apiVersion: gateway.nginx.org/v1alpha1
kind: UpstreamSettingsPolicy
metadata:
name: grpc-svc-usp
spec:
Expand Down
Loading

0 comments on commit d6673fb

Please sign in to comment.