Skip to content

Commit

Permalink
Fix splunk undeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
mkralik3 committed Feb 15, 2023
1 parent 4508034 commit 07dbc39
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
* For services which have can have more configurations for deployment.
* <p>
* WARNING: It is not recommended to use ConfigurableService with ReusableOpenshiftDeployable!
* When some service can have more deployment configuration in the one test run, it should not been long-running (ReusableOpenshiftDeployable)
* because mostly it cannot be installed two same service in the one namespace.
* @param <C> Service configuration class
*/
public abstract class ConfigurableService<C extends ServiceConfiguration> implements Service {
private final C configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ServiceConfiguration {
private final Map<String, Object> configuration = new HashMap<>();
Expand All @@ -14,4 +15,21 @@ protected <T> T get(String key, Class<T> clazz) {
final Object value = configuration.get(key);
return value == null ? null : clazz.cast(value);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ServiceConfiguration that = (ServiceConfiguration) o;
return Objects.equals(configuration, that.configuration);
}

@Override
public int hashCode() {
return Objects.hash(configuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.LinkedList;
import java.util.List;

import cz.xtf.core.openshift.OpenShiftWaiters;
import cz.xtf.core.openshift.helpers.ResourceFunctions;
import io.fabric8.kubernetes.api.model.ContainerPort;
import io.fabric8.kubernetes.api.model.ContainerPortBuilder;
Expand Down Expand Up @@ -105,6 +106,8 @@ public void undeploy() {
OpenshiftClient.get().services().withName(name()).delete();
OpenshiftClient.get().apps().deployments().withName(name()).delete();
OpenshiftClient.get().persistentVolumeClaims().withName(name()).delete();
OpenShiftWaiters.get(OpenshiftClient.get(), () -> false).areNoPodsPresent(OpenshiftConfiguration.openshiftDeploymentLabel(), name())
.timeout(120_000).waitFor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package software.tnb.splunk.resource.openshift;

import software.tnb.common.account.AccountFactory;
import software.tnb.common.deployment.ReusableOpenshiftDeployable;
import software.tnb.common.deployment.OpenshiftDeployable;
import software.tnb.common.openshift.OpenshiftClient;
import software.tnb.common.utils.HTTPUtils;
import software.tnb.common.utils.WaitUtils;
Expand All @@ -26,6 +26,7 @@
import java.util.Objects;
import java.util.stream.Collectors;

import cz.xtf.core.openshift.OpenShiftWaiters;
import cz.xtf.core.openshift.helpers.ResourceParsers;
import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.api.model.HasMetadata;
Expand All @@ -38,7 +39,7 @@
import io.fabric8.openshift.api.model.RouteBuilder;

@AutoService(Splunk.class)
public class OpenshiftSplunk extends Splunk implements ReusableOpenshiftDeployable {
public class OpenshiftSplunk extends Splunk implements OpenshiftDeployable {
private static final Logger LOG = LoggerFactory.getLogger(OpenshiftSplunk.class);
private static final String CRD_API = "v4";
private static final String SERVICE_NAME = "splunk-s1-standalone-service";
Expand Down Expand Up @@ -124,6 +125,7 @@ public void undeploy() {
//if CR creates PVC's, they need to be deleted. (usage of the finalizer in CR can in some situations (e.g. failure during operator
// creation) cause the deletion of CR get stuck)
OpenshiftClient.get().persistentVolumeClaims().withLabel("app.kubernetes.io/name", "standalone").delete();
OpenShiftWaiters.get(OpenshiftClient.get(), () -> false).areNoPodsPresent("name", "splunk-operator").timeout(120_000).waitFor();
}

@Override
Expand Down Expand Up @@ -193,19 +195,6 @@ private boolean isAppDeployed() {
return pods.size() == 1 && ResourceParsers.isPodReady(pods.get(0));
}

@Override
public void cleanup() {
for (String customIndex : client().getIndexes().keySet()) {
try {
client().getIndexes().remove(customIndex);
} catch (com.splunk.HttpException ex) { // ignore when internal or disabled indexes are not deleted.
if (!(ex.getDetail().contains("is internal") || ex.getDetail().contains("is disabled"))) {
throw ex;
}
}
}
}

@Override
public String externalHostname() {
return apiRoute.getSpec().getHost();
Expand Down

0 comments on commit 07dbc39

Please sign in to comment.