Skip to content

Commit

Permalink
fix: k8s errors with new deprecated imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderMatt committed Nov 1, 2024
1 parent 853e3d7 commit 2bf98a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
CoreV1Api,
KubeConfig,
NetworkingV1beta1Api,
NetworkingV1Api,
V1ObjectMeta,
V1Secret,
V1ServiceAccount,
Expand All @@ -13,7 +13,7 @@ import { findIndex, mapValues } from 'lodash'

let kc: KubeConfig
let coreClient: CoreV1Api
let networkingClient: NetworkingV1beta1Api
let networkingClient: NetworkingV1Api

export const k8s = {
kc: (): KubeConfig => {
Expand All @@ -27,9 +27,9 @@ export const k8s = {
coreClient = k8s.kc().makeApiClient(CoreV1Api)
return coreClient
},
networking: (): NetworkingV1beta1Api => {
networking: (): NetworkingV1Api => {
if (networkingClient) return networkingClient
networkingClient = k8s.kc().makeApiClient(NetworkingV1beta1Api)
networkingClient = k8s.kc().makeApiClient(NetworkingV1Api)
return networkingClient
},
}
Expand Down Expand Up @@ -128,9 +128,19 @@ export async function createK8sSecret({
const idx = findIndex(sa.imagePullSecrets, { name })
if (idx === -1) {
sa.imagePullSecrets.push({ name })
await client.patchNamespacedServiceAccount('default', namespace, sa, undefined, undefined, undefined, undefined, {
headers: { 'content-type': 'application/strategic-merge-patch+json' },
})
await client.patchNamespacedServiceAccount(
'default',
namespace,
sa,
undefined,
undefined,
undefined,
undefined,
undefined,
{
headers: { 'content-type': 'application/strategic-merge-patch+json' },
},
)
}
}

Expand Down Expand Up @@ -196,9 +206,19 @@ export async function deleteSecret(namespace: string, name: string): Promise<voi
const idx = findIndex(sa.imagePullSecrets, { name })
if (idx > -1) {
sa.imagePullSecrets!.splice(idx, 1)
await client.patchNamespacedServiceAccount('default', namespace, sa, undefined, undefined, undefined, undefined, {
headers: { 'content-type': 'application/strategic-merge-patch+json' },
})
await client.patchNamespacedServiceAccount(
'default',
namespace,
sa,
undefined,
undefined,
undefined,
undefined,
undefined,
{
headers: { 'content-type': 'application/strategic-merge-patch+json' },
},
)
}
try {
await client.deleteNamespacedSecret(name, namespace)
Expand Down
1 change: 1 addition & 0 deletions src/operator/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class MyOperator extends Operator {
undefined,
undefined,
undefined,
undefined,
{ headers },
)
console.debug(
Expand Down

0 comments on commit 2bf98a9

Please sign in to comment.