Skip to content

Commit

Permalink
fix: The system cannot be restarted the first time the configuration …
Browse files Browse the repository at this point in the history
…is set. (#3013)
  • Loading branch information
icey-yu authored Dec 27, 2024
1 parent 1af3184 commit 930a9fd
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/common/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,22 @@ func (r *RootCmd) updateConfigFromEtcd(opts *CmdOpts) error {
}

update := func(configFileName string, configStruct any) error {
ctx := context.TODO()
key := disetcd.BuildKey(configFileName)
etcdRes, err := r.etcdClient.Get(context.TODO(), key)
if err != nil || etcdRes.Count == 0 {
etcdRes, err := r.etcdClient.Get(ctx, key)
if err != nil {
log.ZWarn(ctx, "root cmd updateConfigFromEtcd, etcd Get err: %v", errs.Wrap(err))
return nil
}
if etcdRes.Count == 0 {
data, err := json.Marshal(configStruct)
if err != nil {
return errs.ErrArgs.WithDetail(err.Error()).Wrap()
}
_, err = r.etcdClient.Put(ctx, disetcd.BuildKey(configFileName), string(data))
if err != nil {
log.ZWarn(ctx, "root cmd updateConfigFromEtcd, etcd Put err: %v", errs.Wrap(err))
}
return nil
}
err = json.Unmarshal(etcdRes.Kvs[0].Value, configStruct)
Expand Down

0 comments on commit 930a9fd

Please sign in to comment.