From 035454d1118311962261dc1e303f05637ac52b36 Mon Sep 17 00:00:00 2001
From: Xiaopeng Han
Date: Fri, 8 Sep 2023 02:03:02 +0800
Subject: [PATCH] Fix some install flags not taking effect (#46870)
* fix some flags not taking effect
* lint
* more flag
---
operator/cmd/mesh/operator-init.go | 10 +--------
operator/cmd/mesh/operator-remove.go | 6 -----
operator/cmd/mesh/root.go | 3 ---
operator/cmd/mesh/uninstall.go | 33 ++++++++++------------------
4 files changed, 12 insertions(+), 40 deletions(-)
diff --git a/operator/cmd/mesh/operator-init.go b/operator/cmd/mesh/operator-init.go
index 41033a0eee4d..6ae07f5a4594 100644
--- a/operator/cmd/mesh/operator-init.go
+++ b/operator/cmd/mesh/operator-init.go
@@ -37,10 +37,6 @@ import (
type operatorInitArgs struct {
// inFilenames is the path to the input IstioOperator CR.
inFilename string
- // kubeConfigPath is the path to kube config file.
- kubeConfigPath string
- // context is the cluster context in the kube config.
- context string
// common is shared operator args
common operatorCommonArgs
@@ -53,8 +49,6 @@ func addOperatorInitFlags(cmd *cobra.Command, args *operatorInitArgs) {
hub, tag := buildversion.DockerInfo.Hub, buildversion.DockerInfo.Tag
cmd.PersistentFlags().StringVarP(&args.inFilename, "filename", "f", "", filenameFlagHelpStr)
- cmd.PersistentFlags().StringVarP(&args.kubeConfigPath, "kubeconfig", "c", "", KubeConfigFlagHelpStr)
- cmd.PersistentFlags().StringVar(&args.context, "context", "", ContextFlagHelpStr)
cmd.PersistentFlags().StringVar(&args.common.hub, "hub", hub, HubFlagHelpStr)
cmd.PersistentFlags().StringVar(&args.common.tag, "tag", tag, TagFlagHelpStr)
cmd.PersistentFlags().StringSliceVar(&args.common.imagePullSecrets, "imagePullSecrets", nil, ImagePullSecretsHelpStr)
@@ -123,9 +117,7 @@ func operatorInit(cliClient kube.CLIClient, args *RootArgs, oiArgs *operatorInit
installerScope.Debugf("Using the following manifest to install operator:\n%s\n", mstr)
opts := &applyOptions{
- DryRun: args.DryRun,
- Kubeconfig: oiArgs.kubeConfigPath,
- Context: oiArgs.context,
+ DryRun: args.DryRun,
}
// If CR was passed, we must create a namespace for it and install CR into it.
diff --git a/operator/cmd/mesh/operator-remove.go b/operator/cmd/mesh/operator-remove.go
index ff1584579c46..3e4bc287af39 100644
--- a/operator/cmd/mesh/operator-remove.go
+++ b/operator/cmd/mesh/operator-remove.go
@@ -31,10 +31,6 @@ import (
)
type operatorRemoveArgs struct {
- // kubeConfigPath is the path to kube config file.
- kubeConfigPath string
- // context is the cluster context in the kube config.
- context string
// skipConfirmation determines whether the user is prompted for confirmation.
// If set to true, the user is not prompted and a Yes response is assumed in all cases.
skipConfirmation bool
@@ -49,8 +45,6 @@ type operatorRemoveArgs struct {
}
func addOperatorRemoveFlags(cmd *cobra.Command, oiArgs *operatorRemoveArgs) {
- cmd.PersistentFlags().StringVarP(&oiArgs.kubeConfigPath, "kubeconfig", "c", "", KubeConfigFlagHelpStr)
- cmd.PersistentFlags().StringVar(&oiArgs.context, "context", "", ContextFlagHelpStr)
cmd.PersistentFlags().BoolVarP(&oiArgs.skipConfirmation, "skip-confirmation", "y", false, skipConfirmationFlagHelpStr)
cmd.PersistentFlags().BoolVar(&oiArgs.force, "force", false, ForceFlagHelpStr)
cmd.PersistentFlags().StringVar(&oiArgs.operatorNamespace, "operatorNamespace", operatorDefaultNamespace, OperatorNamespaceHelpstr)
diff --git a/operator/cmd/mesh/root.go b/operator/cmd/mesh/root.go
index 96b89427befd..300d9ec73622 100644
--- a/operator/cmd/mesh/root.go
+++ b/operator/cmd/mesh/root.go
@@ -39,7 +39,6 @@ settings (--set meshConfig.enableTracing=true). See documentation for more info:
const (
ChartsDeprecatedStr = "Deprecated, use --manifests instead."
- ControlPlaneRevStr = "Control plane revision"
revisionFlagHelpStr = `Target control plane revision for the command.`
skipConfirmationFlagHelpStr = `The skipConfirmation determines whether the user is prompted for confirmation.
If set to true, the user is not prompted and a Yes response is assumed in all cases.`
@@ -48,8 +47,6 @@ This flag can be specified multiple times to overlay multiple files. Multiple fi
installationCompleteStr = `Installation complete`
ForceFlagHelpStr = `Proceed even with validation errors.`
MaxConcurrentReconcilesFlagHelpStr = `Defines the concurrency limit for operator to reconcile IstioOperatorSpec in parallel. Default value is 1.`
- KubeConfigFlagHelpStr = `Path to kube config.`
- ContextFlagHelpStr = `The name of the kubeconfig context to use.`
HubFlagHelpStr = `The hub for the operator controller image.`
TagFlagHelpStr = `The tag for the operator controller image.`
ImagePullSecretsHelpStr = `The imagePullSecrets are used to pull the operator image from the private registry,
diff --git a/operator/cmd/mesh/uninstall.go b/operator/cmd/mesh/uninstall.go
index 0511f0b329a8..61e2ef14488c 100644
--- a/operator/cmd/mesh/uninstall.go
+++ b/operator/cmd/mesh/uninstall.go
@@ -35,17 +35,12 @@ import (
"istio.io/istio/operator/pkg/translate"
"istio.io/istio/operator/pkg/util/clog"
"istio.io/istio/operator/pkg/util/progress"
- "istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/log"
proxyinfo "istio.io/istio/pkg/proxy"
)
type uninstallArgs struct {
- // kubeConfigPath is the path to kube config file.
- kubeConfigPath string
- // context is the cluster context in the kube config.
- context string
// skipConfirmation determines whether the user is prompted for confirmation.
// If set to true, the user is not prompted and a Yes response is assumed in all cases.
skipConfirmation bool
@@ -55,8 +50,6 @@ type uninstallArgs struct {
purge bool
// revision is the Istio control plane revision the command targets.
revision string
- // istioNamespace is the target namespace of istio control plane.
- istioNamespace string
// filename is the path of input IstioOperator CR.
filename string
// set is a string with element format "path=value" where path is an IstioOperator path and the value is a
@@ -77,14 +70,10 @@ const (
)
func addUninstallFlags(cmd *cobra.Command, args *uninstallArgs) {
- cmd.PersistentFlags().StringVarP(&args.kubeConfigPath, "kubeconfig", "c", "", KubeConfigFlagHelpStr)
- cmd.PersistentFlags().StringVar(&args.context, "context", "", ContextFlagHelpStr)
cmd.PersistentFlags().BoolVarP(&args.skipConfirmation, "skip-confirmation", "y", false, skipConfirmationFlagHelpStr)
cmd.PersistentFlags().BoolVar(&args.force, "force", false, ForceFlagHelpStr)
cmd.PersistentFlags().BoolVar(&args.purge, "purge", false, "Delete all Istio related sources for all versions")
cmd.PersistentFlags().StringVarP(&args.revision, "revision", "r", "", revisionFlagHelpStr)
- cmd.PersistentFlags().StringVar(&args.istioNamespace, "istioNamespace", constants.IstioSystemNamespace,
- "The namespace of Istio Control Plane.")
cmd.PersistentFlags().StringVarP(&args.filename, "filename", "f", "",
"The filename of the IstioOperator CR.")
cmd.PersistentFlags().StringVarP(&args.manifestsPath, "manifests", "d", "", ManifestsFlagHelpStr)
@@ -118,11 +107,7 @@ func UninstallCmd(ctx cli.Context, logOpts *log.Options) *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
- client, err := ctx.CLIClient()
- if err != nil {
- return err
- }
- return uninstall(cmd, client, rootArgs, uiArgs, logOpts)
+ return uninstall(cmd, ctx, rootArgs, uiArgs, logOpts)
},
}
addFlags(uicmd, rootArgs)
@@ -131,18 +116,22 @@ func UninstallCmd(ctx cli.Context, logOpts *log.Options) *cobra.Command {
}
// uninstall uninstalls control plane by either pruning by target revision or deleting specified manifests.
-func uninstall(cmd *cobra.Command, cliClient kube.CLIClient, rootArgs *RootArgs, uiArgs *uninstallArgs, logOpts *log.Options) error {
+func uninstall(cmd *cobra.Command, ctx cli.Context, rootArgs *RootArgs, uiArgs *uninstallArgs, logOpts *log.Options) error {
l := clog.NewConsoleLogger(cmd.OutOrStdout(), cmd.ErrOrStderr(), installerScope)
if err := configLogs(logOpts); err != nil {
return fmt.Errorf("could not configure logs: %s", err)
}
+ cliClient, err := ctx.CLIClient()
+ if err != nil {
+ return err
+ }
kubeClient, client, err := KubernetesClients(cliClient, l)
if err != nil {
l.LogAndFatal(err)
}
var kubeClientWithRev kube.CLIClient
if uiArgs.revision != "" && uiArgs.revision != "default" {
- kubeClientWithRev, err = kube.NewCLIClient(kube.BuildClientCmd(uiArgs.kubeConfigPath, uiArgs.context), uiArgs.revision)
+ kubeClientWithRev, err = ctx.CLIClientWithRevision(uiArgs.revision)
if err != nil {
return err
}
@@ -185,7 +174,7 @@ func uninstall(cmd *cobra.Command, cliClient kube.CLIClient, rootArgs *RootArgs,
if err != nil {
return err
}
- preCheckWarnings(cmd, kubeClientWithRev, uiArgs, uiArgs.revision, objectsList, nil, l, rootArgs.DryRun)
+ preCheckWarnings(cmd, kubeClientWithRev, uiArgs, ctx.IstioNamespace(), uiArgs.revision, objectsList, nil, l, rootArgs.DryRun)
if err := h.DeleteObjectsList(objectsList, ""); err != nil {
return fmt.Errorf("failed to delete control plane resources by revision: %v", err)
@@ -203,7 +192,7 @@ func uninstall(cmd *cobra.Command, cliClient kube.CLIClient, rootArgs *RootArgs,
if err != nil {
return err
}
- preCheckWarnings(cmd, kubeClientWithRev, uiArgs, iop.Spec.Revision, nil, cpObjects, l, rootArgs.DryRun)
+ preCheckWarnings(cmd, kubeClientWithRev, uiArgs, ctx.IstioNamespace(), iop.Spec.Revision, nil, cpObjects, l, rootArgs.DryRun)
h, err = helmreconciler.NewHelmReconciler(client, kubeClient, iop, opts)
if err != nil {
return fmt.Errorf("failed to create reconciler: %v", err)
@@ -218,10 +207,10 @@ func uninstall(cmd *cobra.Command, cliClient kube.CLIClient, rootArgs *RootArgs,
// preCheckWarnings checks possible breaking changes and issue warnings to users, it checks the following:
// 1. checks proxies still pointing to the target control plane revision.
// 2. lists to be pruned resources if user uninstall by --revision flag.
-func preCheckWarnings(cmd *cobra.Command, kubeClient kube.CLIClient, uiArgs *uninstallArgs,
+func preCheckWarnings(cmd *cobra.Command, kubeClient kube.CLIClient, uiArgs *uninstallArgs, istioNamespace,
rev string, resourcesList []*unstructured.UnstructuredList, objectsList object.K8sObjects, l *clog.ConsoleLogger, dryRun bool,
) {
- pids, err := proxyinfo.GetIDsFromProxyInfo(kubeClient, uiArgs.istioNamespace)
+ pids, err := proxyinfo.GetIDsFromProxyInfo(kubeClient, istioNamespace)
if err != nil {
l.LogAndError(err.Error())
}