in pkg/cmd/uninstall.go [118:188]
func (o *uninstallCmdOptions) uninstall(cmd *cobra.Command, _ []string) error {
c, err := o.GetCmdClient()
if err != nil {
return err
}
if !o.SkipIntegrationPlatform {
if err = o.uninstallIntegrationPlatform(o.Context, c); err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Camel K Integration Platform removed from namespace %s\n", o.Namespace)
}
if err = o.uninstallNamespaceResources(o.Context, cmd, c); err != nil {
return err
}
//nolint: ifshort
uninstallViaOLM := false
if o.OlmEnabled {
var err error
if uninstallViaOLM, err = olm.IsAPIAvailable(o.Context, c, o.Namespace); err != nil {
return fmt.Errorf("error while checking OLM availability. Run with '--olm=false' to skip this check: %w", err)
}
if uninstallViaOLM {
fmt.Fprintln(cmd.OutOrStdout(), "OLM is available in the cluster")
if err = olm.Uninstall(o.Context, c, o.Namespace, o.Global, o.OlmOptions); err != nil {
return err
}
where := fmt.Sprintf("from namespace %s", o.Namespace)
if o.Global {
where = "globally"
}
fmt.Fprintf(cmd.OutOrStdout(), "Camel K OLM service removed %s\n", where)
}
}
if !uninstallViaOLM {
if !o.SkipOperator {
if err = o.uninstallOperator(o.Context, c); err != nil {
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 fmt.Errorf("error while waiting the operator pod to terminate gracefully: %w", err)
}
}
}
if err = o.uninstallNamespaceRoles(o.Context, cmd, c); err != nil {
return err
}
if err = o.uninstallClusterWideResources(o.Context, cmd, c, o.Namespace); err != nil {
return err
}
}
return nil
}