Skip to content

Commit

Permalink
update kubernetes-client version to 5.12.1 (#1722)
Browse files Browse the repository at this point in the history
update kubernetes-client version
  • Loading branch information
kyoppii13 authored Jul 19, 2022
1 parent 46d7507 commit c3e6cea
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 33 deletions.
2 changes: 1 addition & 1 deletion digdag-standards/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
}

// kubernetes
compile ('io.fabric8:kubernetes-client:4.6.2') {
compile ('io.fabric8:kubernetes-client:5.12.1') {
// Avoid compilation failures due to dependencies
exclude group: 'org.slf4j', module: 'slf4j-api'
// TODO: digdag use version 3.12.0, upgrade to version 3.12.6.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
import io.fabric8.kubernetes.api.model.ContainerStatus;
import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.EnvVarBuilder;
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.PodSpec;
import io.fabric8.kubernetes.api.model.PodSpecBuilder;
import io.fabric8.kubernetes.api.model.ResourceRequirements;
import io.fabric8.kubernetes.api.model.Toleration;
import io.fabric8.kubernetes.api.model.Volume;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.api.model.PersistentVolume;
import io.fabric8.kubernetes.api.model.PersistentVolumeBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeSpec;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec;
import io.fabric8.kubernetes.client.dsl.PodResource;
import io.fabric8.kubernetes.client.utils.Serialization;
Expand Down Expand Up @@ -68,15 +71,16 @@ public Pod runPod(final CommandContext context, final CommandRequest request,
final Config kubernetesPodConfig = extractTargetKindConfig(context, "Pod");
final Container container = createContainer(context, request, kubernetesPodConfig, name, commands, arguments);
final PodSpec podSpec = createPodSpec(context, request, kubernetesPodConfig, container);
io.fabric8.kubernetes.api.model.Pod pod = client.pods()
.createNew()
.withNewMetadata()
.withName(name)
.withNamespace(client.getNamespace())
.withLabels(getPodLabels())
.endMetadata()
.withSpec(podSpec)
.done();
final io.fabric8.kubernetes.api.model.Pod pod = client.pods().inNamespace(client.getNamespace()).create(
new PodBuilder()
.withNewMetadata()
.withName(name)
.withLabels(getPodLabels())
.withNamespace(client.getNamespace())
.endMetadata()
.withSpec(podSpec)
.build()
);
return Pod.of(pod);
}

Expand Down Expand Up @@ -180,13 +184,15 @@ protected PersistentVolume createPersistentVolume(final CommandContext context)
final Config kubernetesPvConfig = extractTargetKindConfig(context, "PersistentVolume");
if (kubernetesPvConfig != null && kubernetesPvConfig.has("spec"))
return client.persistentVolumes()
.createOrReplaceWithNew()
.withNewMetadata()
.withName(kubernetesPvConfig.get("name", String.class))
.withNamespace(client.getNamespace())
.endMetadata()
.withSpec(getPersistentVolume(kubernetesPvConfig.get("spec", Config.class)))
.done();
.createOrReplace(
new PersistentVolumeBuilder()
.withNewMetadata()
.withName(kubernetesPvConfig.get("name", String.class))
.withNamespace(client.getNamespace())
.endMetadata()
.withSpec(getPersistentVolume(kubernetesPvConfig.get("spec", Config.class)))
.build()
);
else
return null;
}
Expand All @@ -196,13 +202,16 @@ protected PersistentVolumeClaim createPersistentVolumeClaim(final CommandContext
final Config kubernetesPvcConfig = extractTargetKindConfig(context, "PersistentVolumeClaim");
if (kubernetesPvcConfig != null && kubernetesPvcConfig.has("spec"))
return client.persistentVolumeClaims()
.createOrReplaceWithNew()
.withNewMetadata()
.withName(kubernetesPvcConfig.get("name", String.class))
.withNamespace(client.getNamespace())
.endMetadata()
.withSpec(getPersistentVolumeClaim(kubernetesPvcConfig.get("spec", Config.class)))
.done();
.createOrReplace(
new PersistentVolumeClaimBuilder()
.withNewMetadata()
.withName(kubernetesPvcConfig.get("name", String.class))
.withNamespace(client.getNamespace())
.endMetadata()
.withSpec(getPersistentVolumeClaim(kubernetesPvcConfig.get("spec", Config.class)))
.build()

);
else
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
import io.fabric8.kubernetes.api.model.AffinityBuilder;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerBuilder;
import io.fabric8.kubernetes.api.model.EmptyDirVolumeSource;
import io.fabric8.kubernetes.api.model.NodeAffinityBuilder;
import io.fabric8.kubernetes.api.model.NodeSelectorBuilder;
import io.fabric8.kubernetes.api.model.NodeSelectorRequirementBuilder;
import io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpecBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeSpec;
import io.fabric8.kubernetes.api.model.PersistentVolumeSpecBuilder;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.api.model.PodSpec;
import io.fabric8.kubernetes.api.model.PodSpecBuilder;
import io.fabric8.kubernetes.api.model.Quantity;
Expand All @@ -22,18 +29,13 @@
import io.fabric8.kubernetes.api.model.VolumeBuilder;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolume;
import io.fabric8.kubernetes.api.model.PersistentVolumeBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeSpec;
import io.fabric8.kubernetes.api.model.PersistentVolumeSpecBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpecBuilder;
import io.fabric8.kubernetes.api.model.EmptyDirVolumeSource;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.PodResource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.ArrayList;
Expand All @@ -45,7 +47,12 @@
import static io.digdag.core.workflow.OperatorTestingUtils.newTaskRequest;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
Expand All @@ -57,6 +64,12 @@ public class DefaultKubernetesClientTest
private CommandContext commandContext;
private CommandRequest commandRequest;
private Config testKubernetesConfig;
private io.fabric8.kubernetes.client.DefaultKubernetesClient client;
private io.fabric8.kubernetes.api.model.Pod fabricPod;
private ObjectMeta objectMeta;
private Container container;
@Mock private MixedOperation<io.fabric8.kubernetes.api.model.Pod, PodList, PodResource<io.fabric8.kubernetes.api.model.Pod>> pods;
@Mock private NonNamespaceOperation<io.fabric8.kubernetes.api.model.Pod, PodList, PodResource<io.fabric8.kubernetes.api.model.Pod>> namespace;

@Before
public void setUp()
Expand All @@ -66,6 +79,10 @@ public void setUp()
k8sDefaultKubernetesClient = mock(io.fabric8.kubernetes.client.DefaultKubernetesClient.class);
commandContext = mock(CommandContext.class);
commandRequest = mock(CommandRequest.class);
client = mock(io.fabric8.kubernetes.client.DefaultKubernetesClient.class);
fabricPod = mock(io.fabric8.kubernetes.api.model.Pod.class);
objectMeta = mock(ObjectMeta.class);
container = mock(Container.class);

/*
kubernetes:
Expand Down Expand Up @@ -155,6 +172,27 @@ public void setUp()
.set("persistentVolumeReclaimPolicy", "Retain")));
}

@Test
public void testRunPod()
throws Exception
{
String podName = "testPod";
doReturn(objectMeta).when(fabricPod).getMetadata();
doReturn(podName).when(objectMeta).getName();
doReturn(pods).when(client).pods();
doReturn(namespace).when(pods).inNamespace(anyString());
doReturn(fabricPod).when(namespace).create(any(io.fabric8.kubernetes.api.model.Pod.class));

final DefaultKubernetesClient kubernetesClient = spy(new DefaultKubernetesClient(kubernetesClientConfig, client));
doReturn(testKubernetesConfig).when(kubernetesClient).extractTargetKindConfig(any(CommandContext.class), anyString());
doReturn(container).when(kubernetesClient).createContainer(any(CommandContext.class), any(CommandRequest.class), any(Config.class), anyString(), anyListOf(String.class), anyListOf(String.class));

List<String> commands = new ArrayList<String>();
List<String> arguments = new ArrayList<String>();
Pod pod = kubernetesClient.runPod(commandContext, commandRequest, podName, commands, arguments);
org.hamcrest.MatcherAssert.assertThat(pod.getName(), is(podName));
}

@Test
public void testCreateContainer()
throws Exception
Expand Down

0 comments on commit c3e6cea

Please sign in to comment.