Skip to content

Commit

Permalink
Use networking/v1 api (#1632)
Browse files Browse the repository at this point in the history
* fix: Use networking/v1 api

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha authored Sep 8, 2021
1 parent 8dbe3cb commit 731f31c
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 345 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"bugs": "https://github.com/che-incubator/chectl/issues",
"dependencies": {
"@kubernetes/client-node": "0.12.1",
"@kubernetes/client-node": "0.14.3",
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/parser": "^3.8.5",
Expand Down
30 changes: 15 additions & 15 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/

import { AdmissionregistrationV1Api, ApiextensionsV1Api, ApiextensionsV1beta1Api, ApisApi, AppsV1Api, AuthorizationV1Api, BatchV1Api, CoreV1Api, CustomObjectsApi, ExtensionsV1beta1Api, ExtensionsV1beta1IngressList, KubeConfig, Log, PortForward, RbacAuthorizationV1Api, V1ClusterRole, V1ClusterRoleBinding, V1ClusterRoleBindingList, V1ConfigMap, V1ConfigMapEnvSource, V1Container, V1ContainerStateTerminated, V1ContainerStateWaiting, V1Deployment, V1DeploymentList, V1DeploymentSpec, V1EnvFromSource, V1Job, V1JobSpec, V1LabelSelector, V1MutatingWebhookConfiguration, V1Namespace, V1NamespaceList, V1ObjectMeta, V1PersistentVolumeClaimList, V1Pod, V1PodCondition, V1PodList, V1PodSpec, V1PodTemplateSpec, V1PolicyRule, V1Role, V1RoleBinding, V1RoleBindingList, V1RoleList, V1RoleRef, V1Secret, V1SelfSubjectAccessReview, V1SelfSubjectAccessReviewSpec, V1Service, V1ServiceAccount, V1ServiceList, V1Subject, Watch } from '@kubernetes/client-node'
import { AdmissionregistrationV1Api, ApiextensionsV1Api, ApiextensionsV1beta1Api, ApisApi, AppsV1Api, AuthorizationV1Api, BatchV1Api, CoreV1Api, CustomObjectsApi, KubeConfig, Log, NetworkingV1Api, PortForward, RbacAuthorizationV1Api, V1ClusterRole, V1ClusterRoleBinding, V1ClusterRoleBindingList, V1ConfigMap, V1ConfigMapEnvSource, V1Container, V1ContainerStateTerminated, V1ContainerStateWaiting, V1Deployment, V1DeploymentList, V1DeploymentSpec, V1EnvFromSource, V1IngressList, V1Job, V1JobSpec, V1LabelSelector, V1MutatingWebhookConfiguration, V1Namespace, V1NamespaceList, V1ObjectMeta, V1PersistentVolumeClaimList, V1Pod, V1PodCondition, V1PodList, V1PodSpec, V1PodTemplateSpec, V1PolicyRule, V1Role, V1RoleBinding, V1RoleBindingList, V1RoleList, V1RoleRef, V1Secret, V1SelfSubjectAccessReview, V1SelfSubjectAccessReviewSpec, V1Service, V1ServiceAccount, V1ServiceList, V1Subject, Watch } from '@kubernetes/client-node'
import { Cluster, Context } from '@kubernetes/client-node/dist/config_types'
import axios, { AxiosRequestConfig } from 'axios'
import { cli } from 'cli-ux'
Expand Down Expand Up @@ -1379,20 +1379,20 @@ export class KubeHelper {
}
}

async ingressExist(name = '', namespace = ''): Promise<boolean> {
const k8sExtensionsApi = this.kubeConfig.makeApiClient(ExtensionsV1beta1Api)
async ingressExist(name: string, namespace: string): Promise<boolean> {
const networkingV1Api = this.kubeConfig.makeApiClient(NetworkingV1Api)
try {
const { body } = await k8sExtensionsApi.readNamespacedIngress(name, namespace)
const { body } = await networkingV1Api.readNamespacedIngress(name, namespace)
return this.compare(body, name)
} catch {
return false
}
}

async deleteAllIngresses(namespace: string): Promise<void> {
const k8sExtensionsApi = this.kubeConfig.makeApiClient(ExtensionsV1beta1Api)
const networkingV1Api = this.kubeConfig.makeApiClient(NetworkingV1Api)
try {
await k8sExtensionsApi.deleteCollectionNamespacedIngress(namespace)
await networkingV1Api.deleteCollectionNamespacedIngress(namespace)
} catch (e) {
throw this.wrapK8sClientError(e)
}
Expand Down Expand Up @@ -2453,10 +2453,10 @@ export class KubeHelper {
}
}

async getIngressHost(name = '', namespace = ''): Promise<string> {
const k8sExtensionsApi = this.kubeConfig.makeApiClient(ExtensionsV1beta1Api)
async getIngressHost(name: string, namespace: string): Promise<string> {
const networkingV1Api = this.kubeConfig.makeApiClient(NetworkingV1Api)
try {
const res = await k8sExtensionsApi.readNamespacedIngress(name, namespace)
const res = await networkingV1Api.readNamespacedIngress(name, namespace)
if (res && res.body &&
res.body.spec &&
res.body.spec.rules &&
Expand All @@ -2469,10 +2469,10 @@ export class KubeHelper {
}
}

async getIngressProtocol(name = '', namespace = ''): Promise<string> {
const k8sExtensionsApi = this.kubeConfig.makeApiClient(ExtensionsV1beta1Api)
async getIngressProtocol(name: string, namespace: string): Promise<string> {
const networkingV1Api = this.kubeConfig.makeApiClient(NetworkingV1Api)
try {
const res = await k8sExtensionsApi.readNamespacedIngress(name, namespace)
const res = await networkingV1Api.readNamespacedIngress(name, namespace)
if (!res || !res.body || !res.body.spec) {
throw new Error('ERR_INGRESS_NO_HOST')
}
Expand All @@ -2486,10 +2486,10 @@ export class KubeHelper {
}
}

async getIngressesBySelector(labelSelector = '', namespace = ''): Promise<ExtensionsV1beta1IngressList> {
const k8sV1Beta = this.kubeConfig.makeApiClient(ExtensionsV1beta1Api)
async getIngressesBySelector(labelSelector: string, namespace: string): Promise<V1IngressList> {
const networkingV1Api = this.kubeConfig.makeApiClient(NetworkingV1Api)
try {
const res = await k8sV1Beta.listNamespacedIngress(namespace, 'true', undefined, undefined, undefined, labelSelector)
const res = await networkingV1Api.listNamespacedIngress(namespace, 'true', undefined, undefined, undefined, labelSelector)
if (res && res.body) {
return res.body
}
Expand Down
10 changes: 5 additions & 5 deletions src/commands/devfile/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Red Hat, Inc. - initial API and implementation
*/

import { ExtensionsV1beta1Ingress, V1Deployment, V1DeploymentSpec, V1ObjectMeta, V1PersistentVolumeClaim, V1PersistentVolumeClaimSpec, V1PodTemplateSpec, V1Service, V1ServicePort, V1ServiceSpec } from '@kubernetes/client-node'
import { V1Deployment, V1DeploymentSpec, V1Ingress, V1ObjectMeta, V1PersistentVolumeClaim, V1PersistentVolumeClaimSpec, V1PodTemplateSpec, V1Service, V1ServicePort, V1ServiceSpec } from '@kubernetes/client-node'
import { Command, flags } from '@oclif/command'
import { string } from '@oclif/parser/lib/flags'
import * as yaml from 'js-yaml'
Expand Down Expand Up @@ -315,14 +315,14 @@ export default class Generate extends Command {
return items
}

private async getIngressesBySelector(labelSelector: string, namespace = ''): Promise<Array<ExtensionsV1beta1Ingress>> {
const items = new Array<ExtensionsV1beta1Ingress>()
private async getIngressesBySelector(labelSelector: string, namespace = ''): Promise<Array<V1Ingress>> {
const items = new Array<V1Ingress>()

const k8sIngressesList = await kube.getIngressesBySelector(labelSelector, namespace)
k8sIngressesList.items.forEach(async item => {
const ingress = new ExtensionsV1beta1Ingress()
const ingress = new V1Ingress()
ingress.kind = 'Ingress'
ingress.apiVersion = 'extensions/v1beta1'
ingress.apiVersion = 'networking/v1'
ingress.metadata = new V1ObjectMeta()
ingress.metadata.labels = { ...item.metadata!.labels }
ingress.metadata.name = item.metadata!.name
Expand Down
Loading

0 comments on commit 731f31c

Please sign in to comment.