@@ -73,7 +73,7 @@ public void setup() throws IOException {
73
73
}
74
74
75
75
@ Test
76
- public void testKubeDelete () throws KubectlException , IOException , ApiException {
76
+ public void testPatchConfigMap () throws KubectlException , IOException , ApiException {
77
77
// wireMockRule.stubFor(
78
78
// patch(urlPathEqualTo("/apis/batch/v1/namespaces/foo/jobs/bar"))
79
79
// .withHeader(
@@ -97,6 +97,16 @@ public void testKubeDelete() throws KubectlException, IOException, ApiException
97
97
// String localVarPath = "/apis/batch/v1/namespaces/{namespace}/jobs"
98
98
// .replaceAll("\\{" + "namespace" + "\\}", localVarApiClient.escapeString(namespace.toString()));
99
99
100
+
101
+ // /apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar
102
+ // /apis/batch/v1/namespaces/foo/jobs/bar
103
+ wireMockRule .stubFor (
104
+ 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 " )));
109
+
100
110
wireMockRule .stubFor (
101
111
get (urlPathEqualTo ("/api" ))
102
112
.willReturn (
@@ -115,6 +125,12 @@ public void testKubeDelete() throws KubectlException, IOException, ApiException
115
125
aResponse ()
116
126
.withStatus (200 )
117
127
.withBody (new String (Files .readAllBytes (Paths .get (DISCOVERY_APIV1 ))))));
128
+ wireMockRule .stubFor (
129
+ get (urlPathEqualTo ("/apis/batch/v1/" ))
130
+ .willReturn (
131
+ aResponse ()
132
+ .withStatus (200 )
133
+ .withBody ("{\" kind\" :\" APIResourceList\" ,\" apiVersion\" :\" v1\" ,\" groupVersion\" :\" batch/v1\" ,\" resources\" :[{\" name\" :\" cronjobs\" ,\" singularName\" :\" cronjob\" ,\" namespaced\" :true,\" kind\" :\" CronJob\" ,\" verbs\" :[\" create\" ,\" delete\" ,\" deletecollection\" ,\" get\" ,\" list\" ,\" patch\" ,\" update\" ,\" watch\" ],\" shortNames\" :[\" cj\" ],\" categories\" :[\" all\" ],\" storageVersionHash\" :\" sd5LIXh4Fjs=\" },{\" name\" :\" cronjobs/status\" ,\" singularName\" :\" \" ,\" namespaced\" :true,\" kind\" :\" CronJob\" ,\" verbs\" :[\" get\" ,\" patch\" ,\" update\" ]},{\" name\" :\" jobs\" ,\" singularName\" :\" job\" ,\" namespaced\" :true,\" kind\" :\" Job\" ,\" verbs\" :[\" create\" ,\" delete\" ,\" deletecollection\" ,\" get\" ,\" list\" ,\" patch\" ,\" update\" ,\" watch\" ],\" categories\" :[\" all\" ],\" storageVersionHash\" :\" mudhfqk/qZY=\" },{\" name\" :\" jobs/status\" ,\" singularName\" :\" \" ,\" namespaced\" :true,\" kind\" :\" Job\" ,\" verbs\" :[\" get\" ,\" patch\" ,\" update\" ]}]}\n " )));
118
134
119
135
V1JobSpec v1JobSpec = new V1JobSpec ()
120
136
.template (new V1PodTemplateSpec ()
@@ -141,15 +157,20 @@ public void testKubeDelete() throws KubectlException, IOException, ApiException
141
157
// aResponse()
142
158
// .withStatus(200)
143
159
// .withBody("{\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\"}}")))
144
-
145
- // V1Job is not namespaced in apiClient, so I have to add it to model map??
146
- ModelMapper .addModelMap (V1Job .class , true );
160
+ ModelMapper .addModelMap (api .getAPIResources ().getGroupVersion (), job .getApiVersion (), job .getKind (), "jobs" , true , V1Job .class );
147
161
148
162
KubectlDelete <V1Job > kubectlDelete = Kubectl .delete (V1Job .class );
149
163
kubectlDelete .apiClient (apiClient );
150
164
kubectlDelete .namespace ("foo" ).name ("bar" );
151
165
kubectlDelete .execute ();
152
166
167
+ // this job should error upon deletion now
168
+
169
+ KubectlDelete <V1Job > kubectlDelete2 = Kubectl .delete (V1Job .class );
170
+ kubectlDelete2 .apiClient (apiClient );
171
+ kubectlDelete2 .namespace ("foo" ).name ("bar" );
172
+ kubectlDelete2 .execute ();
173
+
153
174
// jobClient.delete("foo", "bar");
154
175
155
176
0 commit comments