istio.io/istio@v0.0.0-20240520182934-d79c90f27776/operator/cmd/mesh/root.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package mesh
    16  
    17  import (
    18  	"flag"
    19  
    20  	"github.com/spf13/cobra"
    21  
    22  	"istio.io/istio/istioctl/pkg/cli"
    23  	binversion "istio.io/istio/operator/version"
    24  	"istio.io/istio/pkg/url"
    25  	"istio.io/istio/pkg/version"
    26  )
    27  
    28  var (
    29  	baseVersion    = binversion.OperatorVersionString
    30  	setFlagHelpStr = `Override an IstioOperator value, e.g. to choose a profile
    31  (--set profile=demo), enable or disable components (--set components.cni.enabled=true), or override Istio
    32  settings (--set meshConfig.enableTracing=true). See documentation for more info:` + url.IstioOperatorSpec
    33  	// ManifestsFlagHelpStr is the command line description for --manifests
    34  	ManifestsFlagHelpStr = `Specify a path to a directory of charts and profiles
    35  (e.g. ~/Downloads/istio-` + baseVersion + `/manifests).
    36  `
    37  )
    38  
    39  const (
    40  	ChartsDeprecatedStr         = "Deprecated, use --manifests instead."
    41  	revisionFlagHelpStr         = `Target control plane revision for the command.`
    42  	skipConfirmationFlagHelpStr = `The skipConfirmation determines whether the user is prompted for confirmation.
    43  If set to true, the user is not prompted and a Yes response is assumed in all cases.`
    44  	filenameFlagHelpStr = `Path to file containing IstioOperator custom resource
    45  This flag can be specified multiple times to overlay multiple files. Multiple files are overlaid in left to right order.`
    46  	installationCompleteStr            = `Installation complete`
    47  	ForceFlagHelpStr                   = `Proceed even with validation errors.`
    48  	MaxConcurrentReconcilesFlagHelpStr = `Defines the concurrency limit for operator to reconcile IstioOperatorSpec in parallel. Default value is 1.`
    49  	HubFlagHelpStr                     = `The hub for the operator controller image.`
    50  	TagFlagHelpStr                     = `The tag for the operator controller image.`
    51  	ImagePullSecretsHelpStr            = `The imagePullSecrets are used to pull the operator image from the private registry,
    52  could be secret list separated by comma, eg. '--imagePullSecrets imagePullSecret1,imagePullSecret2'`
    53  	OperatorNamespaceHelpstr  = `The namespace the operator controller is installed into.`
    54  	OperatorRevFlagHelpStr    = `Target revision for the operator.`
    55  	AllOperatorRevFlagHelpStr = `Remove all versions of Istio operator.`
    56  	ComponentFlagHelpStr      = "Specify which component to generate manifests for."
    57  	VerifyCRInstallHelpStr    = "Verify the Istio control plane after installation/in-place upgrade"
    58  )
    59  
    60  type RootArgs struct {
    61  	// DryRun performs all steps except actually applying the manifests or creating output dirs/files.
    62  	DryRun bool
    63  }
    64  
    65  func addFlags(cmd *cobra.Command, rootArgs *RootArgs) {
    66  	cmd.PersistentFlags().BoolVarP(&rootArgs.DryRun, "dry-run", "",
    67  		false, "Console/log output only, make no changes.")
    68  }
    69  
    70  // GetRootCmd returns the root of the cobra command-tree.
    71  func GetRootCmd(ctx cli.Context, args []string) *cobra.Command {
    72  	rootCmd := &cobra.Command{
    73  		Use:          "mesh",
    74  		Short:        "Command line Istio install utility.",
    75  		SilenceUsage: true,
    76  		Long: "This command uses the Istio operator code to generate templates, query configurations and perform " +
    77  			"utility operations.",
    78  	}
    79  	rootCmd.SetArgs(args)
    80  	rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
    81  
    82  	rootCmd.AddCommand(ManifestCmd(ctx))
    83  	rootCmd.AddCommand(InstallCmd(ctx))
    84  	rootCmd.AddCommand(ProfileCmd(ctx))
    85  	rootCmd.AddCommand(OperatorCmd(ctx))
    86  	rootCmd.AddCommand(version.CobraCommand())
    87  	rootCmd.AddCommand(UpgradeCmd(ctx))
    88  
    89  	return rootCmd
    90  }