Skip to content

Commit

Permalink
improve tunnel availability
Browse files Browse the repository at this point in the history
  • Loading branch information
aholic committed Jul 7, 2021
1 parent 9426d63 commit 269bc1e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
14 changes: 14 additions & 0 deletions cmd/yurt-tunnel-agent/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package app

import (
"fmt"
"time"

"github.com/openyurtio/openyurt/cmd/yurt-tunnel-agent/app/config"
"github.com/openyurtio/openyurt/cmd/yurt-tunnel-agent/app/options"
Expand All @@ -30,6 +31,8 @@ import (
"github.com/openyurtio/openyurt/pkg/yurttunnel/util"

"github.com/spf13/cobra"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/certificate"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -91,6 +94,17 @@ func Run(cfg *config.CompletedConfig, stopCh <-chan struct{}) error {
}
agentCertMgr.Start()

// 2.1. waiting for the certificate is generated
_ = wait.PollUntil(5*time.Second, func() (bool, error) {
if agentCertMgr.Current() != nil {
return true, nil
}
klog.Infof("certificate %s not signed, waiting...",
projectinfo.GetAgentName())
return false, nil
}, stopCh)
klog.Infof("certificate %s ok", projectinfo.GetAgentName())

// 3. generate a TLS configuration for securing the connection to server
tlsCfg, err := pki.GenTLSConfigUseCertMgrAndCA(agentCertMgr,
tunnelServerAddr, constants.YurttunnelCAFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/yurt-tunnel-server/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (o *ServerOptions) Config() (*config.Config, error) {
if err != nil {
return nil, err
}
cfg.SharedInformerFactory = informers.NewSharedInformerFactory(cfg.Client, 10*time.Second)
cfg.SharedInformerFactory = informers.NewSharedInformerFactory(cfg.Client, 24*time.Hour)

klog.Infof("yurttunnel server config: %#+v", cfg)
return cfg, nil
Expand Down
25 changes: 22 additions & 3 deletions pkg/yurttunnel/pki/certmanager/csrapprover.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,25 @@ func enqueueObj(wq workqueue.RateLimitingInterface, obj interface{}) {
runtime.HandleError(err)
return
}
wq.AddRateLimited(key)

csr, ok := obj.(*certificates.CertificateSigningRequest)
if !ok {
klog.Errorf("%s is not a csr", key)
return
}

if !isYurttunelCSR(csr) {
klog.Infof("csr(%s) is not %s csr", csr.GetName(), projectinfo.GetTunnelName())
return
}

approved, denied := checkCertApprovalCondition(&csr.Status)
if !approved && !denied {
klog.Infof("non-approved and non-denied csr, enqueue: %s", key)
wq.AddRateLimited(key)
}

klog.V(4).Infof("approved or denied csr, ignore it: %s", key)
}

// NewCSRApprover creates a new YurttunnelCSRApprover
Expand Down Expand Up @@ -139,6 +157,7 @@ func approveYurttunnelCSR(
csrClient typev1beta1.CertificateSigningRequestInterface) error {
csr, ok := obj.(*certificates.CertificateSigningRequest)
if !ok {
klog.Infof("object is not csr: %v", obj)
return nil
}

Expand All @@ -149,12 +168,12 @@ func approveYurttunnelCSR(

approved, denied := checkCertApprovalCondition(&csr.Status)
if approved {
klog.V(4).Infof("csr(%s) is approved", csr.GetName())
klog.Infof("csr(%s) is approved", csr.GetName())
return nil
}

if denied {
klog.V(4).Infof("csr(%s) is denied", csr.GetName())
klog.Infof("csr(%s) is denied", csr.GetName())
return nil
}

Expand Down

0 comments on commit 269bc1e

Please sign in to comment.