12
12
*/
13
13
14
14
import static com .github .tomakehurst .wiremock .client .WireMock .*;
15
- import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .options ;
16
15
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
17
- import static org .junit .Assert .assertNotNull ;
18
16
import static org .junit .Assert .assertThrows ;
19
17
20
18
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
21
- import com .github .tomakehurst .wiremock .matching .EqualToPattern ;
22
19
import com .github .tomakehurst .wiremock .stubbing .Scenario ;
23
- import io .kubernetes .client .custom .V1Patch ;
24
20
import io .kubernetes .client .extended .kubectl .Kubectl ;
25
21
import io .kubernetes .client .extended .kubectl .KubectlDelete ;
26
22
import io .kubernetes .client .extended .kubectl .exception .KubectlException ;
37
33
import java .nio .file .Paths ;
38
34
39
35
import io .kubernetes .client .util .generic .GenericKubernetesApi ;
40
- import io .kubernetes .client .util .generic .KubernetesApiResponse ;
41
36
import org .junit .Before ;
42
37
import org .junit .Rule ;
43
38
import org .junit .Test ;
@@ -46,9 +41,6 @@ public class KubectlDeleteTest {
46
41
47
42
private ApiClient apiClient ;
48
43
49
- private JSON json = new JSON ();
50
- private GenericKubernetesApi <V1Job , V1JobList > jobClient ;
51
-
52
44
private static final String DISCOVERY_API =
53
45
new File (KubectlDeleteTest .class .getClassLoader ().getResource ("discovery-api.json" ).getPath ())
54
46
.toString ();
@@ -70,45 +62,16 @@ public class KubectlDeleteTest {
70
62
@ Before
71
63
public void setup () throws IOException {
72
64
apiClient = new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule .port ()).build ();
73
- jobClient =
74
- new GenericKubernetesApi <>(V1Job .class , V1JobList .class , "batch" , "v1" , "jobs" , apiClient );
75
65
}
76
66
77
67
@ Test
78
68
public void testKubectlDelete () throws KubectlException , IOException , ApiException , InterruptedException {
79
- // wireMockRule.stubFor(
80
- // patch(urlPathEqualTo("/apis/batch/v1/namespaces/foo/jobs/bar"))
81
- // .withHeader(
82
- // "Content-Type", new EqualToPattern(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
83
- // .willReturn(
84
- // aResponse()
85
- // .withStatus(200)
86
- // .withBody("{\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\"}}")));
87
- // V1Status status = new V1Status().kind("Status").code(200).message("good!");
88
- // stubFor(
89
- // delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
90
- // .willReturn(aResponse().withStatus(200).withBody(json.serialize(status))));
91
69
wireMockRule .stubFor (
92
70
post (urlPathEqualTo ("/apis/batch/v1/namespaces/foo/jobs" ))
93
- // .withHeader(
94
- // "Content-Type", new EqualToPattern("application-json"))
95
71
.willReturn (
96
72
aResponse ()
97
73
.withStatus (201 )
98
74
.withBody ("{\" kind\" :\" Job\" ,\" apiVersion\" :\" batch/v1\" ,\" metadata\" :{\" name\" :\" bar\" ,\" namespace\" :\" foo\" ,\" uid\" :\" 7f64e06e-d6a6-4598-b375-7c8773f3b0e7\" ,\" resourceVersion\" :\" 46205\" ,\" generation\" :1,\" creationTimestamp\" :\" 2023-11-23T15:38:18Z\" ,\" labels\" :{\" batch.kubernetes.io/controller-uid\" :\" 7f64e06e-d6a6-4598-b375-7c8773f3b0e7\" ,\" batch.kubernetes.io/job-name\" :\" bar\" ,\" controller-uid\" :\" 7f64e06e-d6a6-4598-b375-7c8773f3b0e7\" ,\" job-name\" :\" bar\" },\" annotations\" :{\" batch.kubernetes.io/job-tracking\" :\" \" },\" managedFields\" :[{\" manager\" :\" Kubernetes Java Client\" ,\" operation\" :\" Update\" ,\" apiVersion\" :\" batch/v1\" ,\" time\" :\" 2023-11-23T15:38:18Z\" ,\" fieldsType\" :\" FieldsV1\" ,\" fieldsV1\" :{\" f:spec\" :{\" f:backoffLimit\" :{},\" f:completionMode\" :{},\" f:completions\" :{},\" f:parallelism\" :{},\" f:suspend\" :{},\" f:template\" :{\" f:spec\" :{\" f:containers\" :{\" k:{\\ \" name\\ \" :\\ \" bar2\\ \" }\" :{\" .\" :{},\" f:command\" :{},\" f:image\" :{},\" f:imagePullPolicy\" :{},\" f:name\" :{},\" f:resources\" :{},\" f:terminationMessagePath\" :{},\" f:terminationMessagePolicy\" :{}}},\" f:dnsPolicy\" :{},\" f:restartPolicy\" :{},\" f:schedulerName\" :{},\" f:securityContext\" :{},\" f:terminationGracePeriodSeconds\" :{}}}}}}]},\" spec\" :{\" parallelism\" :1,\" completions\" :1,\" backoffLimit\" :6,\" selector\" :{\" matchLabels\" :{\" batch.kubernetes.io/controller-uid\" :\" 7f64e06e-d6a6-4598-b375-7c8773f3b0e7\" }},\" template\" :{\" metadata\" :{\" creationTimestamp\" :null,\" labels\" :{\" batch.kubernetes.io/controller-uid\" :\" 7f64e06e-d6a6-4598-b375-7c8773f3b0e7\" ,\" batch.kubernetes.io/job-name\" :\" bar\" ,\" controller-uid\" :\" 7f64e06e-d6a6-4598-b375-7c8773f3b0e7\" ,\" job-name\" :\" bar\" }},\" spec\" :{\" containers\" :[{\" name\" :\" bar2\" ,\" image\" :\" busybox\" ,\" command\" :[\" sh\" ,\" -c\" ,\" echo Hello World!\" ],\" resources\" :{},\" terminationMessagePath\" :\" /dev/termination-log\" ,\" terminationMessagePolicy\" :\" File\" ,\" imagePullPolicy\" :\" Always\" }],\" restartPolicy\" :\" Never\" ,\" terminationGracePeriodSeconds\" :30,\" dnsPolicy\" :\" ClusterFirst\" ,\" securityContext\" :{},\" schedulerName\" :\" default-scheduler\" }},\" completionMode\" :\" NonIndexed\" ,\" suspend\" :false},\" status\" :{}}" )));
99
- // String localVarPath = "/apis/batch/v1/namespaces/{namespace}/jobs"
100
- // .replaceAll("\\{" + "namespace" + "\\}", localVarApiClient.escapeString(namespace.toString()));
101
-
102
-
103
- // /apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar
104
- // /apis/batch/v1/namespaces/foo/jobs/bar
105
- // wireMockRule.stubFor(
106
- // delete(urlPathEqualTo("/apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar"))
107
- // .willReturn(
108
- // aResponse()
109
- // .withStatus(200)
110
- // .withBody("{\"kind\":\"Job\",\"apiVersion\":\"batch/v1\",\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\",\"uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"resourceVersion\":\"82015\",\"generation\":2,\"creationTimestamp\":\"2023-11-24T06:00:49Z\",\"deletionTimestamp\":\"2023-11-24T06:07:44Z\",\"deletionGracePeriodSeconds\":0,\"labels\":{\"batch.kubernetes.io/controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"batch.kubernetes.io/job-name\":\"bar\",\"controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"job-name\":\"bar\"},\"annotations\":{\"batch.kubernetes.io/job-tracking\":\"\"},\"finalizers\":[\"orphan\"],\"managedFields\":[{\"manager\":\"Kubernetes Java Client\",\"operation\":\"Update\",\"apiVersion\":\"batch/v1\",\"time\":\"2023-11-24T06:00:49Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:spec\":{\"f:backoffLimit\":{},\"f:completionMode\":{},\"f:completions\":{},\"f:parallelism\":{},\"f:suspend\":{},\"f:template\":{\"f:spec\":{\"f:containers\":{\"k:{\\\"name\\\":\\\"bar2\\\"}\":{\".\":{},\"f:command\":{},\"f:image\":{},\"f:imagePullPolicy\":{},\"f:name\":{},\"f:resources\":{},\"f:terminationMessagePath\":{},\"f:terminationMessagePolicy\":{}}},\"f:dnsPolicy\":{},\"f:restartPolicy\":{},\"f:schedulerName\":{},\"f:securityContext\":{},\"f:terminationGracePeriodSeconds\":{}}}}}},{\"manager\":\"kube-controller-manager\",\"operation\":\"Update\",\"apiVersion\":\"batch/v1\",\"time\":\"2023-11-24T06:00:53Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:status\":{\"f:completionTime\":{},\"f:conditions\":{},\"f:ready\":{},\"f:startTime\":{},\"f:succeeded\":{},\"f:uncountedTerminatedPods\":{}}},\"subresource\":\"status\"}]},\"spec\":{\"parallelism\":1,\"completions\":1,\"backoffLimit\":6,\"selector\":{\"matchLabels\":{\"batch.kubernetes.io/controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"batch.kubernetes.io/controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"batch.kubernetes.io/job-name\":\"bar\",\"controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"job-name\":\"bar\"}},\"spec\":{\"containers\":[{\"name\":\"bar2\",\"image\":\"busybox\",\"command\":[\"sh\",\"-c\",\"echo Hello World!\"],\"resources\":{},\"terminationMessagePath\":\"/dev/termination-log\",\"terminationMessagePolicy\":\"File\",\"imagePullPolicy\":\"Always\"}],\"restartPolicy\":\"Never\",\"terminationGracePeriodSeconds\":30,\"dnsPolicy\":\"ClusterFirst\",\"securityContext\":{},\"schedulerName\":\"default-scheduler\"}},\"completionMode\":\"NonIndexed\",\"suspend\":false},\"status\":{\"conditions\":[{\"type\":\"Complete\",\"status\":\"True\",\"lastProbeTime\":\"2023-11-24T06:00:53Z\",\"lastTransitionTime\":\"2023-11-24T06:00:53Z\"}],\"startTime\":\"2023-11-24T06:00:49Z\",\"completionTime\":\"2023-11-24T06:00:53Z\",\"succeeded\":1,\"uncountedTerminatedPods\":{},\"ready\":0}}\n")));
111
- //
112
75
wireMockRule .stubFor (
113
76
delete (urlPathEqualTo ("/apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar" ))
114
77
.inScenario ("JobDeletionScenario" )
@@ -168,18 +131,9 @@ public void testKubectlDelete() throws KubectlException, IOException, ApiExcepti
168
131
.kind ("Job" )
169
132
.metadata (new V1ObjectMeta ().name ("bar" ))
170
133
.spec (v1JobSpec );
171
- ////
172
134
BatchV1Api api = new BatchV1Api ();
173
135
api .setApiClient (apiClient );
174
136
api .createNamespacedJob ("foo" , job , null , null , null , "Strict" );
175
- // wireMockRule.stubFor(
176
- // patch(urlPathEqualTo("/apis/batch/v1/namespaces/foo/jobs/bar"))
177
- // .withHeader(
178
- // "Content-Type", new EqualToPattern(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
179
- // .willReturn(
180
- // aResponse()
181
- // .withStatus(200)
182
- // .withBody("{\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\"}}")))
183
137
ModelMapper .addModelMap (api .getAPIResources ().getGroupVersion (), job .getApiVersion (), job .getKind (), "jobs" , true , V1Job .class );
184
138
185
139
KubectlDelete <V1Job > kubectlDelete = Kubectl .delete (V1Job .class );
@@ -198,24 +152,5 @@ public void testKubectlDelete() throws KubectlException, IOException, ApiExcepti
198
152
kubectlDelete2 .apiClient (apiClient );
199
153
kubectlDelete2 .namespace ("foo" ).name ("bar" ).ignoreNotFound (true );
200
154
kubectlDelete2 .execute ();
201
-
202
- // jobClient.delete("foo", "bar");
203
-
204
-
205
- // V1Job foo1 =
206
- // new V1Job().kind("Job").metadata(new V1ObjectMeta().namespace("foo").name("bar"));
207
- //
208
- // stubFor(
209
- // post(urlEqualTo("/apis/batch/v1/namespaces/foo/jobs"))
210
- // .willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
211
- // KubernetesApiResponse<V1Job> jobListResp = jobClient.create(foo1);
212
- // V1Status status = new V1Status().kind("Status").code(200).message("good!");
213
- // stubFor(
214
- // delete(urlEqualTo("/apis/batch/v1/namespaces/foo/jobs/bar"))
215
- // .willReturn(aResponse().withStatus(200).withBody(json.serialize(status))));
216
- //
217
- // KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("foo", "bar", null);
218
- // System.out.println(deleteJobResp.isSuccess());
219
- // System.out.println(deleteJobResp.getStatus());
220
155
}
221
156
}
0 commit comments