mirror of https://github.com/linkerd/linkerd2.git
Add support for legacy names in extension uninstall (#6226)
Because extension label values have been changed, an older install of an extension will fail to be uninstalled with a more recent CLI version. This is because the uninstall command checks the new label value which doesn't match older installs. This small change fixes that by checking both -- the new, non-prefixed version and the old prefixed one. The bug should have a relatively small impact since there are only a few edge releases that contain the prefixed label value (an exception being stable-2.10.0 which used the prefixed version still). Signed-off-by: Matei David <matei@buoyant.io>
This commit is contained in:
parent
0be792fadc
commit
e17a796d88
|
@ -82,7 +82,12 @@ This command provides all Kubernetes namespace-scoped and cluster-scoped resourc
|
|||
}
|
||||
}
|
||||
|
||||
err = pkgCmd.Uninstall(cmd.Context(), k8sAPI, k8s.ControllerNSLabel)
|
||||
selector, err := pkgCmd.GetLabelSelector(k8s.ControllerNSLabel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = pkgCmd.Uninstall(cmd.Context(), k8sAPI, selector)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@ const (
|
|||
// JaegerExtensionName is the name of jaeger extension
|
||||
JaegerExtensionName = "jaeger"
|
||||
|
||||
// JaegerLegacyExtension is the name of the jaeger extension prior to
|
||||
// stable-2.10.0 when the linkerd prefix was removed.
|
||||
JaegerLegacyExtension = "linkerd-jaeger"
|
||||
|
||||
// linkerdJaegerExtensionCheck adds checks related to the jaeger extension
|
||||
linkerdJaegerExtensionCheck healthcheck.CategoryID = "linkerd-jaeger"
|
||||
)
|
||||
|
|
|
@ -38,5 +38,10 @@ func uninstallRunE(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return pkgCmd.Uninstall(ctx, k8sAPI, fmt.Sprintf("%s=%s", k8s.LinkerdExtensionLabel, JaegerExtensionName))
|
||||
selector, err := pkgCmd.GetLabelSelector(k8s.LinkerdExtensionLabel, JaegerExtensionName, JaegerLegacyExtension)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return pkgCmd.Uninstall(ctx, k8sAPI, selector)
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ const (
|
|||
// MulticlusterExtensionName is the name of the multicluster extension
|
||||
MulticlusterExtensionName = "multicluster"
|
||||
|
||||
// MulticlusterLegacyExtension is the name of the multicluster extension
|
||||
// prior to stable-2.10.0 when the linkerd prefix was removed.
|
||||
MulticlusterLegacyExtension = "linkerd-multicluster"
|
||||
|
||||
// linkerdMulticlusterExtensionCheck adds checks related to the multicluster extension
|
||||
linkerdMulticlusterExtensionCheck healthcheck.CategoryID = "linkerd-multicluster"
|
||||
|
||||
|
|
|
@ -53,7 +53,12 @@ func newMulticlusterUninstallCommand() *cobra.Command {
|
|||
return errors.New(strings.Join(err, "\n"))
|
||||
}
|
||||
|
||||
err = pkgCmd.Uninstall(cmd.Context(), k8sAPI, fmt.Sprintf("%s=%s", k8s.LinkerdExtensionLabel, MulticlusterExtensionName))
|
||||
selector, err := pkgCmd.GetLabelSelector(k8s.LinkerdExtensionLabel, MulticlusterExtensionName, MulticlusterLegacyExtension)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = pkgCmd.Uninstall(cmd.Context(), k8sAPI, selector)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/selection"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
|
@ -125,3 +127,22 @@ func ConfigureKubeContextFlagCompletion(cmd *cobra.Command, kubeconfigPath strin
|
|||
return suggestions, cobra.ShellCompDirectiveDefault
|
||||
})
|
||||
}
|
||||
|
||||
// GetLabelSelector creates a label selector as a string based on a label key
|
||||
// whose value may be in the set provided as an argument to the function. If the
|
||||
// value set is empty then the selector will match resources where the label key
|
||||
// exists regardless of value.
|
||||
func GetLabelSelector(labelKey string, labelValues ...string) (string, error) {
|
||||
selectionOp := selection.In
|
||||
if len(labelValues) < 1 {
|
||||
selectionOp = selection.Exists
|
||||
}
|
||||
|
||||
labelRequirement, err := labels.NewRequirement(labelKey, selectionOp, labelValues)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
selector := labels.NewSelector().Add(*labelRequirement)
|
||||
return selector.String(), nil
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
pkgCmd "github.com/linkerd/linkerd2/pkg/cmd"
|
||||
"github.com/linkerd/linkerd2/pkg/k8s"
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/selection"
|
||||
)
|
||||
|
||||
func newCmdUninstall() *cobra.Command {
|
||||
|
@ -40,11 +38,10 @@ func uninstallRunE(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
extensionReq, err := labels.NewRequirement(k8s.LinkerdExtensionLabel, selection.In, []string{ExtensionName, LegacyExtensionName})
|
||||
selector, err := pkgCmd.GetLabelSelector(k8s.LinkerdExtensionLabel, ExtensionName, LegacyExtensionName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
selector := labels.NewSelector().Add(*extensionReq)
|
||||
return pkgCmd.Uninstall(ctx, k8sAPI, selector.String())
|
||||
return pkgCmd.Uninstall(ctx, k8sAPI, selector)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue