Skip to content

Commit 6a94dec

Browse files
committed
[hbrelay] Allow relay startup even if the password is not yet resolved
During cluster join, the hb relay can start before its secret configuration objects are available. As a result, the heartbeat previously failed to start, leaving no opportunity for proper configuration afterward. This change allows the hb relay to start and wait for password resolution by subscribing to the passwordFrom configuration object. Additional updates: - Added a nil check for the client in the ticker loop to avoid unnecessary executions. - Improved logging in refreshClient to enhance debugging and traceability.
1 parent d1fe893 commit 6a94dec

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

daemon/hb/hbrelay/hbrx.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ func (t *rx) Start(cmdC chan<- any, msgC chan<- *hbtype.Msg) error {
108108
t.cancel()
109109
return
110110
case <-ticker.C:
111+
if t.cli == nil {
112+
continue
113+
}
111114
t.crypto = crypto.Load()
112115
t.onTick()
113116
case ev := <-sub.C:

daemon/hb/hbrelay/main.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (t *cfg) onEvent(ev any) {
132132
t.log.HandleAuditStop(c.Q, c.Subsystems, "hb", strings.Replace(t.id, "hb#", "hb:", 1))
133133
case *msgbus.InstanceConfigUpdated:
134134
if err := t.refreshClient(); err != nil {
135-
t.log.Errorf("refresh client on changed %s: %s", t.passwordFrom.Path, err)
135+
t.log.Warnf("refresh client on changed %s: %s", t.passwordFrom.Path, err)
136136
return
137137
}
138138
}
@@ -152,10 +152,16 @@ func (t *cfg) attachActiveAuditIfAny(ctx context.Context) {
152152

153153
func (t *cfg) refreshClient() error {
154154
if b, err := t.passwordFrom.Decode(); err != nil {
155-
return fmt.Errorf("decode password: %w", err)
155+
t.log.Warnf("decode password key %s from %s: %s", t.passwordFrom.Key, t.passwordFrom.Path, err)
156+
t.cli = nil
157+
return nil
156158
} else if string(b) != t.password {
157159
if t.password != "" {
158-
t.log.Debugf("password changed for %s", t.passwordFrom.Path)
160+
t.log.Debugf("password changed for %s key %s", t.passwordFrom.Path, t.passwordFrom.Key)
161+
} else if t.password == "" {
162+
t.log.Debugf("password is empty for %s key %s", t.passwordFrom.Path, t.passwordFrom.Key)
163+
t.cli = nil
164+
return nil
159165
}
160166
t.password = string(b)
161167
cli, err := client.New(
@@ -172,7 +178,7 @@ func (t *cfg) refreshClient() error {
172178
t.cli = cli
173179
return nil
174180
}
175-
t.log.Debugf("password unhanged for %s", t.passwordFrom.Path)
181+
t.log.Infof("password unhanged for %s", t.passwordFrom.Path)
176182
return nil
177183
}
178184

0 commit comments

Comments
 (0)