Skip to content

Commit

Permalink
Fix some install flags not taking effect (istio#46870)
Browse files Browse the repository at this point in the history
* fix some flags not taking effect

* lint

* more flag
  • Loading branch information
hanxiaop authored Sep 7, 2023
1 parent 199c35c commit 035454d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 40 deletions.
10 changes: 1 addition & 9 deletions operator/cmd/mesh/operator-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions operator/cmd/mesh/operator-remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions operator/cmd/mesh/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
Expand All @@ -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,
Expand Down
33 changes: 11 additions & 22 deletions operator/cmd/mesh/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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())
}
Expand Down

0 comments on commit 035454d

Please sign in to comment.