Skip to content

Commit e5634f0

Browse files
authored
Merge pull request #1182 from sarveshkaushal/k-cmd
Add support for Kubectl patch
2 parents 197a5a0 + b14cbc3 commit e5634f0

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

extended/src/main/java/io/kubernetes/client/extended/kubectl/Kubectl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ public static KubectlApiResources apiResources() {
167167
return new KubectlApiResources();
168168
}
169169

170+
/**
171+
* Equivalent for `Kubectl patch`
172+
*
173+
* @param apiTypeClass
174+
* @param <ApiType>
175+
* @return
176+
*/
177+
public static <ApiType extends KubernetesObject> KubectlPatch<ApiType> patch(
178+
Class<ApiType> apiTypeClass) {
179+
return new KubectlPatch<>(apiTypeClass);
180+
}
181+
170182
/**
171183
* Executable executes a kubectl helper.
172184
*
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.extended.kubectl;
14+
15+
import io.kubernetes.client.common.KubernetesListObject;
16+
import io.kubernetes.client.common.KubernetesObject;
17+
import io.kubernetes.client.custom.V1Patch;
18+
import io.kubernetes.client.util.generic.GenericKubernetesApi;
19+
20+
public class KubectlPatch<ApiType extends KubernetesObject>
21+
extends Kubectl.ResourceBuilder<ApiType, KubectlPatch<ApiType>>
22+
implements Kubectl.Executable<ApiType> {
23+
24+
private Class<ApiType> apiTypeClass;
25+
private Class<KubernetesListObject> apiListTypeClass;
26+
private V1Patch patchContent;
27+
28+
KubectlPatch(Class<ApiType> apiTypeClass) {
29+
super(apiTypeClass);
30+
}
31+
32+
public KubectlPatch patchContent(V1Patch patchContent) {
33+
this.patchContent = patchContent;
34+
return this;
35+
}
36+
37+
@Override
38+
public ApiType execute() {
39+
GenericKubernetesApi genericKubernetesApi = getGenericApi();
40+
return (ApiType) genericKubernetesApi.patch(namespace, name, patchContent);
41+
}
42+
}

0 commit comments

Comments
 (0)