cli: err about extensions for uninstall
Fixes
Currently, We don't provide any information w.r.t extensions
when `linkerd uninstall` is ran and extensions are present.
This PR updates the install command to display a error message
asking to uninstall the existing extensions before uninstalling
the core control-plane.
@@ -34,6 +34,32 @@ This command provides all Kubernetes namespace-scoped and cluster-scoped resourc
}
if !force {
+
+ var fail bool
+ // Retrtieve any installed extensions
+ extensionNamespaces, err := k8sAPI.GetAllNamespacesWithExtensionLabel(cmd.Context())
+ if err != nil {
+ return err
+ }
+
+ // map of the namespace and the extension name
+ // Namespace is used as key so as to support custom namespace installs
+ extensions := make(map[string]string)
+ if len(extensionNamespaces) > 0 {
+ for _, extension := range extensionNamespaces {
+ extensions[extension.Name] = extension.Labels[k8s.LinkerdExtensionLabel]
+ }
+
+ // Retrieve all the extension names
+ extensionNames := make([]string, 0, len(extensions))
+ for _, v := range extensions {
+ extensionNames = append(extensionNames, fmt.Sprintf("* %s", v))
+ }
+
+ fmt.Fprintln(os.Stderr, fmt.Sprintf("Please uninstall the following extensions before uninstalling the control-plane:\n\t%s", strings.Join(extensionNames, "\n\t")))
+ fail = true
+ }
+
podList, err := k8sAPI.CoreV1().Pods("").List(cmd.Context(), metav1.ListOptions{LabelSelector: k8s.ControllerNSLabel})
if err != nil {
return err
@@ -41,14 +67,18 @@ This command provides all Kubernetes namespace-scoped and cluster-scoped resourc
var injectedPods []string
for _, pod := range podList.Items {
- // skip core control-plane namespace
- if pod.Namespace != controlPlaneNamespace {
+ // skip core control-plane namespace, and extension namespaces
+ if pod.Namespace != controlPlaneNamespace && extensions[pod.Namespace] == "" {
injectedPods = append(injectedPods, fmt.Sprintf("* %s", pod.Name))
}
}
if len(injectedPods) > 0 {
fmt.Fprintln(os.Stderr, fmt.Sprintf("Please uninject the following pods before uninstalling the control-plane:\n\t%s", strings.Join(injectedPods, "\n\t")))
+ fail = true
+ }
+
+ if fail {
os.Exit(1)
}
}
