Unverified Commit 5bfc7f0d authored by cuisongliu's avatar cuisongliu Committed by GitHub
Browse files

ci(develop) fix golint for code and lic (#736)

parent 394a8954
Showing with 179 additions and 270 deletions
+179 -270
......@@ -21,8 +21,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Run Check License
run:
run: |
wget https://github.com/google/addlicense/releases/download/v1.0.0/addlicense_1.0.0_Linux_x86_64.tar.gz
tar -zxvf addlicense_1.0.0_Linux_x86_64.tar.gz -C $(go env GOPATH)/bin
chmod a+x $(go env GOPATH)/bin/addlicense
......
......@@ -9,8 +9,6 @@ run:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
modules-download-mode: vendor
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
......@@ -39,11 +37,14 @@ linters:
- ifshort
- unconvert
issues:
exclude-rules:
- linters:
- golint
text: "AccessKeyId"
linters-settings:
errcheck:
check-type-assertions: false
ignore: fmt:.*,io/ioutil:^Read.*
exclude-functions:
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
......
<!--
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-->
# Table of Contents
- [3.3.9-rc.6](#671)
......
......@@ -70,7 +70,7 @@ To put forward a PR, we assume you have registered a GitHub ID. Then you could f
1. **FORK** sealos to your repository. To make this work, you just need to click the button Fork in right-left of [fanux/sealos](https://github.com/fanux/sealos) main page. Then you will end up with your repository in `https://github.com/<your-username>/sealos`, in which `your-username` is your GitHub username.
1. **CLONE** your own repository to develop locally. Use `git clone https://github.com/<your-username>/sealos.git` to clone repository to your local machine. Then you can create new branches to finish the change you wish to make.
1. **CLONE** your own repository to master locally. Use `git clone https://github.com/<your-username>/sealos.git` to clone repository to your local machine. Then you can create new branches to finish the change you wish to make.
1. **Set Remote** upstream to be `https://github.com/fanux/sealos.git` using the following two commands:
......@@ -120,11 +120,11 @@ To put forward a PR, we assume you have registered a GitHub ID. Then you could f
git push // push to your forked repository after rebase done
```
1. **File a pull request** to fanux/sealos:develop
1. **File a pull request** to fanux/sealos:master
### Branch Definition
Right now we assume every contribution via pull request is for [branch develop](https://github.com/fanux/sealos/tree/develop) in sealos. Before contributing, be aware of branch definition would help a lot.
Right now we assume every contribution via pull request is for [branch master](https://github.com/fanux/sealos/tree/master) in sealos. Before contributing, be aware of branch definition would help a lot.
As a contributor, keep in mind again that every contribution via pull request is for branch master. While in project sealos, there are several other branches, we generally call them rc branches, release branches and backport branches.
......
......@@ -66,7 +66,7 @@ filelicense: SHELL:=/bin/bash
filelicense: ## add license
for file in ${Dirs} ; do \
if [[ $$file != '_output' && $$file != 'docs' && $$file != 'vendor' && $$file != 'logger' && $$file != 'applications' ]]; then \
$(ADDLICENSE_BIN) -y $(shell date +"%Y") -c "Alibaba Group Holding Ltd." -f hack/template/LICENSE ./$$file ; \
$(ADDLICENSE_BIN) -y $(shell date +"%Y") -c "sealos." -f hack/template/LICENSE ./$$file ; \
fi \
done
......@@ -74,7 +74,7 @@ install-ossutil: ## check ossutil if not exist install ossutil tools
ifeq (, $(shell which ossutil))
@{ \
set -e ;\
go install github.com/aliyun/ossutil@latest ;\
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(GOBIN) v2.2.0 ;\
}
OSSUTIL_BIN=$(GOBIN)/ossutil
else
......
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cert
import (
......
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cert
import (
"fmt"
"os"
"github.com/wonderivan/logger"
"github.com/fanux/sealos/pkg/logger"
)
// CMD return sealos cert command
......@@ -42,5 +56,5 @@ func GenerateCert(certPATH, certEtcdPATH string, altNames []string, hostIP, host
logger.Error("generator cert config failed %s", err)
os.Exit(-1)
}
certConfig.GenerateAll()
_ = certConfig.GenerateAll()
}
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cert
import (
......@@ -8,7 +22,7 @@ import (
"os"
"path"
"github.com/wonderivan/logger"
"github.com/fanux/sealos/pkg/logger"
)
var (
......@@ -62,7 +76,7 @@ func CaList(CertPath, CertEtcdPath string) []Config {
}
}
func CertList(CertPath, CertEtcdPath string) []Config {
func List(CertPath, CertEtcdPath string) []Config {
return []Config{
{
Path: CertPath,
......@@ -198,8 +212,7 @@ func NewSealosCertMetaData(certPATH, certEtcdPATH string, apiServerIPAndDomains
}
data.APIServer.DNSNames[altName] = altName
}
ip := net.ParseIP(nodeIP)
if ip != nil {
if ip := net.ParseIP(nodeIP); ip != nil {
data.APIServer.IPs[ip.String()] = ip
}
......@@ -213,8 +226,8 @@ func (meta *SealosCertMetaData) apiServerAltName(certList *[]Config) {
(*certList)[APIserverCert].AltNames.DNSNames[dns] = dns
}
svcDns := fmt.Sprintf("kubernetes.default.svc.%s", meta.DNSDomain)
(*certList)[APIserverCert].AltNames.DNSNames[svcDns] = svcDns
svcDNS := fmt.Sprintf("kubernetes.default.svc.%s", meta.DNSDomain)
(*certList)[APIserverCert].AltNames.DNSNames[svcDNS] = svcDNS
(*certList)[APIserverCert].AltNames.DNSNames[meta.NodeName] = meta.NodeName
for _, ip := range meta.APIServer.IPs {
......@@ -268,10 +281,10 @@ func (meta *SealosCertMetaData) generatorServiceAccountKeyPaire() error {
func (meta *SealosCertMetaData) GenerateAll() error {
cas := CaList(meta.CertPath, meta.CertEtcdPath)
certs := CertList(meta.CertPath, meta.CertEtcdPath)
certs := List(meta.CertPath, meta.CertEtcdPath)
meta.apiServerAltName(&certs)
meta.etcdAltAndCommonName(&certs)
meta.generatorServiceAccountKeyPaire()
_ = meta.generatorServiceAccountKeyPaire()
CACerts := map[string]*x509.Certificate{}
CAKeys := map[string]crypto.Signer{}
......
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cert
import (
......
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cert
import (
......@@ -5,7 +19,6 @@ import (
"crypto"
"crypto/x509"
"fmt"
"io"
"os"
"path/filepath"
......@@ -14,7 +27,7 @@ import (
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/keyutil"
"github.com/wonderivan/logger"
"github.com/fanux/sealos/pkg/logger"
)
// clientCertAuth struct holds info required to build a client certificate to provide authentication info in a kubeconfig object
......@@ -64,9 +77,7 @@ func CreateKubeConfigFile(kubeConfigFileName string, outDir string, cfg Config,
// createKubeConfigFiles creates all the requested kubeconfig files.
// If kubeconfig files already exists, they are used only if evaluated equal; otherwise an error is returned.
func createKubeConfigFiles(outDir string, cfg Config, nodeName, controlPlaneEndpoint, clusterName string, kubeConfigFileNames ...string) error {
// gets the KubeConfigSpecs, actualized for the current InitConfiguration
func createKubeConfigFiles(outDir string, cfg Config, nodeName, controlPlaneEndpoint, clusterName string, kubeConfigFileNames ...string) error { // gets the KubeConfigSpecs, actualized for the current InitConfiguration
specs, err := getKubeConfigSpecs(cfg, nodeName, controlPlaneEndpoint)
if err != nil {
return err
......@@ -97,7 +108,6 @@ func createKubeConfigFiles(outDir string, cfg Config, nodeName, controlPlaneEndp
// getKubeConfigSpecs returns all KubeConfigSpecs actualized to the context of the current InitConfiguration
// NB. this methods holds the information about how kubeadm creates kubeconfig files.
func getKubeConfigSpecs(cfg Config, nodeName, controlPlaneEndpoint string) (map[string]*kubeConfigSpec, error) {
caCert, caKey, err := LoadCaCertAndKeyFromDisk(cfg)
if err != nil {
return nil, errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
......@@ -153,7 +163,6 @@ func getKubeConfigSpecs(cfg Config, nodeName, controlPlaneEndpoint string) (map[
// buildKubeConfigFromSpec creates a kubeconfig object for the given kubeConfigSpec
func buildKubeConfigFromSpec(spec *kubeConfigSpec, clustername string) (*clientcmdapi.Config, error) {
// If this kubeconfig should use token
if spec.TokenAuth != nil {
// create a kubeconfig with a token
......@@ -268,107 +277,6 @@ func createKubeConfigFileIfNotExists(outDir, filename string, config *clientcmda
return nil
}
// WriteKubeConfigWithClientCert writes a kubeconfig file - with a client certificate as authentication info - to the given writer.
func WriteKubeConfigWithClientCert(out io.Writer, cfg Config, clientName, controlPlaneEndpoint, clusterName string, organizations []string) error {
// creates the KubeConfigSpecs, actualized for the current InitConfiguration
caCert, caKey, err := LoadCaCertAndKeyFromDisk(cfg)
if err != nil {
return errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
}
if len(controlPlaneEndpoint) == 0 {
return errors.New("controlPlaneEndpoint can not be empty")
}
spec := &kubeConfigSpec{
ClientName: clientName,
APIServer: controlPlaneEndpoint,
CACert: caCert,
ClientCertAuth: &clientCertAuth{
CAKey: caKey,
Organizations: organizations,
},
}
return writeKubeConfigFromSpec(out, spec, clusterName)
}
// WriteKubeConfigWithToken writes a kubeconfig file - with a token as client authentication info - to the given writer.
func WriteKubeConfigWithToken(out io.Writer, cfg Config, clientName, controlPlaneEndpoint, clusterName, token string) error {
// creates the KubeConfigSpecs, actualized for the current InitConfiguration
caCert, _, err := LoadCaCertAndKeyFromDisk(cfg)
if err != nil {
return errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
}
if len(controlPlaneEndpoint) == 0 {
return errors.New("controlPlaneEndpoint can not be empty")
}
spec := &kubeConfigSpec{
ClientName: clientName,
APIServer: controlPlaneEndpoint,
CACert: caCert,
TokenAuth: &tokenAuth{
Token: token,
},
}
return writeKubeConfigFromSpec(out, spec, clusterName)
}
// writeKubeConfigFromSpec creates a kubeconfig object from a kubeConfigSpec and writes it to the given writer.
func writeKubeConfigFromSpec(out io.Writer, spec *kubeConfigSpec, clustername string) error {
// builds the KubeConfig object
config, err := buildKubeConfigFromSpec(spec, clustername)
if err != nil {
return err
}
// writes the kubeconfig to disk if it not exists
configBytes, err := clientcmd.Write(*config)
if err != nil {
return errors.Wrap(err, "failure while serializing admin kubeconfig")
}
fmt.Fprintln(out, string(configBytes))
return nil
}
// ValidateKubeconfigsForExternalCA check if the kubeconfig file exist and has the expected CA and server URL using kubeadmapi.InitConfiguration.
func ValidateKubeconfigsForExternalCA(outDir string, cfg Config, controlPlaneEndpoint string) error {
kubeConfigFileNames := []string{
"admin.conf",
"kubelet.conf",
"controller-manager.conf",
"scheduler.conf",
}
// Creates a kubeconfig file with the target CA and server URL
// to be used as a input for validating user provided kubeconfig files
caCert, _, err := LoadCaCertAndKeyFromDisk(cfg)
if err != nil {
return err
}
if len(controlPlaneEndpoint) == 0 {
return errors.New("controlPlaneEndpoint can not be empty")
}
validationConfig := CreateBasic(controlPlaneEndpoint, "dummy", "dummy", EncodeCertPEM(caCert))
// validate user provided kubeconfig files
for _, kubeConfigFileName := range kubeConfigFileNames {
if err = validateKubeConfig(outDir, kubeConfigFileName, validationConfig); err != nil {
return errors.Wrapf(err, "the %s file does not exists or it is not valid", kubeConfigFileName)
}
}
return nil
}
// cmd/kubeadm/app/util/kubeconfig/kubeconfig.go
// CreateBasic creates a basic, general KubeConfig object that then can be extended
func CreateBasic(serverURL, clusterName, userName string, caCert []byte) *clientcmdapi.Config {
......
// Copyright © 2020 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
......
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
......@@ -18,8 +18,8 @@ import (
"os"
"github.com/fanux/sealos/install"
"github.com/fanux/sealos/pkg/logger"
"github.com/spf13/cobra"
"github.com/wonderivan/logger"
)
var exampleCleanCmd = `
......@@ -71,27 +71,9 @@ func CleanCmdFunc(cmd *cobra.Command, args []string) {
deleteNodes := install.ParseIPs(install.NodeIPs)
deleteMasters := install.ParseIPs(install.MasterIPs)
c := &install.SealConfig{}
err := c.Load(cfgFile)
if err != nil {
// comment: if cfgFile is not exist; do not use sealos clean something.
// its danger for sealos do clean nodes without `~/.sealos/config.yaml`
//// 判断错误是否为配置文件不存在
//if errors.Is(err, os.ErrNotExist) {
// _, err = fmt.Fprint(os.Stdout, "Please enter the password to connect to the node:\n")
// if err != nil {
// logger.Error("fmt.Fprint err", err)
// os.Exit(-1)
// }
// passwordTmp, err := terminal.ReadPassword(int(os.Stdin.Fd()))
// if err != nil {
// logger.Error("read password err", err)
// os.Exit(-1)
// }
// install.SSHConfig.Password = string(passwordTmp)
//} else {
if err := c.Load(cfgFile); err != nil {
logger.Error(err)
os.Exit(-1)
//}
}
// 使用 sealos clean --node 不小心写了 masterip.
......@@ -107,7 +89,6 @@ func CleanCmdFunc(cmd *cobra.Command, args []string) {
install.BuildClean(deleteNodes, deleteMasters)
c.Dump(cfgFile)
}
// IsExistNodes
......
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
......@@ -26,9 +26,6 @@ import (
var p bool
func prompt() {
}
// cloudCmd represents the cloud command
var cloudCmd = &cobra.Command{
Use: "cloud",
......
/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"fmt"
"github.com/fanux/sealos/net"
"github.com/fanux/sealos/pkg/logger"
"github.com/spf13/cobra"
"github.com/wonderivan/logger"
)
var cniType string
......@@ -39,7 +38,7 @@ to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
if cniType != net.CALICO && cniType != net.FLANNEL && cniType != net.CILIUM {
logger.Error("unsupport cni: ", cniType)
return
return
}
if version == "" {
logger.Error("cni version should not nil ", version)
......@@ -49,7 +48,7 @@ to quickly create a Cobra application.`,
Interface: "interface=eth.*|en.*|em.*",
IPIP: true,
MTU: "1440",
Version: version,
Version: version,
}).Manifests("")
fmt.Println(yaml)
},
......@@ -58,8 +57,8 @@ to quickly create a Cobra application.`,
func init() {
rootCmd.AddCommand(cniCmd)
cniCmd.Flags().StringVarP(&cniType,"cni-type", "t", net.CALICO, "print cni yaml, cni tpye just like, calico.flannel.cilium")
cniCmd.Flags().StringVarP(&version,"version", "v", "", "calico version")
cniCmd.Flags().StringVarP(&cniType, "cni-type", "t", net.CALICO, "print cni yaml, cni tpye just like, calico.flannel.cilium")
cniCmd.Flags().StringVarP(&version, "version", "v", "", "calico version")
// Here you will define your flags and configuration settings.
......
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
......@@ -23,7 +8,7 @@ import (
"github.com/spf13/cobra"
"github.com/wonderivan/logger"
"github.com/fanux/sealos/pkg/logger"
)
const defaultCopyRight = `
......@@ -132,7 +117,7 @@ func runCompletionBash(out io.Writer, copyRight string, sealos *cobra.Command) e
func runCompletionZsh(out io.Writer, copyRight string, sealos *cobra.Command) error {
zshHead := "#compdef sealos\n"
out.Write([]byte(zshHead))
_, _ = out.Write([]byte(zshHead))
if len(copyRight) == 0 {
copyRight = defaultCopyRight
......@@ -229,17 +214,17 @@ __sealos_convert_bash_to_zsh() {
-e "s/\\\$(type${RWORD}/\$(__sealos_type/g" \
<<'BASH_COMPLETION_EOF'
`
out.Write([]byte(zshInitialization))
_, _ = out.Write([]byte(zshInitialization))
buf := new(bytes.Buffer)
sealos.GenBashCompletion(buf)
out.Write(buf.Bytes())
_ = sealos.GenBashCompletion(buf)
_, _ = out.Write(buf.Bytes())
zshTail := `
BASH_COMPLETION_EOF
}
__sealos_bash_source <(__sealos_convert_bash_to_zsh)
`
out.Write([]byte(zshTail))
_, _ = out.Write([]byte(zshTail))
return nil
}
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
......
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
......@@ -46,11 +45,11 @@ var deleteCmd = &cobra.Command{
Example: deleteExamlpe,
Run: func(cmd *cobra.Command, args []string) {
cfg := appmanager.GetDeleteFlags(AppURL)
appmanager.DeleteApp(cfg, cfgFile)
_ = appmanager.DeleteApp(cfg, cfgFile)
},
PreRun: func(cmd *cobra.Command, args []string) {
if install.ExitDeleteCase(AppURL) {
cmd.Help()
_ = cmd.Help()
os.Exit(install.ErrorExitOSCase)
}
},
......
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
......@@ -23,7 +22,7 @@ import (
"github.com/spf13/cobra"
"github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
"github.com/fanux/sealos/pkg/logger"
)
var exampleCmd = `
......@@ -86,7 +85,7 @@ func NewEtcdSaveCommand() *cobra.Command {
cmd.Flags().StringVar(&install.SnapshotName, "name", install.ETCDSNAPSHOTDEFAULTNAME, "Specify snapshot name")
cmd.Flags().StringVar(&install.EtcdBackDir, "backupPath", install.ETCDDEFAULTBACKUPDIR, "Specify snapshot backup dir")
cmd.Flags().StringVar(&install.BucketName, "bucket", "", "oss bucketName to save snapshot")
cmd.Flags().StringVar(&install.AccessKeyId, "aliId", "", "aliyun accessKeyId to save snapshot")
cmd.Flags().StringVar(&install.AccessKeyID, "aliId", "", "aliyun accessKeyId to save snapshot")
cmd.Flags().StringVar(&install.AccessKeySecrets, "aliKey", "", "aliyun accessKeySecrets to save snapshot")
cmd.Flags().StringVar(&install.OssEndpoint, "ep", "", "aliyun endpoints to save snapshot")
cmd.Flags().StringVar(&install.ObjectPath, "objectPath", "", "aliyun oss objectPath to save snapshot, like: /sealos/snapshots/")
......@@ -118,7 +117,7 @@ func NewEtcdHealthCommand() *cobra.Command {
func EtcdSaveCmdFunc(cmd *cobra.Command, args []string) {
e := install.GetEtcdBackFlags(cfgFile)
err := e.Save(install.InDocker)
if err == nil && e.AccessKeyId != "" {
if err == nil && e.AccessKeyID != "" {
e.Dump(cfgFile)
}
logger.Info("Finished saving/uploading snapshot [%s]", e.Name)
......@@ -144,8 +143,7 @@ func EtcdRestoreCmdFunc(cmd *cobra.Command, args []string) {
time.Sleep(time.Second * 10)
logger.Info("send restore file to etcd master node and start etcd")
// send restore file to etcd master node to start etcd
err := e.AfterRestore()
if err != nil {
if err := e.AfterRestore(); err != nil {
logger.Error(err)
logger.Info("Start RecoveryKuBeCluster")
e.RecoveryKuBeCluster(tmpdir)
......
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
......@@ -47,7 +46,6 @@ func init() {
execCmd.Flags().StringVar(&install.ExecCommand, "cmd", "", "exec command string")
execCmd.Flags().StringVar(&install.Label, "label", "", "kubernetes labels like node-role.kubernetes.io/master=")
execCmd.Flags().StringSliceVar(&install.ExecNode, "node", []string{}, "node ip or hostname in kubernetes")
}
func ExecCmdFunc(cmd *cobra.Command, args []string) {
......
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
// Copyright © 2021 sealos.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
......@@ -22,7 +22,7 @@ import (
"github.com/fanux/sealos/cert"
"github.com/fanux/sealos/install"
"github.com/fanux/sealos/net"
"github.com/wonderivan/logger"
"github.com/fanux/sealos/pkg/logger"
)
var contact = `
......@@ -98,7 +98,7 @@ var initCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
// 使用了cfgFile 就不进行preRun了
if cfgFile == "" && install.ExitInitCase() {
cmd.Help()
_ = cmd.Help()
os.Exit(install.ErrorExitOSCase)
}
},
......@@ -116,13 +116,13 @@ func init() {
initCmd.Flags().StringVar(&install.KubeadmFile, "kubeadm-config", "", "kubeadm-config.yaml template file")
initCmd.Flags().StringVar(&install.ApiServer, "apiserver", "apiserver.cluster.local", "apiserver domain name")
initCmd.Flags().StringVar(&install.APIServer, "apiserver", "apiserver.cluster.local", "apiserver domain name")
initCmd.Flags().StringVar(&install.VIP, "vip", "10.103.97.2", "virtual ip")
initCmd.Flags().StringSliceVar(&install.MasterIPs, "master", []string{}, "kubernetes multi-masters ex. 192.168.0.2-192.168.0.4")
initCmd.Flags().StringSliceVar(&install.NodeIPs, "node", []string{}, "kubernetes multi-nodes ex. 192.168.0.5-192.168.0.5")
initCmd.Flags().StringSliceVar(&install.CertSANS, "cert-sans", []string{}, "kubernetes apiServerCertSANs ex. 47.0.0.22 sealyun.com ")
initCmd.Flags().StringVar(&install.PkgUrl, "pkg-url", "", "http://store.lameleg.com/kube1.14.1.tar.gz download offline package url, or file location ex. /root/kube1.14.1.tar.gz")
initCmd.Flags().StringVar(&install.PkgURL, "pkg-url", "", "http://store.lameleg.com/kube1.14.1.tar.gz download offline package url, or file location ex. /root/kube1.14.1.tar.gz")
initCmd.Flags().StringVar(&install.Version, "version", "", "version is kubernetes version")
initCmd.Flags().StringVar(&install.Repo, "repo", "k8s.gcr.io", "choose a container registry to pull control plane images from")
initCmd.Flags().StringVar(&install.PodCIDR, "podcidr", "100.64.0.0/10", "Specify range of IP addresses for the pod network")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment