From 665e2b6340b5dcdd6fcc8d52974ca02f51ec64a7 Mon Sep 17 00:00:00 2001 From: Sunghoon Kang Date: Sun, 23 Jan 2022 11:11:47 +0900 Subject: [PATCH] Feat: extend gateway trait to set class in spec (#3138) * Feat: extend gateway trait to set class in spec `kubernetes.io/ingress.class` annotation is deprecated in favor of `.spec.ingressClassName`. However, there is no way to set it through the gateway trait for now. This commit extends the gateway trait by adding `classInSpec` to parameter. Forcing the use of `.spec.ingressClassName` makes sense, but some ingress controllers (including old versions) may not recognize this field. Therefore, set default value of `classInSpec` to `false` for backward compatibility. Signed-off-by: Sunghoon Kang * Chore: update classInSpec usage Signed-off-by: Sunghoon Kang --- .../templates/defwithtemplate/gateway.yaml | 40 ++++++++++++------- .../templates/defwithtemplate/gateway.yaml | 40 ++++++++++++------- .../definitions/internal/trait/gateway.cue | 40 ++++++++++++------- 3 files changed, 77 insertions(+), 43 deletions(-) diff --git a/charts/vela-core/templates/defwithtemplate/gateway.yaml b/charts/vela-core/templates/defwithtemplate/gateway.yaml index 6e1a75e2c..9b044df2e 100644 --- a/charts/vela-core/templates/defwithtemplate/gateway.yaml +++ b/charts/vela-core/templates/defwithtemplate/gateway.yaml @@ -32,21 +32,30 @@ spec: kind: "Ingress" metadata: { name: context.name - annotations: "kubernetes.io/ingress.class": parameter.class + annotations: { + if !parameter.classInSpec { + "kubernetes.io/ingress.class": parameter.class + } + } + } + spec: { + if parameter.classInSpec { + ingressClassName: parameter.class + } + rules: [{ + host: parameter.domain + http: paths: [ + for k, v in parameter.http { + path: k + pathType: "ImplementationSpecific" + backend: service: { + name: context.name + port: number: v + } + }, + ] + }] } - spec: rules: [{ - host: parameter.domain - http: paths: [ - for k, v in parameter.http { - path: k - pathType: "ImplementationSpecific" - backend: service: { - name: context.name - port: number: v - } - }, - ] - }] } parameter: { // +usage=Specify the domain you want to expose @@ -57,6 +66,9 @@ spec: // +usage=Specify the class of ingress to use class: *"nginx" | string + + // +usage=Set ingress class in '.spec.ingressClassName' instead of 'kubernetes.io/ingress.class' annotation. + classInSpec: *false | bool } status: customStatus: |- diff --git a/charts/vela-minimal/templates/defwithtemplate/gateway.yaml b/charts/vela-minimal/templates/defwithtemplate/gateway.yaml index 6e1a75e2c..9b044df2e 100644 --- a/charts/vela-minimal/templates/defwithtemplate/gateway.yaml +++ b/charts/vela-minimal/templates/defwithtemplate/gateway.yaml @@ -32,21 +32,30 @@ spec: kind: "Ingress" metadata: { name: context.name - annotations: "kubernetes.io/ingress.class": parameter.class + annotations: { + if !parameter.classInSpec { + "kubernetes.io/ingress.class": parameter.class + } + } + } + spec: { + if parameter.classInSpec { + ingressClassName: parameter.class + } + rules: [{ + host: parameter.domain + http: paths: [ + for k, v in parameter.http { + path: k + pathType: "ImplementationSpecific" + backend: service: { + name: context.name + port: number: v + } + }, + ] + }] } - spec: rules: [{ - host: parameter.domain - http: paths: [ - for k, v in parameter.http { - path: k - pathType: "ImplementationSpecific" - backend: service: { - name: context.name - port: number: v - } - }, - ] - }] } parameter: { // +usage=Specify the domain you want to expose @@ -57,6 +66,9 @@ spec: // +usage=Specify the class of ingress to use class: *"nginx" | string + + // +usage=Set ingress class in '.spec.ingressClassName' instead of 'kubernetes.io/ingress.class' annotation. + classInSpec: *false | bool } status: customStatus: |- diff --git a/vela-templates/definitions/internal/trait/gateway.cue b/vela-templates/definitions/internal/trait/gateway.cue index 1dd6926db..c376fd02e 100644 --- a/vela-templates/definitions/internal/trait/gateway.cue +++ b/vela-templates/definitions/internal/trait/gateway.cue @@ -1,4 +1,4 @@ -"gateway": { +gateway: { type: "trait" annotations: {} labels: {} @@ -49,22 +49,29 @@ template: { metadata: { name: context.name annotations: { - "kubernetes.io/ingress.class": parameter.class + if !parameter.classInSpec { + "kubernetes.io/ingress.class": parameter.class + } } } - spec: rules: [{ - host: parameter.domain - http: paths: [ - for k, v in parameter.http { - path: k - pathType: "ImplementationSpecific" - backend: service: { - name: context.name - port: number: v - } - }, - ] - }] + spec: { + if parameter.classInSpec { + ingressClassName: parameter.class + } + rules: [{ + host: parameter.domain + http: paths: [ + for k, v in parameter.http { + path: k + pathType: "ImplementationSpecific" + backend: service: { + name: context.name + port: number: v + } + }, + ] + }] + } } parameter: { @@ -76,5 +83,8 @@ template: { // +usage=Specify the class of ingress to use class: *"nginx" | string + + // +usage=Set ingress class in '.spec.ingressClassName' instead of 'kubernetes.io/ingress.class' annotation. + classInSpec: *false | bool } }