15
15
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .options ;
16
16
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
17
17
import static org .junit .Assert .assertNotNull ;
18
+ import static org .junit .Assert .assertThrows ;
18
19
19
20
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
20
21
import com .github .tomakehurst .wiremock .matching .EqualToPattern ;
22
+ import com .github .tomakehurst .wiremock .stubbing .Scenario ;
21
23
import io .kubernetes .client .custom .V1Patch ;
22
24
import io .kubernetes .client .extended .kubectl .Kubectl ;
23
25
import io .kubernetes .client .extended .kubectl .KubectlDelete ;
@@ -73,7 +75,7 @@ public void setup() throws IOException {
73
75
}
74
76
75
77
@ Test
76
- public void testPatchConfigMap () throws KubectlException , IOException , ApiException {
78
+ public void testKubectlDelete () throws KubectlException , IOException , ApiException , InterruptedException {
77
79
// wireMockRule.stubFor(
78
80
// patch(urlPathEqualTo("/apis/batch/v1/namespaces/foo/jobs/bar"))
79
81
// .withHeader(
@@ -100,12 +102,33 @@ public void testPatchConfigMap() throws KubectlException, IOException, ApiExcept
100
102
101
103
// /apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar
102
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
+ //
103
112
wireMockRule .stubFor (
104
113
delete (urlPathEqualTo ("/apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar" ))
105
- .willReturn (
106
- aResponse ()
107
- .withStatus (200 )
108
- .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 " )));
114
+ .inScenario ("JobDeletionScenario" )
115
+ .whenScenarioStateIs (Scenario .STARTED )
116
+ .willReturn (aResponse ()
117
+ .withStatus (200 )
118
+ .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 " )
119
+ )
120
+ .willSetStateTo ("SecondCall" )
121
+ );
122
+
123
+ wireMockRule .stubFor (
124
+ delete (urlPathEqualTo ("/apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar" ))
125
+ .inScenario ("JobDeletionScenario" )
126
+ .whenScenarioStateIs ("SecondCall" )
127
+ .willReturn (aResponse ()
128
+ .withStatus (404 )
129
+ .withBody ("{\" kind\" :\" Status\" ,\" apiVersion\" :\" v1\" ,\" metadata\" :{},\" status\" :\" Failure\" ,\" message\" :\" jobs.batch \\ \" bar\\ \" not found\" ,\" reason\" :\" NotFound\" ,\" details\" :{\" name\" :\" bar\" ,\" group\" :\" batch\" ,\" kind\" :\" jobs\" },\" code\" :404}" )
130
+ )
131
+ );
109
132
110
133
wireMockRule .stubFor (
111
134
get (urlPathEqualTo ("/api" ))
@@ -164,11 +187,16 @@ public void testPatchConfigMap() throws KubectlException, IOException, ApiExcept
164
187
kubectlDelete .namespace ("foo" ).name ("bar" );
165
188
kubectlDelete .execute ();
166
189
167
- // this job should error upon deletion now
190
+ assertThrows (KubectlException .class , () -> {
191
+ KubectlDelete <V1Job > kubectlDelete2 = Kubectl .delete (V1Job .class );
192
+ kubectlDelete2 .apiClient (apiClient );
193
+ kubectlDelete2 .namespace ("foo" ).name ("bar" );
194
+ kubectlDelete2 .execute ();
195
+ });
168
196
169
197
KubectlDelete <V1Job > kubectlDelete2 = Kubectl .delete (V1Job .class );
170
198
kubectlDelete2 .apiClient (apiClient );
171
- kubectlDelete2 .namespace ("foo" ).name ("bar" );
199
+ kubectlDelete2 .namespace ("foo" ).name ("bar" ). ignoreNotFound ( true ) ;
172
200
kubectlDelete2 .execute ();
173
201
174
202
// jobClient.delete("foo", "bar");
0 commit comments