Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx-Ingress - Provide possibility to disable everything at root level - with corresponding possibility to enable at path level #164

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions generators/ambassador/ambassador.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,12 @@ func (g *Generator) shouldSplit(opts *options.Options, spec *openapi3.T) bool {
}

for path, pathItem := range spec.Paths {
// a path is disabled
if opts.IsPathDisabled(path) {
return true
}

if pathSubOptions, ok := opts.PathSubOptions[path]; ok {
// a path is disabled
if opts.IsPathDisabled(path) {
return true
}

// a path has non-zero, different from global scope CORS options
if !reflect.DeepEqual(options.CORSOptions{}, pathSubOptions.CORS) &&
!reflect.DeepEqual(opts.CORS, pathSubOptions.CORS) {
Expand Down
1 change: 0 additions & 1 deletion generators/ambassador/ambassador_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,6 @@ paths:
{
name: "path disabled, operation enabled",
options: options.Options{
Disabled: true,
Namespace: "default",
Service: options.ServiceOptions{
Namespace: "default",
Expand Down
12 changes: 6 additions & 6 deletions generators/nginx_ingress/nginx_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (g *Generator) Generate(opts *options.Options, spec *openapi3.T) (string, e

ingresses = append(ingresses, ingress)
}
} else {
} else if !opts.Disabled {
ingress := g.newIngressResource(
fmt.Sprintf("%s-ingress", opts.Service.Name),
opts.Namespace,
Expand Down Expand Up @@ -330,12 +330,12 @@ func (g *Generator) shouldSplit(opts *options.Options, spec *openapi3.T) bool {
warnGroupUnsupported(opts.RateLimits)

for path, pathItem := range spec.Paths {
if pathSubOptions, ok := opts.PathSubOptions[path]; ok {
// a path is disabled
if opts.IsPathDisabled(path) {
return true
}
// a path is disabled
if opts.IsPathDisabled(path) {
return true
}

if pathSubOptions, ok := opts.PathSubOptions[path]; ok {
// a path has non-zero, different from global scope CORS options
if !reflect.DeepEqual(options.CORSOptions{}, pathSubOptions.CORS) &&
!reflect.DeepEqual(opts.CORS, pathSubOptions.CORS) {
Expand Down
139 changes: 139 additions & 0 deletions generators/nginx_ingress/nginx_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type testCase struct {
}

func TestNGINXIngress(t *testing.T) {
trueValue := true
falseValue := false

var testCases = []testCase{
{
name: "root base path and no trim prefix",
Expand Down Expand Up @@ -515,6 +518,142 @@ spec:
pathType: Prefix
status:
loadBalancer: {}
`,
},
{
name: "globally disabled",
options: options.Options{
Disabled: true,
Namespace: "default",
Service: options.ServiceOptions{
Namespace: "default",
Name: "petstore",
},
},
spec: `
openapi: 3.0.2
info:
title: Swagger Petstore - OpenAPI 3.0
version: 1.0.5
x-kusk:
disabled: true
paths:
/:
get: {}
post: {}
`,
res: ``,
},
{
name: "path disabled, another path enabled",
options: options.Options{
Namespace: "default",
Service: options.ServiceOptions{
Namespace: "default",
Name: "petstore",
},
PathSubOptions: map[string]options.SubOptions{
"/": {
Disabled: &trueValue,
},
"/path": {
Disabled: &falseValue,
},
},
},
spec: `
openapi: 3.0.2
info:
title: Swagger Petstore - OpenAPI 3.0
version: 1.0.5
paths:
/:
x-kusk:
disabled: true
get: {}
/path:
x-kusk:
disabled: true
get: {}
`,
res: `---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /path
creationTimestamp: null
name: petstore-path
namespace: default
spec:
ingressClassName: nginx
rules:
- http:
paths:
- backend:
service:
name: petstore
port:
number: 80
path: /path
pathType: Exact
status:
loadBalancer: {}
`,
},
{
name: "globally disabled, single path enabled",
options: options.Options{
Disabled: true,
Namespace: "default",
Service: options.ServiceOptions{
Namespace: "default",
Name: "petstore",
},
PathSubOptions: map[string]options.SubOptions{
"/path": {
Disabled: &falseValue,
},
},
},
spec: `
openapi: 3.0.2
info:
title: Swagger Petstore - OpenAPI 3.0
version: 1.0.5
x-kusk:
disabled: true
paths:
/:
get: {}
/path:
x-kusk:
disabled: false
get: {}
`,
res: `---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /path
creationTimestamp: null
name: petstore-path
namespace: default
spec:
ingressClassName: nginx
rules:
- http:
paths:
- backend:
service:
name: petstore
port:
number: 80
path: /path
pathType: Exact
status:
loadBalancer: {}
`,
},
}
Expand Down