github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/seautil/cmd/certs.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  	"os"
    19  
    20  	"github.com/spf13/cobra"
    21  
    22  	"github.com/alibaba/sealer/logger"
    23  	"github.com/alibaba/sealer/pkg/cert"
    24  )
    25  
    26  type Flag struct {
    27  	AltNames     []string
    28  	NodeName     string
    29  	ServiceCIDR  string
    30  	NodeIP       string
    31  	DNSDomain    string
    32  	CertPath     string
    33  	CertEtcdPath string
    34  }
    35  
    36  var config *Flag
    37  
    38  // certsCmd represents the certs command
    39  var certsCmd = &cobra.Command{
    40  	Use:   "certs",
    41  	Short: "generate kubernetes certes",
    42  	Long:  `seautil cert --node-ip 192.168.0.2 --node-name master1 --dns-domain aliyun.com --alt-names aliyun.local`,
    43  	Run: func(cmd *cobra.Command, args []string) {
    44  		err := cert.GenerateCert(config.CertPath, config.CertEtcdPath, config.AltNames, config.NodeIP, config.NodeName, config.ServiceCIDR, config.DNSDomain)
    45  		if err != nil {
    46  			logger.Error(err)
    47  			os.Exit(-1)
    48  		}
    49  	},
    50  }
    51  
    52  func init() {
    53  	config = &Flag{}
    54  	rootCmd.AddCommand(certsCmd)
    55  
    56  	certsCmd.Flags().StringSliceVar(&config.AltNames, "alt-names", []string{}, "like sealyun.com or 10.103.97.2")
    57  	certsCmd.Flags().StringVar(&config.NodeName, "node-name", "", "like master0")
    58  	certsCmd.Flags().StringVar(&config.ServiceCIDR, "service-cidr", "", "like 10.103.97.2/24")
    59  	certsCmd.Flags().StringVar(&config.NodeIP, "node-ip", "", "like 10.103.97.2")
    60  	certsCmd.Flags().StringVar(&config.DNSDomain, "dns-domain", "cluster.local", "cluster dns domain")
    61  	certsCmd.Flags().StringVar(&config.CertPath, "cert-path", "/etc/kubernetes/pki", "kubernetes cert file path")
    62  	certsCmd.Flags().StringVar(&config.CertEtcdPath, "cert-etcd-path", "/etc/kubernetes/pki/etcd", "kubernetes etcd cert file path")
    63  }