Skip to content

Commit

Permalink
improve kube methods
Browse files Browse the repository at this point in the history
Signed-off-by: Flavius Lacatusu <[email protected]>
  • Loading branch information
flacatus committed Feb 17, 2021
1 parent 8f72e52 commit 192dd2c
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,30 +429,42 @@ export class KubeHelper {
async roleBindingExist(name = '', namespace = ''): Promise<boolean> {
const k8sRbacAuthApi = KubeHelper.KUBE_CONFIG.makeApiClient(RbacAuthorizationV1Api)
try {
const { body } = await k8sRbacAuthApi.readNamespacedRoleBinding(name, namespace)
return this.compare(body, name)
} catch {
return false
await k8sRbacAuthApi.readNamespacedRoleBinding(name, namespace)
return true
} catch (e) {
if (e.response.statusCode === 404) {
return false
}

throw this.wrapK8sClientError(e)
}
}

async isMutatingWebhookConfigurationExists(name: string): Promise<boolean> {
const k8sAdmissionApi = KubeHelper.KUBE_CONFIG.makeApiClient(AdmissionregistrationV1Api)
try {
const { body } = await k8sAdmissionApi.readMutatingWebhookConfiguration(name)
return this.compare(body, name)
} catch {
return false
await k8sAdmissionApi.readMutatingWebhookConfiguration(name)
return true
} catch (e) {
if (e.response.statusCode === 404) {
return false
}

throw this.wrapK8sClientError(e)
}
}

async isValidatingWebhookConfigurationExists(name: string): Promise<boolean> {
const k8sAdmissionApi = KubeHelper.KUBE_CONFIG.makeApiClient(AdmissionregistrationV1Api)
try {
const { body } = await k8sAdmissionApi.readValidatingWebhookConfiguration(name)
return this.compare(body, name)
} catch {
return false
await k8sAdmissionApi.readValidatingWebhookConfiguration(name)
return true
} catch (e) {
if (e.response.statusCode === 404) {
return false
}

throw this.wrapK8sClientError(e)
}
}

Expand Down Expand Up @@ -981,10 +993,14 @@ export class KubeHelper {
async isConfigMapExists(name: string, namespace: string): Promise<boolean> {
const k8sApi = KubeHelper.KUBE_CONFIG.makeApiClient(CoreV1Api)
try {
const { body } = await k8sApi.readNamespacedConfigMap(name, namespace)
return this.compare(body, name)
} catch {
return false
await k8sApi.readNamespacedConfigMap(name, namespace)
return true
} catch (e) {
if (e.response.statusCode === 404) {
return false
}

throw this.wrapK8sClientError(e)
}
}

Expand Down Expand Up @@ -1440,10 +1456,14 @@ export class KubeHelper {
async isCRDV1Exists(name: string): Promise<boolean> {
const k8sApiextensionsApi = KubeHelper.KUBE_CONFIG.makeApiClient(ApiextensionsV1Api)
try {
const { body } = await k8sApiextensionsApi.readCustomResourceDefinition(name)
return this.compare(body, name)
} catch {
return false
await k8sApiextensionsApi.readCustomResourceDefinition(name)
return true
} catch (e) {
if (e.response.statusCode === 404) {
return false
}

throw this.wrapK8sClientError(e)
}
}

Expand Down

0 comments on commit 192dd2c

Please sign in to comment.