Skip to content

Commit 1cd3b44

Browse files
authored
fix: create new context for bare-metal deployer (#148)
* create new context for bare-metal deployer Signed-off-by: sh2 <shawnhxh@outlook.com> * rm the useless stop func Signed-off-by: sh2 <shawnhxh@outlook.com> --------- Signed-off-by: sh2 <shawnhxh@outlook.com>
1 parent 6366341 commit 1cd3b44

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pkg/cmd/gtctl/cluster/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func NewCluster(args []string, options ClusterCliOptions, l logger.Logger) error
128128
ctx, cancel = context.WithTimeout(ctx, time.Duration(options.Timeout)*time.Second)
129129
defer cancel()
130130
}
131-
ctx, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
131+
ctx, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
132132
defer stop()
133133

134134
clusterDeployer, err := newDeployer(l, clusterName, &options)

pkg/deployer/baremetal/deployer.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
"fmt"
2020
"os"
2121
"os/exec"
22+
"os/signal"
2223
"path"
2324
"strings"
2425
"sync"
26+
"syscall"
2527
"time"
2628

2729
"gopkg.in/yaml.v3"
@@ -39,6 +41,7 @@ type Deployer struct {
3941
am *ArtifactManager
4042
wg sync.WaitGroup
4143
bm *component.BareMetalCluster
44+
ctx context.Context
4245

4346
createNoDirs bool
4447
workingDirs component.WorkingDirs
@@ -54,9 +57,12 @@ var _ Interface = &Deployer{}
5457
type Option func(*Deployer)
5558

5659
func NewDeployer(l logger.Logger, clusterName string, opts ...Option) (Interface, error) {
60+
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
61+
5762
d := &Deployer{
5863
logger: l,
5964
config: config.DefaultConfig(),
65+
ctx: ctx,
6066
}
6167

6268
for _, opt := range opts {
@@ -258,15 +264,15 @@ func (d *Deployer) CreateGreptimeDBCluster(ctx context.Context, clusterName stri
258264
return err
259265
}
260266

261-
if err := d.bm.MetaSrv.Start(ctx, binary); err != nil {
267+
if err := d.bm.MetaSrv.Start(d.ctx, binary); err != nil {
262268
return err
263269
}
264270

265-
if err := d.bm.Datanode.Start(ctx, binary); err != nil {
271+
if err := d.bm.Datanode.Start(d.ctx, binary); err != nil {
266272
return err
267273
}
268274

269-
if err := d.bm.Frontend.Start(ctx, binary); err != nil {
275+
if err := d.bm.Frontend.Start(d.ctx, binary); err != nil {
270276
return err
271277
}
272278

@@ -318,7 +324,7 @@ func (d *Deployer) CreateEtcdCluster(ctx context.Context, clusterName string, op
318324
return err
319325
}
320326

321-
if err = d.bm.Etcd.Start(ctx, bin); err != nil {
327+
if err = d.bm.Etcd.Start(d.ctx, bin); err != nil {
322328
return err
323329
}
324330

@@ -392,7 +398,7 @@ func (d *Deployer) Wait(ctx context.Context, option component.DeleteOptions) err
392398

393399
d.logger.V(3).Info("Cluster shutting down. Cleaning allocated resources.")
394400

395-
<-ctx.Done()
401+
<-d.ctx.Done()
396402
// Delete cluster after closing, which can only happens in the foreground.
397403
if err := d.deleteGreptimeDBClusterForeground(ctx, option); err != nil {
398404
return err

0 commit comments

Comments
 (0)