Skip to content

Commit

Permalink
* [fix]: update tls gen timeout & imp tls check
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Oct 23, 2024
1 parent d813afd commit de51f88
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
13 changes: 6 additions & 7 deletions cmd/manage/renewtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import (

func NewRenewTLS(f factory.Factory) *cobra.Command {
var force bool
rtls := &cobra.Command{
Use: "renewtls",
Short: "renew tls domain",
Aliases: []string{"rtls", "rt"},
tlsCmd := &cobra.Command{
Use: "tls",
Short: "check and renew tls",
Version: "1.2.11",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return httptls.CheckReNewCertificate(force)
},
}
rtls.Flags().BoolVarP(&force, "force", "f", false, "force renew tls")
return rtls
tlsCmd.Flags().BoolVarP(&force, "force", "f", false, "force renew tls")
return tlsCmd
}
8 changes: 7 additions & 1 deletion internal/pkg/util/httptls/httptls.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,28 @@ func checkCertificate(domain string) (bool, error) {
log := log.GetInstance()
log.Debugf("start check domain %s certificate", domain)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // nolint:gosec
TLSClientConfig: &tls.Config{InsecureSkipVerify: false}, // nolint:gosec
}
client := &http.Client{
Transport: tr,
Timeout: 10 * time.Second,
}
resp, err := client.Get(domain)
if err != nil {
if strings.Contains(err.Error(), "x509: certificate is valid for ingress.local") {
log.Warnf("domain %s use self-signed certificate", domain)
return true, nil
}
return false, err
}
defer func() { _ = resp.Body.Close() }()
for _, cert := range resp.TLS.PeerCertificates {
// 证书过期已过期
if !cert.NotAfter.After(time.Now()) {
log.Warnf("domain %s tls expired", domain)
return true, nil
}
// 证书过期时间在7天内过期
if cert.NotAfter.Sub(time.Now()).Hours() < 7*24 {
log.Warnf("domain %s tls expire after %fh", domain, cert.NotAfter.Sub(time.Now()).Hours())
return true, nil
Expand Down
8 changes: 5 additions & 3 deletions pkg/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (m *Meta) Init() error {
for {
if file.CheckFileExists(defaultTLS) {
m.Log.StopWait()
m.Log.Done("download tls cert success")
m.Log.Done("detect tls cert file success")
if err := qcexec.Command(os.Args[0], "experimental", "kubectl", "apply", "-f", defaultTLS, "-n", common.GetDefaultSystemNamespace(true), "--kubeconfig", common.GetKubeConfig()).Run(); err != nil {
m.Log.Warnf("load default tls cert failed, reason: %v", err)
} else {
Expand All @@ -273,9 +273,11 @@ func (m *Meta) Init() error {
m.Log.Debug("wait for tls cert ready...")
time.Sleep(time.Second * 5)
trywaitsc := time.Now()
if trywaitsc.Sub(waittls) > time.Minute*3 {
if trywaitsc.Sub(waittls) >= time.Minute*5 {
// TODO timeout
m.Log.Debugf("wait tls cert ready, timeout: %v", trywaitsc.Sub(waittls).Seconds())
m.Log.Warnf("wait tls cert ready, timeout: %v", trywaitsc.Sub(waittls).Seconds())
cmd := fmt.Sprintf("%s pt tls", os.Args[0])
m.Log.Warnf("wait cluster install success, please use cmd check: %s", color.SGreen(cmd))
break
}
}
Expand Down

0 comments on commit de51f88

Please sign in to comment.