mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-19 06:26:44 +00:00
Merge pull request #483 from skriss/graceful-shutdown-on-sigs
shutdown gracefully on SIGINT/SIGTERM
This commit is contained in:
@@ -21,10 +21,13 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/heptio/ark/pkg/buildinfo"
|
||||
@@ -221,6 +224,9 @@ func newServer(namespace, baseName, pluginDir string, logger *logrus.Logger) (*s
|
||||
}
|
||||
|
||||
func (s *server) run() error {
|
||||
defer s.pluginManager.CleanupClients()
|
||||
s.handleShutdownSignals()
|
||||
|
||||
if err := s.ensureArkNamespace(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -364,6 +370,17 @@ func (s *server) watchConfig(config *api.Config) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *server) handleShutdownSignals() {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
sig := <-sigs
|
||||
s.logger.Infof("Received signal %s, gracefully shutting down", sig)
|
||||
s.cancelFunc()
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *server) initBackupService(config *api.Config) error {
|
||||
s.logger.Info("Configuring cloud provider for backup service")
|
||||
objectStore, err := getObjectStore(config.BackupStorageProvider.CloudProviderConfig, s.pluginManager)
|
||||
|
||||
@@ -415,3 +415,9 @@ func (_m *MockManager) GetObjectStore(name string) (cloudprovider.ObjectStore, e
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CleanupClients provides a mock function
|
||||
func (_m *MockManager) CleanupClients() {
|
||||
_ = _m.Called()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ func baseConfig() *plugin.ClientConfig {
|
||||
return &plugin.ClientConfig{
|
||||
HandshakeConfig: Handshake,
|
||||
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
|
||||
Managed: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +124,9 @@ type Manager interface {
|
||||
// CloseRestoreItemActions terminates the plugin sub-processes that
|
||||
// are hosting RestoreItemAction plugins for the given restore name.
|
||||
CloseRestoreItemActions(restoreName string) error
|
||||
|
||||
// CleanupClients kills all plugin subprocesses.
|
||||
CleanupClients()
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
@@ -411,3 +415,7 @@ func closeAll(store *clientStore, kind PluginKind, scope string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) CleanupClients() {
|
||||
plugin.CleanupClients()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user