Skip to content

Commit 60a7fca

Browse files
egeguneshors
andauthored
K8SPSMDB-937: Fix decoding initialSyncStatus to empty interface (#1235)
Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent d5cb2b2 commit 60a7fca

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

healthcheck/health.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package healthcheck
1616

1717
import (
1818
"context"
19+
"encoding/json"
1920

2021
v "github.com/hashicorp/go-version"
2122
"github.com/percona/percona-server-mongodb-operator/pkg/psmdb/mongo"
@@ -110,14 +111,31 @@ func HealthCheckMongodLiveness(client mongo.Client, startupDelaySeconds int64) (
110111
// standalone mongod nodes in an unmanaged cluster doesn't need
111112
// to die before they added to a replset
112113
if res.Err().Error() == ErrNoReplsetConfigStr {
113-
return nil, nil
114+
state := mongo.MemberStateUnknown
115+
return &state, nil
114116
}
115117
return nil, errors.Wrap(res.Err(), "get replsetGetStatus response")
116118
}
117119

120+
// this is a workaround to fix decoding of empty interfaces
121+
// https://jira.mongodb.org/browse/GODRIVER-988
118122
rsStatus := ReplSetStatus{}
119-
if err := res.Decode(&rsStatus); err != nil {
120-
return nil, errors.Wrap(err, "get replsetGetStatus response")
123+
tempResult := bson.M{}
124+
err = res.Decode(&tempResult)
125+
if err != nil {
126+
return nil, errors.Wrap(err, "decode replsetGetStatus response")
127+
}
128+
129+
if err == nil {
130+
result, err := json.Marshal(tempResult)
131+
if err != nil {
132+
return nil, errors.Wrap(err, "marshal temp result")
133+
}
134+
135+
err = json.Unmarshal(result, &rsStatus)
136+
if err != nil {
137+
return nil, errors.Wrap(err, "unmarshal temp result")
138+
}
121139
}
122140

123141
oplogRs := OplogRs{}

0 commit comments

Comments
 (0)