Chore: Update extensions/v1beta1 to networking.k8s.io/v1 on OpenAPI-2-Kong (#4667)

* Update extensions/v1beta1 to  networking.k8s.io/v1

This is follow the deprecation guide of past k8s version 1.22

https://kubernetes.io/docs/reference/using-api/deprecation-guide/#ingress-v122

* Fix other deprecated k8s ingress interfaces.

* Fix typo in url.
This commit is contained in:
Filipe Freire 2022-04-19 19:00:23 +01:00 committed by GitHub
parent dafed833e6
commit cc63a1ccec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 148 additions and 64 deletions

View File

@ -258,7 +258,7 @@ paths:
#### Generated config #### Generated config
```yaml ```yaml
apiVersion: extensions/v1beta1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: insomnia-api-1 name: insomnia-api-1
@ -271,10 +271,13 @@ spec:
paths: paths:
- path: /v1/.* - path: /v1/.*
backend: backend:
serviceName: insomnia-api-service-0 service:
servicePort: 80 name: insomnia-api-service-0
port:
number: 80
pathType: 'ImplementationSpecific'
--- ---
apiVersion: extensions/v1beta1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: insomnia-api-2 name: insomnia-api-2
@ -287,8 +290,11 @@ spec:
paths: paths:
- path: /v2/.* - path: /v2/.*
backend: backend:
serviceName: insomnia-api-service-1 service:
servicePort: 80 name: insomnia-api-service-1
port:
number: 80
pathType: 'ImplementationSpecific'
``` ```
</details> </details>
@ -300,7 +306,7 @@ The `Ingress` document `metadata.name` is derived from sections in the source sp
Each of the following specifications generate an `Ingress` document with the following name: Each of the following specifications generate an `Ingress` document with the following name:
```yaml ```yaml
apiVersion: extensions/v1beta1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: insomnia-api name: insomnia-api
@ -445,7 +451,7 @@ config:
key_in_body: false key_in_body: false
hide_credentials: true hide_credentials: true
--- ---
apiVersion: extensions/v1beta1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: insomnia-api-0 name: insomnia-api-0
@ -460,10 +466,13 @@ spec:
paths: paths:
- path: /v1/path - path: /v1/path
backend: backend:
serviceName: insomnia-api-service-0 service:
servicePort: 80 name: insomnia-api-service-0
port:
number: 80
pathType: 'ImplementationSpecific'
--- ---
apiVersion: extensions/v1beta1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: insomnia-api-1 name: insomnia-api-1
@ -479,10 +488,13 @@ spec:
paths: paths:
- path: /v1/another - path: /v1/another
backend: backend:
serviceName: insomnia-api-service-0 service:
servicePort: 80 name: insomnia-api-service-0
port:
number: 80
pathType: 'ImplementationSpecific'
--- ---
apiVersion: extensions/v1beta1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: insomnia-api-2 name: insomnia-api-2
@ -497,10 +509,13 @@ spec:
paths: paths:
- path: /v2/path - path: /v2/path
backend: backend:
serviceName: insomnia-api-service-1 service:
servicePort: 80 name: insomnia-api-service-1
port:
number: 80
pathType: 'ImplementationSpecific'
--- ---
apiVersion: extensions/v1beta1 apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: insomnia-api-3 name: insomnia-api-3
@ -516,8 +531,11 @@ spec:
paths: paths:
- path: /v2/another - path: /v2/another
backend: backend:
serviceName: insomnia-api-service-1 service:
servicePort: 80 name: insomnia-api-service-1
port:
number: 80
pathType: 'ImplementationSpecific'
``` ```
</details> </details>

View File

@ -94,7 +94,7 @@ documents:
issuer: <well-known-config> issuer: <well-known-config>
scopes_required: scopes_required:
- fred_read - fred_read
- apiVersion: extensions/v1beta1 - apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: my-cloud-api-0 name: my-cloud-api-0
@ -115,10 +115,13 @@ documents:
http: http:
paths: paths:
- backend: - backend:
serviceName: my-cloud-api-service-0 service:
servicePort: 443 name: my-cloud-api-service-0
port:
number: 443
path: /v1/offline-portal path: /v1/offline-portal
- apiVersion: extensions/v1beta1 pathType: ImplementationSpecific
- apiVersion: networking.k8s.io/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: my-cloud-api-1 name: my-cloud-api-1
@ -140,6 +143,9 @@ documents:
paths: paths:
- path: /v1/user-info - path: /v1/user-info
backend: backend:
serviceName: my-cloud-api-service-0 service:
servicePort: 443 name: my-cloud-api-service-0
port:
number: 443
pathType: ImplementationSpecific
warnings: [] warnings: []

View File

@ -327,10 +327,15 @@ describe('index', () => {
paths: [ paths: [
{ {
backend: { backend: {
serviceName: 'my-ingress-service-0', service: {
servicePort: 80, name: 'my-ingress-service-0',
port: {
number: 80,
}, },
}, },
},
pathType: 'ImplementationSpecific',
},
], ],
}, },
}); });
@ -351,10 +356,15 @@ describe('index', () => {
{ {
path: '/v1/.*', path: '/v1/.*',
backend: { backend: {
serviceName: 'my-ingress-service-0', service: {
servicePort: 80, name: 'my-ingress-service-0',
port: {
number: 80,
}, },
}, },
},
pathType: 'ImplementationSpecific',
},
], ],
}, },
}); });
@ -376,10 +386,15 @@ describe('index', () => {
{ {
path: '/v1/.*/.*/path', path: '/v1/.*/.*/path',
backend: { backend: {
serviceName: 'my-ingress-service-1', service: {
servicePort: 80, name: 'my-ingress-service-1',
port: {
number: 80,
}, },
}, },
},
pathType: 'ImplementationSpecific',
},
], ],
}, },
}); });
@ -401,10 +416,15 @@ describe('index', () => {
{ {
path: '/v1/.*', path: '/v1/.*',
backend: { backend: {
serviceName: 'my-ingress-service-1', service: {
servicePort: 80, name: 'my-ingress-service-1',
port: {
number: 80,
}, },
}, },
},
pathType: 'ImplementationSpecific',
},
], ],
}, },
}); });
@ -422,10 +442,15 @@ describe('index', () => {
{ {
path: '/v1/.*', path: '/v1/.*',
backend: { backend: {
serviceName: 'my-ingress-service-1', service: {
servicePort: 80, name: 'my-ingress-service-1',
port : {
number: 80,
}, },
}, },
},
pathType: 'ImplementationSpecific',
},
], ],
}, },
}); });
@ -449,10 +474,15 @@ describe('index', () => {
{ {
path: '/v1/.*', path: '/v1/.*',
backend: { backend: {
serviceName: 'my-ingress-service-1', service: {
servicePort: 80, name: 'my-ingress-service-1',
port: {
number: 80,
}, },
}, },
},
pathType: 'ImplementationSpecific',
},
], ],
}, },
}); });
@ -476,10 +506,15 @@ describe('index', () => {
{ {
path: '/.*/v1/.*', path: '/.*/v1/.*',
backend: { backend: {
serviceName: 'my-ingress-service-1', service: {
servicePort: 80, name: 'my-ingress-service-1',
port: {
number: 80,
}, },
}, },
},
pathType: 'ImplementationSpecific',
},
], ],
}, },
}); });

View File

@ -51,7 +51,7 @@ export const generateKongForKubernetesConfigFromSpec = (api: OpenApi3Spec) => {
const rule = generateIngressRule(serverIndex, serverPlugin.server, specName, [pathPlugin.path]); const rule = generateIngressRule(serverIndex, serverPlugin.server, specName, [pathPlugin.path]);
const doc: K8sIngress = { const doc: K8sIngress = {
apiVersion: 'extensions/v1beta1', apiVersion: 'networking.k8s.io/v1',
kind: 'Ingress', kind: 'Ingress',
metadata, metadata,
spec: { spec: {
@ -159,8 +159,12 @@ export const generateIngressRule = (
const { hostname, pathname } = parseUrl(server.url); const { hostname, pathname } = parseUrl(server.url);
const pathsToUse = paths?.length ? paths : ['']; const pathsToUse = paths?.length ? paths : [''];
const backend: K8sIngressBackend = { const backend: K8sIngressBackend = {
serviceName: generateServiceName(server, specName, index), service:{
servicePort: generateServicePort(server), name: generateServiceName(server, specName, index),
port: {
number: generateServicePort(server),
},
},
}; };
const k8sPaths = pathsToUse.map((pathToUse): K8sHTTPIngressPath => { const k8sPaths = pathsToUse.map((pathToUse): K8sHTTPIngressPath => {
@ -168,6 +172,7 @@ export const generateIngressRule = (
return { return {
backend, backend,
...(path ? { path } : {}), ...(path ? { path } : {}),
pathType: 'ImplementationSpecific',
}; };
}); });
@ -211,7 +216,7 @@ export const generateTLS = (server?: OA3Server) => {
} }
if (!Array.isArray(tls)) { if (!Array.isArray(tls)) {
throw new Error('x-kubernetes-tls must be an array of IngressTLS, matching the kubernetes IngressSpec resource. see https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#ingressspec-v1beta1-extensions'); throw new Error('x-kubernetes-tls must be an array of IngressTLS, matching the kubernetes IngressSpec resource. see https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#ingressspec-v1-networking-k8s-io');
} }
return tls; return tls;

View File

@ -53,10 +53,10 @@ export const ingressDoc = (
index: number, index: number,
plugins: string[], plugins: string[],
host: string, host: string,
serviceName: string, name: string,
path?: string | null, path?: string | null,
): K8sIngress => ({ ): K8sIngress => ({
apiVersion: 'extensions/v1beta1', apiVersion: 'networking.k8s.io/v1',
kind: 'Ingress', kind: 'Ingress',
metadata: { metadata: {
annotations: { annotations: {
@ -73,10 +73,15 @@ export const ingressDoc = (
paths: [ paths: [
{ {
backend: { backend: {
serviceName, service: {
servicePort: 80, name,
port: {
number: 80,
},
},
}, },
...(path ? { path } : {}), ...(path ? { path } : {}),
pathType: 'ImplementationSpecific',
}, },
], ],
}, },
@ -90,10 +95,10 @@ export const ingressDocWithOverride = (
plugins: string[], plugins: string[],
override: string, override: string,
host: string, host: string,
serviceName: string, name: string,
path?: string | null, path?: string | null,
): K8sIngress => ({ ): K8sIngress => ({
apiVersion: 'extensions/v1beta1', apiVersion: 'networking.k8s.io/v1',
kind: 'Ingress', kind: 'Ingress',
metadata: { metadata: {
annotations: { annotations: {
@ -111,10 +116,13 @@ export const ingressDocWithOverride = (
paths: [ paths: [
{ {
backend: { backend: {
serviceName, service: {
servicePort: 80, name,
port: { number: 80 },
},
}, },
...(path ? { path } : {}), ...(path ? { path } : {}),
pathType: 'ImplementationSpecific',
}, },
], ],
}, },

View File

@ -13,7 +13,7 @@ export interface K8sOverrideAnnotation {
'konghq.com/override'?: string; 'konghq.com/override'?: string;
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#objectmeta-v1-meta then look at `annotations`. */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#objectmeta-v1-meta then look at `annotations`. */
export type K8sAnnotations = export type K8sAnnotations =
& K8sIngressClassAnnotation & K8sIngressClassAnnotation
& K8sOverrideAnnotation & K8sOverrideAnnotation
@ -21,45 +21,57 @@ export type K8sAnnotations =
& Record<string, string> & Record<string, string>
; ;
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#objectmeta-v1-meta */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#objectmeta-v1-meta */
export interface K8sMetadata { export interface K8sMetadata {
/** The unique-per-instance name used by kubernetes to track individual Kubernetes resources */ /** The unique-per-instance name used by kubernetes to track individual Kubernetes resources */
name: string; name: string;
annotations?: K8sAnnotations; annotations?: K8sAnnotations;
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#ingressbackend-v1beta1-extensions */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#ingressbackend-v1-networking-k8s-io */
export interface K8sIngressBackend { export interface K8sIngressBackend {
serviceName: string; service: K8sIngressServiceBackend;
servicePort: number;
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#httpingresspath-v1beta1-extensions */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#ingressservicebackend-v1-networking-k8s-io */
export interface K8sIngressServiceBackend {
name: string;
port: K8sServiceBackendPort;
}
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#servicebackendport-v1-networking-k8s-io */
export interface K8sServiceBackendPort {
name?: string;
number: number;
}
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#httpingresspath-v1-networking-k8s-io */
export interface K8sHTTPIngressPath { export interface K8sHTTPIngressPath {
path?: string; path?: string;
backend: K8sIngressBackend; backend: K8sIngressBackend;
pathType: string;
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#httpingressrulevalue-v1beta1-extensions */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#httpingressrulevalue-v1-networking-k8s-io */
export interface K8sHTTPIngressRuleValue { export interface K8sHTTPIngressRuleValue {
paths: K8sHTTPIngressPath[]; paths: K8sHTTPIngressPath[];
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#ingressrule-v1beta1-extensions */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#ingressrule-v1-networking-k8s-io */
export interface K8sIngressRule { export interface K8sIngressRule {
host?: string; host?: string;
http?: K8sHTTPIngressRuleValue; http?: K8sHTTPIngressRuleValue;
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#ingresstls-v1beta1-extensions */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#ingresstls-v1-networking-k8s-io */
export interface K8sIngressTLS { export interface K8sIngressTLS {
hosts?: string[]; hosts?: string[];
secretName: string; secretName: string;
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#ingressspec-v1beta1-extensions */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#ingressspec-v1-networking-k8s-io */
export interface K8sIngressSpec { export interface K8sIngressSpec {
backend?: K8sIngressBackend; defaultBackend?: K8sIngressBackend;
rules: K8sIngressRule[]; rules: K8sIngressRule[];
tls?: K8sIngressTLS[]; tls?: K8sIngressTLS[];
} }
@ -79,9 +91,9 @@ export interface K8sKongIngress extends KubernetesResource {
}; };
} }
/** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/#ingress-v1beta1-extensions */ /** see: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#ingress-v1-networking-k8s-io */
export interface K8sIngress extends KubernetesResource { export interface K8sIngress extends KubernetesResource {
apiVersion: 'extensions/v1beta1'; apiVersion: 'networking.k8s.io/v1';
kind: 'Ingress'; kind: 'Ingress';
spec: K8sIngressSpec; spec: K8sIngressSpec;
} }