Files
my-rook-config/pkg/operator/k8sutil/replicaset.go
T
Yuichiro Ueno b6ce262e7f core: add context to k8sutil replicaset and secret
This commit adds context parameter to k8sutil replicaset and secret
functions. By this, we can handle cancellation during API call of
replicaset and secret resource.

Signed-off-by: Yuichiro Ueno <y1r.ueno@gmail.com>
2021-12-11 11:42:31 +09:00

37 lines
1.3 KiB
Go

/*
Copyright 2018 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package k8sutil
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
// DeleteReplicaSet makes a best effort at deleting a deployment and its pods, then waits for them to be deleted
func DeleteReplicaSet(ctx context.Context, clientset kubernetes.Interface, namespace, name string) error {
deleteAction := func(options *metav1.DeleteOptions) error {
return clientset.AppsV1().ReplicaSets(namespace).Delete(ctx, name, *options)
}
getAction := func() error {
_, err := clientset.AppsV1().ReplicaSets(namespace).Get(ctx, name, metav1.GetOptions{})
return err
}
return deleteResourceAndWait(namespace, name, "replicaset", deleteAction, getAction)
}