Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update che-operator in a different namespace than eclipse-che #2865

Merged
merged 1 commit into from
Mar 29, 2024
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
20 changes: 8 additions & 12 deletions src/api/kube-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,24 +951,20 @@ export class KubeClient {
}
}

async replaceDeployment(deployment: V1Deployment): Promise<void> {
// updating restartedAt to make sure that rollout will be restarted
let annotations = deployment.spec!.template!.metadata!.annotations
if (!annotations) {
annotations = {}
deployment.spec!.template!.metadata!.annotations = annotations
}
async replaceDeployment(name: string, deployment: V1Deployment, namespace: string): Promise<void> {
const k8sAppsApi = this.kubeConfig.makeApiClient(AppsV1Api)

annotations['kubectl.kubernetes.io/restartedAt'] = new Date().toISOString()
deployment.spec!.template!.metadata!.annotations = deployment.spec!.template!.metadata!.annotations || {}
deployment.spec!.template!.metadata!.annotations['kubectl.kubernetes.io/restartedAt'] = new Date().toISOString()
delete deployment.metadata?.namespace

const k8sAppsApi = this.kubeConfig.makeApiClient(AppsV1Api)
try {
await k8sAppsApi.replaceNamespacedDeployment(deployment.metadata!.name!, deployment.metadata!.namespace!, deployment)
await k8sAppsApi.replaceNamespacedDeployment(name, namespace, deployment)
} catch (e: any) {
if (e.response && e.response.body && e.response.body.message && e.response.body.message.toString().endsWith('field is immutable')) {
try {
await k8sAppsApi.deleteNamespacedDeployment(deployment.metadata!.name!, deployment.metadata!.namespace!)
await k8sAppsApi.createNamespacedDeployment(deployment.metadata!.namespace!, deployment)
await k8sAppsApi.deleteNamespacedDeployment(name, namespace)
await k8sAppsApi.createNamespacedDeployment(namespace, deployment)
} catch (e: any) {
throw this.wrapK8sClientError(e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/installers/eclipse-che/eclipse-che-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export namespace EclipseCheTasks {
EclipseChe.OPERATOR_DEPLOYMENT_NAME,
() => kubeHelper.isDeploymentExist(EclipseChe.OPERATOR_DEPLOYMENT_NAME, flags[CHE_NAMESPACE_FLAG]),
() => kubeHelper.createDeployment(deployment, flags[CHE_NAMESPACE_FLAG]),
() => kubeHelper.replaceDeployment(deployment))
() => kubeHelper.replaceDeployment(EclipseChe.OPERATOR_DEPLOYMENT_NAME, deployment, flags[CHE_NAMESPACE_FLAG]))
}

export function getCreateOrUpdateCrdTask(isCreateOnly: boolean): Listr.ListrTask<any> {
Expand Down
Loading