Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import io.kubernetes.client.custom.V1Patch;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
Expand All @@ -40,7 +39,6 @@
import io.kubernetes.client.openapi.apis.RbacAuthorizationV1Api;
import io.kubernetes.client.openapi.models.V1APIService;
import io.kubernetes.client.openapi.models.V1ClusterRole;
import io.kubernetes.client.openapi.models.V1ClusterRoleBinding;
import io.kubernetes.client.openapi.models.V1ConfigMap;
import io.kubernetes.client.openapi.models.V1Deployment;
import io.kubernetes.client.openapi.models.V1DeploymentCondition;
Expand All @@ -55,7 +53,6 @@
import io.kubernetes.client.openapi.models.V1Service;
import io.kubernetes.client.openapi.models.V1ServiceAccount;
import io.kubernetes.client.util.Config;
import io.kubernetes.client.util.PatchUtils;
import io.kubernetes.client.util.Yaml;
import jakarta.annotation.Nullable;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -335,49 +332,6 @@ public void setUp(String namespace) {

}

public void setUpClusterWideClusterRoleBinding(String serviceAccountNamespace) {

try {
V1ServiceAccount serviceAccount = (V1ServiceAccount) yaml("cluster/service-account.yaml");
CheckedSupplier<V1ServiceAccount> accountSupplier = () -> coreV1Api
.readNamespacedServiceAccount(serviceAccount.getMetadata().getName(), serviceAccountNamespace, null);
CheckedSupplier<V1ServiceAccount> accountDefaulter = () -> coreV1Api
.createNamespacedServiceAccount(serviceAccountNamespace, serviceAccount, null, null, null, null);
notExistsHandler(accountSupplier, accountDefaulter);

V1ClusterRole clusterRole = (V1ClusterRole) yaml("cluster/cluster-role.yaml");
notExistsHandler(() -> rbacApi.readClusterRole(clusterRole.getMetadata().getName(), null),
() -> rbacApi.createClusterRole(clusterRole, null, null, null, null));

V1ClusterRoleBinding clusterRoleBinding = (V1ClusterRoleBinding) yaml("cluster/cluster-role-binding.yaml");
notExistsHandler(() -> rbacApi.readClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null),
() -> rbacApi.createClusterRoleBinding(clusterRoleBinding, null, null, null, null));
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}

}

public void deleteClusterWideClusterRoleBinding(String serviceAccountNamespace) {
try {
V1ServiceAccount serviceAccount = (V1ServiceAccount) yaml("cluster/service-account.yaml");
V1ClusterRole clusterRole = (V1ClusterRole) yaml("cluster/cluster-role.yaml");
V1ClusterRoleBinding clusterRoleBinding = (V1ClusterRoleBinding) yaml("cluster/cluster-role-binding.yaml");

coreV1Api.deleteNamespacedServiceAccount(serviceAccount.getMetadata().getName(), serviceAccountNamespace,
null, null, null, null, null, null);
rbacApi.deleteClusterRole(clusterRole.getMetadata().getName(), null, null, null, null, null, null);
rbacApi.deleteClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null, null, null, null, null,
null);
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

public void setUpClusterWide(String serviceAccountNamespace, Set<String> namespaces) {

try {
Expand Down Expand Up @@ -517,41 +471,6 @@ public void wiremock(String namespace, String path, Phase phase, boolean withIng

}

public static void patchWithMerge(String deploymentName, String namespace, String patchBody,
Map<String, String> podLabels) {
try {
PatchUtils.patch(V1Deployment.class,
() -> new AppsV1Api().patchNamespacedDeploymentCall(deploymentName, namespace,
new V1Patch(patchBody), null, null, null, null, null, null),
V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, new CoreV1Api().getApiClient());
}
catch (ApiException e) {
LOG.error("error : " + e.getResponseBody());
throw new RuntimeException(e);
}

waitForDeploymentAfterPatch(deploymentName, namespace, podLabels);
}

public static void patchWithReplace(String imageName, String deploymentName, String namespace, String patchBody,
Map<String, String> podLabels) {
String body = patchBody.replace("image_name_here", imageName);

try {
PatchUtils.patch(V1Deployment.class,
() -> new AppsV1Api().patchNamespacedDeploymentCall(deploymentName, namespace, new V1Patch(body),
null, null, null, null, null, null),
V1Patch.PATCH_FORMAT_JSON_MERGE_PATCH, new CoreV1Api().getApiClient());
}
catch (ApiException e) {
LOG.error("error : " + e.getResponseBody());
throw new RuntimeException(e);
}

waitForDeploymentAfterPatch(deploymentName, namespace, podLabels);

}

private String deploymentName(V1Deployment deployment) {
return deployment.getMetadata().getName();
}
Expand Down
Loading