-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
che #9062: Adding property for setting pod termination grace period f…
…or Kubernetes / OpenShift infrastructures Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
- Loading branch information
Showing
6 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...e/workspace/infrastructure/kubernetes/provision/PodTerminationGracePeriodProvisioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.provision; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; | ||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment; | ||
|
||
public class PodTerminationGracePeriodProvisioner implements ConfigurationProvisioner { | ||
private final long graceTerminationPeriodSec; | ||
|
||
@Inject | ||
public PodTerminationGracePeriodProvisioner( | ||
@Named("che.infra.kubernetes.pod.termination_grace_period_sec") | ||
long graceTerminationPeriodSec) { | ||
this.graceTerminationPeriodSec = graceTerminationPeriodSec; | ||
} | ||
|
||
@Override | ||
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) | ||
throws InfrastructureException { | ||
for (Pod pod : k8sEnv.getPods().values()) { | ||
if (!isTerminationGracePeriodSet(pod)) { | ||
pod.getSpec().setTerminationGracePeriodSeconds(graceTerminationPeriodSec); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param pod | ||
* @return true if 'terminationGracePeriodSeconds' have been explicitly set in Kubernetes / | ||
* OpenShift recipe, false otherwise | ||
*/ | ||
private boolean isTerminationGracePeriodSet(final Pod pod) { | ||
return pod.getSpec().getTerminationGracePeriodSeconds() != null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters