get rid of ext interface

Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
pull/13604/head
Austin Abro 9 months ago
parent e6c6a40fe0
commit 8ce1876192
No known key found for this signature in database
GPG Key ID: 92EB5159E403F9D6

@ -22,7 +22,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"helm.sh/helm/v4/pkg/kube"
"helm.sh/helm/v4/pkg/release" "helm.sh/helm/v4/pkg/release"
helmtime "helm.sh/helm/v4/pkg/time" helmtime "helm.sh/helm/v4/pkg/time"
) )
@ -138,11 +137,8 @@ func (cfg *Configuration) deleteHookByPolicy(h *release.Hook, policy release.Hoo
return errors.New(joinErrors(errs)) return errors.New(joinErrors(errs))
} }
//wait for resources until they are deleted to avoid conflicts if err := cfg.KubeClient.WaitForDelete(resources, timeout); err != nil {
if kubeClient, ok := cfg.KubeClient.(kube.InterfaceExt); ok { return err
if err := kubeClient.WaitForDelete(resources, timeout); err != nil {
return err
}
} }
} }
return nil return nil

@ -131,10 +131,8 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error)
res.Info = kept res.Info = kept
if u.Wait { if u.Wait {
if kubeClient, ok := u.cfg.KubeClient.(kube.InterfaceExt); ok { if err := u.cfg.KubeClient.WaitForDelete(deletedResources, u.Timeout); err != nil {
if err := kubeClient.WaitForDelete(deletedResources, u.Timeout); err != nil { errs = append(errs, err)
errs = append(errs, err)
}
} }
} }

@ -331,15 +331,6 @@ func getResource(info *resource.Info) (runtime.Object, error) {
return obj, nil return obj, nil
} }
// WaitForDelete wait up to the given timeout for the specified resources to be deleted.
func (c *Client) WaitForDelete(resources ResourceList, timeout time.Duration) error {
w := HelmWaiter{
log: c.Log,
timeout: timeout,
}
return w.waitForDeletedResources(resources)
}
func (c *Client) namespace() string { func (c *Client) namespace() string {
if c.Namespace != "" { if c.Namespace != "" {
return c.Namespace return c.Namespace

@ -67,12 +67,7 @@ type Waiter interface {
// WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs. // WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs.
WaitWithJobs(resources ResourceList, timeout time.Duration) error WaitWithJobs(resources ResourceList, timeout time.Duration) error
}
// InterfaceExt is introduced to avoid breaking backwards compatibility for Interface implementers.
//
// TODO Helm 4: Remove InterfaceExt and integrate its method(s) into the Interface.
type InterfaceExt interface {
// WaitForDelete wait up to the given timeout for the specified resources to be deleted. // WaitForDelete wait up to the given timeout for the specified resources to be deleted.
WaitForDelete(resources ResourceList, timeout time.Duration) error WaitForDelete(resources ResourceList, timeout time.Duration) error
} }
@ -108,6 +103,5 @@ type InterfaceResources interface {
} }
var _ Interface = (*Client)(nil) var _ Interface = (*Client)(nil)
var _ InterfaceExt = (*Client)(nil)
var _ InterfaceDeletionPropagation = (*Client)(nil) var _ InterfaceDeletionPropagation = (*Client)(nil)
var _ InterfaceResources = (*Client)(nil) var _ InterfaceResources = (*Client)(nil)

@ -50,6 +50,12 @@ func (w *statusWaiter) WaitWithJobs(resourceList ResourceList, timeout time.Dura
return w.wait(ctx, resourceList, true) return w.wait(ctx, resourceList, true)
} }
func (w *statusWaiter) WaitForDelete(resourceList ResourceList, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
defer cancel()
return w.waitForDelete(ctx, resourceList)
}
func (w *statusWaiter) waitForDelete(ctx context.Context, resourceList ResourceList) error { func (w *statusWaiter) waitForDelete(ctx context.Context, resourceList ResourceList) error {
deadline, _ := ctx.Deadline() deadline, _ := ctx.Deadline()
w.log("beginning wait for %d resources to be deleted with timeout of %v", len(resourceList), time.Until(deadline)) w.log("beginning wait for %d resources to be deleted with timeout of %v", len(resourceList), time.Until(deadline))

@ -153,8 +153,6 @@ func TestStatusWaitForDelete(t *testing.T) {
sw: statusWatcher, sw: statusWatcher,
log: t.Logf, log: t.Logf,
} }
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
createdObjs := []runtime.Object{} createdObjs := []runtime.Object{}
for _, objYaml := range tt.objToCreate { for _, objYaml := range tt.objToCreate {
m := make(map[string]interface{}) m := make(map[string]interface{})
@ -184,7 +182,7 @@ func TestStatusWaitForDelete(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
resourceList = append(resourceList, list...) resourceList = append(resourceList, list...)
} }
err := statusWaiter.waitForDelete(ctx, resourceList) err := statusWaiter.WaitForDelete(resourceList, timeout)
if tt.expectErrs != nil { if tt.expectErrs != nil {
assert.EqualError(t, err, errors.Join(tt.expectErrs...).Error()) assert.EqualError(t, err, errors.Join(tt.expectErrs...).Error())
return return

@ -43,29 +43,26 @@ import (
// Helm 4 now uses the StatusWaiter interface instead // Helm 4 now uses the StatusWaiter interface instead
type HelmWaiter struct { type HelmWaiter struct {
c ReadyChecker c ReadyChecker
timeout time.Duration
log func(string, ...interface{}) log func(string, ...interface{})
kubeClient *kubernetes.Clientset kubeClient *kubernetes.Clientset
} }
func (w *HelmWaiter) Wait(resources ResourceList, timeout time.Duration) error { func (w *HelmWaiter) Wait(resources ResourceList, timeout time.Duration) error {
w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true)) w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true))
w.timeout = timeout return w.waitForResources(resources, timeout)
return w.waitForResources(resources)
} }
func (w *HelmWaiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error { func (w *HelmWaiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true), CheckJobs(true)) w.c = NewReadyChecker(w.kubeClient, w.log, PausedAsReady(true), CheckJobs(true))
w.timeout = timeout return w.waitForResources(resources, timeout)
return w.waitForResources(resources)
} }
// waitForResources polls to get the current status of all pods, PVCs, Services and // waitForResources polls to get the current status of all pods, PVCs, Services and
// Jobs(optional) until all are ready or a timeout is reached // Jobs(optional) until all are ready or a timeout is reached
func (w *HelmWaiter) waitForResources(created ResourceList) error { func (w *HelmWaiter) waitForResources(created ResourceList, timeout time.Duration) error {
w.log("beginning wait for %d resources with timeout of %v", len(created), w.timeout) w.log("beginning wait for %d resources with timeout of %v", len(created), timeout)
ctx, cancel := context.WithTimeout(context.Background(), w.timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
numberOfErrors := make([]int, len(created)) numberOfErrors := make([]int, len(created))
@ -116,10 +113,10 @@ func (w *HelmWaiter) isRetryableHTTPStatusCode(httpStatusCode int32) bool {
} }
// waitForDeletedResources polls to check if all the resources are deleted or a timeout is reached // waitForDeletedResources polls to check if all the resources are deleted or a timeout is reached
func (w *HelmWaiter) waitForDeletedResources(deleted ResourceList) error { func (w *HelmWaiter) WaitForDelete(deleted ResourceList, timeout time.Duration) error {
w.log("beginning wait for %d resources to be deleted with timeout of %v", len(deleted), w.timeout) w.log("beginning wait for %d resources to be deleted with timeout of %v", len(deleted), timeout)
ctx, cancel := context.WithTimeout(context.Background(), w.timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
return wait.PollUntilContextCancel(ctx, 2*time.Second, true, func(_ context.Context) (bool, error) { return wait.PollUntilContextCancel(ctx, 2*time.Second, true, func(_ context.Context) (bool, error) {

Loading…
Cancel
Save