Skip to content

Commit 33b7db9

Browse files
committed
adding context
1 parent a1816eb commit 33b7db9

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

common-lib/utils/k8s/K8sUtil.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ 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
GetGVRForCRD(config *rest.Config, CRDName string) (schema.GroupVersionResource, error)
151-
GetResourceByGVR(config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string) (*unstructured.Unstructured, error)
152-
PatchResourceByGVR(config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, patchType types.PatchType, patchData []byte) (*unstructured.Unstructured, error)
153-
DeleteResourceByGVR(config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, forceDelete bool) error
151+
GetResourceByGVR(ctx context.Context, config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string) (*unstructured.Unstructured, error)
152+
PatchResourceByGVR(ctx context.Context, config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, patchType types.PatchType, patchData []byte) (*unstructured.Unstructured, error)
153+
DeleteResourceByGVR(ctx context.Context, config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, forceDelete bool) error
154154
}
155155

156156
func NewK8sUtil(logger *zap.SugaredLogger, runTimeConfig *RuntimeConfig) (*K8sServiceImpl, error) {
@@ -1936,35 +1936,35 @@ func (impl *K8sServiceImpl) GetGVRForCRD(config *rest.Config, CRDName string) (s
19361936
}, nil
19371937
}
19381938

1939-
func (impl *K8sServiceImpl) GetResourceByGVR(config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string) (*unstructured.Unstructured, error) {
1939+
func (impl *K8sServiceImpl) GetResourceByGVR(ctx context.Context, config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string) (*unstructured.Unstructured, error) {
19401940
dynClient, err := dynamic.NewForConfig(config)
19411941
if err != nil {
19421942
impl.logger.Errorw("failed to create dynamic client", "err", err)
19431943
return nil, err
19441944
}
1945-
resource, err := dynClient.Resource(GVR).Namespace(namespace).Get(context.TODO(), resourceName, metav1.GetOptions{})
1945+
resource, err := dynClient.Resource(GVR).Namespace(namespace).Get(ctx, resourceName, metav1.GetOptions{})
19461946
if err != nil {
19471947
impl.logger.Errorw("failed to get resource", "resourceName", resourceName, "namespace", namespace, "err", err)
19481948
return nil, err
19491949
}
19501950
return resource, nil
19511951
}
19521952

1953-
func (impl *K8sServiceImpl) PatchResourceByGVR(config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, patchType types.PatchType, patchData []byte) (*unstructured.Unstructured, error) {
1953+
func (impl *K8sServiceImpl) PatchResourceByGVR(ctx context.Context, config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, patchType types.PatchType, patchData []byte) (*unstructured.Unstructured, error) {
19541954
dynClient, err := dynamic.NewForConfig(config)
19551955
if err != nil {
19561956
impl.logger.Errorw("failed to create dynamic client", "err", err)
19571957
return nil, err
19581958
}
1959-
resource, err := dynClient.Resource(GVR).Namespace(namespace).Patch(context.TODO(), resourceName, patchType, patchData, metav1.PatchOptions{FieldManager: "patch"})
1959+
resource, err := dynClient.Resource(GVR).Namespace(namespace).Patch(ctx, resourceName, patchType, patchData, metav1.PatchOptions{FieldManager: "patch"})
19601960
if err != nil {
19611961
impl.logger.Errorw("failed to get resource", "resourceName", resourceName, "namespace", namespace, "err", err)
19621962
return nil, err
19631963
}
19641964
return resource, nil
19651965
}
19661966

1967-
func (impl *K8sServiceImpl) DeleteResourceByGVR(config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, forceDelete bool) error {
1967+
func (impl *K8sServiceImpl) DeleteResourceByGVR(ctx context.Context, config *rest.Config, GVR schema.GroupVersionResource, resourceName, namespace string, forceDelete bool) error {
19681968
dynClient, err := dynamic.NewForConfig(config)
19691969
if err != nil {
19701970
impl.logger.Errorw("failed to create dynamic client", "err", err)
@@ -1974,7 +1974,7 @@ func (impl *K8sServiceImpl) DeleteResourceByGVR(config *rest.Config, GVR schema.
19741974
if forceDelete {
19751975
deleteOptions.GracePeriodSeconds = pointer.Int64Ptr(0)
19761976
}
1977-
err = dynClient.Resource(GVR).Namespace(namespace).Delete(context.TODO(), resourceName, deleteOptions)
1977+
err = dynClient.Resource(GVR).Namespace(namespace).Delete(ctx, resourceName, deleteOptions)
19781978
if err != nil {
19791979
impl.logger.Errorw("failed to get resource", "resourceName", resourceName, "namespace", namespace, "err", err)
19801980
return err

0 commit comments

Comments
 (0)