github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/sealer/cmd/check.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  	"fmt"
    19  
    20  	"github.com/spf13/cobra"
    21  
    22  	"github.com/alibaba/sealer/pkg/checker"
    23  )
    24  
    25  type CheckArgs struct {
    26  	Pre  bool
    27  	Post bool
    28  }
    29  
    30  var checkArgs *CheckArgs
    31  
    32  // pushCmd represents the push command
    33  var checkCmd = &cobra.Command{
    34  	Use:     "check",
    35  	Short:   "check the state of cluster ",
    36  	Example: `sealer check --pre or sealer check --post`,
    37  	Args:    cobra.NoArgs,
    38  	RunE: func(cmd *cobra.Command, args []string) error {
    39  		if checkArgs.Pre && checkArgs.Post {
    40  			return fmt.Errorf("don't allow to set two flags --pre and --post")
    41  		}
    42  		list := []checker.Interface{checker.NewNodeChecker(), checker.NewSvcChecker(), checker.NewPodChecker()}
    43  		if checkArgs.Pre {
    44  			return checker.RunCheckList(list, nil, checker.PhasePre)
    45  		}
    46  		return checker.RunCheckList(list, nil, checker.PhasePost)
    47  	},
    48  }
    49  
    50  func init() {
    51  	checkArgs = &CheckArgs{}
    52  	rootCmd.AddCommand(checkCmd)
    53  	checkCmd.Flags().BoolVar(&checkArgs.Pre, "pre", false, "Check dependencies before cluster creation")
    54  	checkCmd.Flags().BoolVar(&checkArgs.Post, "post", false, "Check the status of the cluster after it is created")
    55  }