istio.io/istio@v0.0.0-20240520182934-d79c90f27776/operator/cmd/mesh/upgrade.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  	"github.com/spf13/cobra"
    19  
    20  	"istio.io/istio/istioctl/pkg/cli"
    21  	"istio.io/istio/operator/pkg/util/clog"
    22  )
    23  
    24  type upgradeArgs struct {
    25  	*InstallArgs
    26  }
    27  
    28  // UpgradeCmd upgrades Istio control plane in-place with eligibility checks.
    29  func UpgradeCmd(ctx cli.Context) *cobra.Command {
    30  	rootArgs := &RootArgs{}
    31  	upgradeArgs := &upgradeArgs{
    32  		InstallArgs: &InstallArgs{},
    33  	}
    34  	cmd := &cobra.Command{
    35  		Use:   "upgrade",
    36  		Short: "Upgrade Istio control plane in-place",
    37  		Long:  "The upgrade command is an alias for the install command",
    38  		RunE: func(cmd *cobra.Command, args []string) (e error) {
    39  			l := clog.NewConsoleLogger(cmd.OutOrStdout(), cmd.ErrOrStderr(), installerScope)
    40  			p := NewPrinterForWriter(cmd.OutOrStderr())
    41  			client, err := ctx.CLIClient()
    42  			if err != nil {
    43  				return err
    44  			}
    45  			return Install(client, rootArgs, upgradeArgs.InstallArgs, cmd.OutOrStdout(), l, p)
    46  		},
    47  	}
    48  	addFlags(cmd, rootArgs)
    49  	addInstallFlags(cmd, upgradeArgs.InstallArgs)
    50  	return cmd
    51  }