Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(cmd): uninstall to wait the operator pod" #4295

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions pkg/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package cmd
import (
"context"
"fmt"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -36,9 +35,7 @@ import (

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/client"
"github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/util/olm"
"github.com/apache/camel-k/v2/pkg/util/watch"
)

func newCmdUninstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *uninstallCmdOptions) {
Expand Down Expand Up @@ -159,19 +156,6 @@ func (o *uninstallCmdOptions) uninstall(cmd *cobra.Command, _ []string) error {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Camel K Operator removed from namespace %s\n", o.Namespace)

// Let's wait the Pod has completed all the tasks before removing roles, as it may cause
// problems during the shutdown

pod := platform.GetOperatorPod(o.Context, c, o.Namespace)
if pod != nil {
tctx, cancel := context.WithTimeout(o.Context, 15*time.Second)
defer cancel()
err := watch.WaitPodToTerminate(tctx, c, pod)
if err != nil {
return errors.Wrap(err, "error while waiting the operator pod to terminate gracefully")
}
}
}

if err = o.uninstallNamespaceRoles(o.Context, cmd, c); err != nil {
Expand Down
26 changes: 0 additions & 26 deletions pkg/util/watch/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/client"
Expand Down Expand Up @@ -213,31 +212,6 @@ func HandleIntegrationPlatformEvents(ctx context.Context, c client.Client, p *v1
}
}

// WaitPodToTerminate will wait for a given pod to teminate.
func WaitPodToTerminate(ctx context.Context, c client.Client, pod *corev1.Pod) error {
opts := metav1.ListOptions{
TypeMeta: metav1.TypeMeta{},
FieldSelector: fmt.Sprintf("metadata.name=%s", pod.Name),
}
watcher, err := c.CoreV1().Pods(pod.Namespace).Watch(ctx, opts)
if err != nil {
return err
}

defer watcher.Stop()

for {
select {
case event := <-watcher.ResultChan():
if event.Type == watch.Deleted {
return nil
}
case <-ctx.Done():
return nil
}
}
}

func isAllowed(lastEvent, event *corev1.Event, baseTime int64) bool {
if lastEvent == nil {
return true
Expand Down