github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/sealer/cmd/join.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     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 cmd
    16  
    17  import (
    18  	"github.com/alibaba/sealer/pkg/clusterfile"
    19  	"github.com/spf13/cobra"
    20  
    21  	"github.com/alibaba/sealer/apply"
    22  	"github.com/alibaba/sealer/common"
    23  )
    24  
    25  var clusterName string
    26  var joinArgs *common.RunArgs
    27  
    28  var joinCmd = &cobra.Command{
    29  	Use:   "join",
    30  	Short: "join node to cluster",
    31  	Args:  cobra.NoArgs,
    32  	Example: `
    33  join to default cluster:
    34  	sealer join --masters x.x.x.x --nodes x.x.x.x
    35      sealer join --masters x.x.x.x-x.x.x.y --nodes x.x.x.x-x.x.x.y
    36  `,
    37  	RunE: func(cmd *cobra.Command, args []string) error {
    38  		if clusterName == "" {
    39  			cn, err := clusterfile.GetDefaultClusterName()
    40  			if err != nil {
    41  				return err
    42  			}
    43  			clusterName = cn
    44  		}
    45  		path := common.GetClusterWorkClusterfile(clusterName)
    46  		applier, err := apply.NewScaleApplierFromArgs(path, joinArgs, common.JoinSubCmd)
    47  		if err != nil {
    48  			return err
    49  		}
    50  		return applier.Apply()
    51  	},
    52  }
    53  
    54  func init() {
    55  	joinArgs = &common.RunArgs{}
    56  	rootCmd.AddCommand(joinCmd)
    57  	joinCmd.Flags().StringVarP(&joinArgs.Masters, "masters", "m", "", "set Count or IPList to masters")
    58  	joinCmd.Flags().StringVarP(&joinArgs.Nodes, "nodes", "n", "", "set Count or IPList to nodes")
    59  	joinCmd.Flags().StringVarP(&clusterName, "cluster-name", "c", "", "submit one cluster name")
    60  }