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
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: insomnia-api-1
@ -271,10 +271,13 @@ spec:
paths:
- path: /v1/.*
backend:
serviceName: insomnia-api-service-0
servicePort: 80
service:
name: insomnia-api-service-0
port:
number: 80
pathType: 'ImplementationSpecific'
---
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: insomnia-api-2
@ -287,8 +290,11 @@ spec:
paths:
- path: /v2/.*
backend:
serviceName: insomnia-api-service-1
servicePort: 80
service:
name: insomnia-api-service-1
port:
number: 80
pathType: 'ImplementationSpecific'
```
</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:
```yaml
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: insomnia-api
@ -445,7 +451,7 @@ config:
key_in_body: false
hide_credentials: true
---
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: insomnia-api-0
@ -460,10 +466,13 @@ spec:
paths:
- path: /v1/path
backend:
serviceName: insomnia-api-service-0
servicePort: 80
service:
name: insomnia-api-service-0
port:
number: 80
pathType: 'ImplementationSpecific'
---
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: insomnia-api-1
@ -479,10 +488,13 @@ spec:
paths:
- path: /v1/another
backend:
serviceName: insomnia-api-service-0
servicePort: 80
service:
name: insomnia-api-service-0
port:
number: 80
pathType: 'ImplementationSpecific'
---
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: insomnia-api-2
@ -497,10 +509,13 @@ spec:
paths:
- path: /v2/path
backend:
serviceName: insomnia-api-service-1
servicePort: 80
service:
name: insomnia-api-service-1
port:
number: 80
pathType: 'ImplementationSpecific'
---
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: insomnia-api-3
@ -516,8 +531,11 @@ spec:
paths:
- path: /v2/another
backend:
serviceName: insomnia-api-service-1
servicePort: 80
service:
name: insomnia-api-service-1
port:
number: 80
pathType: 'ImplementationSpecific'
```
</details>

View File

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

View File

@ -327,10 +327,15 @@ describe('index', () => {
paths: [
{
backend: {
serviceName: 'my-ingress-service-0',
servicePort: 80,
service: {
name: 'my-ingress-service-0',
port: {
number: 80,
},
},
},
pathType: 'ImplementationSpecific',
},
],
},
});
@ -351,10 +356,15 @@ describe('index', () => {
{
path: '/v1/.*',
backend: {
serviceName: 'my-ingress-service-0',
servicePort: 80,
service: {
name: 'my-ingress-service-0',
port: {
number: 80,
},
},
},
pathType: 'ImplementationSpecific',
},
],
},
});
@ -376,10 +386,15 @@ describe('index', () => {
{
path: '/v1/.*/.*/path',
backend: {
serviceName: 'my-ingress-service-1',
servicePort: 80,
service: {
name: 'my-ingress-service-1',
port: {
number: 80,
},
},
},
pathType: 'ImplementationSpecific',
},
],
},
});
@ -401,10 +416,15 @@ describe('index', () => {
{
path: '/v1/.*',
backend: {
serviceName: 'my-ingress-service-1',
servicePort: 80,
service: {
name: 'my-ingress-service-1',
port: {
number: 80,
},
},
},
pathType: 'ImplementationSpecific',
},
],
},
});
@ -422,10 +442,15 @@ describe('index', () => {
{
path: '/v1/.*',
backend: {
serviceName: 'my-ingress-service-1',
servicePort: 80,
service: {
name: 'my-ingress-service-1',
port : {
number: 80,
},
},
},
pathType: 'ImplementationSpecific',
},
],
},
});
@ -449,10 +474,15 @@ describe('index', () => {
{
path: '/v1/.*',
backend: {
serviceName: 'my-ingress-service-1',
servicePort: 80,
service: {
name: 'my-ingress-service-1',
port: {
number: 80,
},
},
},
pathType: 'ImplementationSpecific',
},
],
},
});
@ -476,10 +506,15 @@ describe('index', () => {
{
path: '/.*/v1/.*',
backend: {
serviceName: 'my-ingress-service-1',
servicePort: 80,
service: {
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 doc: K8sIngress = {
apiVersion: 'extensions/v1beta1',
apiVersion: 'networking.k8s.io/v1',
kind: 'Ingress',
metadata,
spec: {
@ -159,8 +159,12 @@ export const generateIngressRule = (
const { hostname, pathname } = parseUrl(server.url);
const pathsToUse = paths?.length ? paths : [''];
const backend: K8sIngressBackend = {
serviceName: generateServiceName(server, specName, index),
servicePort: generateServicePort(server),
service:{
name: generateServiceName(server, specName, index),
port: {
number: generateServicePort(server),
},
},
};
const k8sPaths = pathsToUse.map((pathToUse): K8sHTTPIngressPath => {
@ -168,6 +172,7 @@ export const generateIngressRule = (
return {
backend,
...(path ? { path } : {}),
pathType: 'ImplementationSpecific',
};
});
@ -211,7 +216,7 @@ export const generateTLS = (server?: OA3Server) => {
}
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;

View File

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

View File

@ -13,7 +13,7 @@ export interface K8sOverrideAnnotation {
'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 =
& K8sIngressClassAnnotation
& K8sOverrideAnnotation
@ -21,45 +21,57 @@ export type K8sAnnotations =
& 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 {
/** The unique-per-instance name used by kubernetes to track individual Kubernetes resources */
name: string;
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 {
serviceName: string;
servicePort: number;
service: K8sIngressServiceBackend;
}
/** 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 {
path?: string;
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 {
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 {
host?: string;
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 {
hosts?: 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 {
backend?: K8sIngressBackend;
defaultBackend?: K8sIngressBackend;
rules: K8sIngressRule[];
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 {
apiVersion: 'extensions/v1beta1';
apiVersion: 'networking.k8s.io/v1';
kind: 'Ingress';
spec: K8sIngressSpec;
}