Skip to content

Commit 1bf8b5c

Browse files
committed
patch function
1 parent a71f40c commit 1bf8b5c

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

common-lib/utils/k8s/K8sUtil.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type K8sService interface {
148148
CreateNsWithLabels(namespace string, labels map[string]string, client *v12.CoreV1Client) (ns *v1.Namespace, err error)
149149
CreateNs(namespace string, client *v12.CoreV1Client) (ns *v1.Namespace, err error)
150150
GetRestClientForCRD(config *ClusterConfig, groupVersion *schema.GroupVersion) (*rest.RESTClient, error)
151+
PatchResourceByRestClient(restClient *rest.RESTClient, resource, name, namespace string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) rest.Result
151152
}
152153

153154
func NewK8sUtil(logger *zap.SugaredLogger, runTimeConfig *RuntimeConfig) (*K8sServiceImpl, error) {
@@ -1929,3 +1930,15 @@ func (impl *K8sServiceImpl) GetRestClientForCRD(config *ClusterConfig, groupVers
19291930

19301931
return restClient, nil
19311932
}
1933+
1934+
func (impl *K8sServiceImpl) PatchResourceByRestClient(restClient *rest.RESTClient, resource, name, namespace string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) rest.Result {
1935+
result := restClient.Patch(pt).
1936+
Namespace(namespace).
1937+
Resource(resource).
1938+
Name(name).
1939+
SubResource(subresources...).
1940+
VersionedParams(&opts, scheme.ParameterCodec).
1941+
Body(data).
1942+
Do(context.Background())
1943+
return result
1944+
}

0 commit comments

Comments
 (0)