Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/common/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CoreV1Api,
CustomObjectsApi,
KubeConfig,
NetworkingV1Api,
PatchStrategy,
setHeaderOptions,
V1ResourceRequirements,
Expand All @@ -21,7 +22,7 @@ import { ARGOCD_APP_PARAMS, DEPLOYMENT_PASSWORDS_SECRET, DEPLOYMENT_STATUS_CONFI
import { OtomiDebugger, terminal } from './debug'
import { env } from './envalid'
import { hfValues } from './hf'
import { getParsedArgs, parser } from './yargs'
import { parser } from './yargs'
import { askYesNo } from './zx-enhance'

export const secretId = `secret/otomi/${DEPLOYMENT_PASSWORDS_SECRET}`
Expand All @@ -31,6 +32,7 @@ let kc: KubeConfig
let coreClient: CoreV1Api
let appClient: AppsV1Api
let batchClient: BatchV1Api
let networkingClient: NetworkingV1Api
let customClient: CustomObjectsApi
export const k8s = {
kc: (): KubeConfig => {
Expand All @@ -54,6 +56,11 @@ export const k8s = {
batchClient = k8s.kc().makeApiClient(BatchV1Api)
return batchClient
},
networking: (): NetworkingV1Api => {
if (networkingClient) return networkingClient
networkingClient = k8s.kc().makeApiClient(NetworkingV1Api)
return networkingClient
},
custom: (): CustomObjectsApi => {
if (customClient) return customClient
customClient = k8s.kc().makeApiClient(CustomObjectsApi)
Expand Down
41 changes: 23 additions & 18 deletions src/common/runtime-upgrades/runtime-upgrades.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { logLevelString, OtomiDebugger } from '../debug'
import { OtomiDebugger } from '../debug'
import { applyServerSide, k8s, restartOtomiApiDeployment } from '../k8s'
import { getParsedArgs } from '../yargs'
import { detectAndRestartOutdatedIstioSidecars } from './restart-istio-sidecars'
import { upgradeKnativeServing } from './upgrade-knative-serving-cr'
import { hf, HF_DEFAULT_SYNC_ARGS } from '../hf'
import { PatchStrategy, setHeaderOptions } from '@kubernetes/client-node'
import { ApiException, PatchStrategy, setHeaderOptions } from '@kubernetes/client-node'

export interface RuntimeUpgradeContext {
debug: OtomiDebugger
Expand Down Expand Up @@ -98,22 +97,28 @@ export const runtimeUpgrades: RuntimeUpgrades = [
)
}),
)
},
applications: {
'istio-system-oauth2-proxy-artifacts': {
post: async (context: RuntimeUpgradeContext) => {
// Perform one sync as ArgoCD does not perform diffs on annotations
const d = context.debug
await hf(
{
labelOpts: ['name=oauth2-proxy-artifacts'],
logLevel: logLevelString(),
args: [...HF_DEFAULT_SYNC_ARGS, '--take-ownership'],
// Perform manual patch as ArgoCD does not perform diffs on annotations
context.debug.info("Removing obsolete annotation from Ingress 'oauth2-proxy'")
try {
await k8s.networking().patchNamespacedIngress(
{
namespace: 'istio-system',
name: 'oauth2-proxy',
body: {
metadata: {
'nginx.ingress.kubernetes.io/configuration-snippet': null,
},
},
{ streams: { stdout: d.stream.log, stderr: d.stream.error } },
)
},
},
},
setHeaderOptions('Content-Type', PatchStrategy.StrategicMergePatch),
)
} catch (error) {
if (error instanceof ApiException && error.code === 404) {
context.debug.info("Ingress 'oauth2-proxy' not found, patch not required")
} else {
context.debug.error("Failed to patch ingress 'oauth2-proxy'", error)
}
}
},
},
]
Loading