Skip to content

Commit 159e072

Browse files
pebrcbarkbay
andauthored
Fix incorrectly modelled node shutdown API in Elasticsearch client (#5308) (#5311)
Co-authored-by: Michael Morello <[email protected]>
1 parent 57b67ad commit 159e072

File tree

7 files changed

+60
-13
lines changed

7 files changed

+60
-13
lines changed

pkg/controller/elasticsearch/client/model.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ type LicenseResponse struct {
356356
License License `json:"license"`
357357
}
358358

359-
// StartTrialResponse is the response to the start trial API call.
359+
// StartBasicResponse is the response to the start trial API call.
360360
type StartBasicResponse struct {
361361
Acknowledged bool `json:"acknowledged"`
362362
BasicWasStarted bool `json:"basic_was_started"`
@@ -378,7 +378,7 @@ type RemoteClusters struct {
378378
RemoteClusters map[string]RemoteCluster `json:"remote,omitempty"`
379379
}
380380

381-
// RemoteClusterSeeds is the set of seeds to use in a remote cluster setting.
381+
// RemoteCluster is the set of seeds to use in a remote cluster setting.
382382
type RemoteCluster struct {
383383
Seeds []string `json:"seeds"`
384384
}
@@ -421,8 +421,8 @@ var (
421421
type ShutdownStatus string
422422

423423
var (
424-
// ShutdownStarted means a shutdown request has been accepted and is being processed in Elasticsearch.
425-
ShutdownStarted ShutdownStatus = "STARTED"
424+
// ShutdownInProgress means a shutdown request has been accepted and is being processed in Elasticsearch.
425+
ShutdownInProgress ShutdownStatus = "IN_PROGRESS"
426426
// ShutdownComplete means a shutdown request has been processed and the node can be either restarted or taken out
427427
// of the cluster by an orchestrator.
428428
ShutdownComplete ShutdownStatus = "COMPLETE"
@@ -435,9 +435,9 @@ var (
435435

436436
// ShardMigration is the status of shards that are being migrated away from a node that goes through a shutdown.
437437
type ShardMigration struct {
438-
Status ShutdownStatus `json:"status"`
439-
ShardsRemaining int `json:"shards_remaining"`
440-
Explanation string `json:"explanation"`
438+
Status ShutdownStatus `json:"status"`
439+
ShardMigrationsRemaining int `json:"shard_migrations_remaining"`
440+
Explanation string `json:"explanation"`
441441
}
442442

443443
// PersistentTasks expresses the status of preparing ongoing persistent tasks for a node shutdown.
@@ -455,7 +455,7 @@ type NodeShutdown struct {
455455
NodeID string `json:"node_id"`
456456
Type string `json:"type"`
457457
Reason string `json:"reason"`
458-
ShutdownStartedMillis int `json:"shutdown_started_millis"`
458+
ShutdownStartedMillis int `json:"shutdown_startedmillis"` // missing _ is a serialization inconsistency in Elasticsearch
459459
Status ShutdownStatus `json:"status"`
460460
ShardMigration ShardMigration `json:"shard_migration"`
461461
PersistentTasks PersistentTasks `json:"persistent_tasks"`

pkg/controller/elasticsearch/client/model_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,50 @@ func TestLicenseUpdateResponse_IsSuccess(t *testing.T) {
161161
})
162162
}
163163
}
164+
165+
func TestShutdownResponse(t *testing.T) {
166+
nodeShudownSample := `{
167+
"nodes": [{
168+
"node_id": "PQKHA4xCQd2xErO2fUK-hg",
169+
"type": "REMOVE",
170+
"reason": "2331481",
171+
"shutdown_startedmillis": 1643648932189,
172+
"status": "IN_PROGRESS",
173+
"shard_migration": {
174+
"status": "IN_PROGRESS",
175+
"shard_migrations_remaining": 1
176+
},
177+
"persistent_tasks": {
178+
"status": "COMPLETE"
179+
},
180+
"plugins": {
181+
"status": "COMPLETE"
182+
}
183+
}]
184+
}`
185+
expected := ShutdownResponse{Nodes: []NodeShutdown{
186+
{
187+
NodeID: "PQKHA4xCQd2xErO2fUK-hg",
188+
Type: "REMOVE",
189+
Reason: "2331481",
190+
ShutdownStartedMillis: 1643648932189,
191+
Status: ShutdownInProgress,
192+
ShardMigration: ShardMigration{
193+
Status: ShutdownInProgress,
194+
ShardMigrationsRemaining: 1,
195+
Explanation: "",
196+
},
197+
PersistentTasks: PersistentTasks{
198+
Status: ShutdownComplete,
199+
},
200+
Plugins: Plugins{
201+
Status: ShutdownComplete,
202+
},
203+
},
204+
},
205+
}
206+
207+
var actual ShutdownResponse
208+
require.NoError(t, json.Unmarshal([]byte(nodeShudownSample), &actual))
209+
require.Equal(t, expected, actual)
210+
}

pkg/controller/elasticsearch/driver/downscale.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func calculatePerformableDownscale(
203203
ctx.reconcileState.UpdateElasticsearchShutdownStalled(ctx.resourcesState, ctx.observedState, response.Explanation)
204204
// no need to check other nodes since we remove them in order and this one isn't ready anyway
205205
return performableDownscale, nil
206-
case esclient.ShutdownStarted:
206+
case esclient.ShutdownInProgress:
207207
ctx.reconcileState.UpdateElasticsearchMigrating(ctx.resourcesState, ctx.observedState)
208208
// no need to check other nodes since we remove them in order and this one isn't ready anyway
209209
return performableDownscale, nil

pkg/controller/elasticsearch/driver/upgrade_predicates_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ func TestUpgradePodsDeletion_Delete(t *testing.T) {
821821
newTestPod("masters-0").withRoles(esv1.MasterRole, esv1.DataRole).isHealthy(true).needsUpgrade(true).isInCluster(true),
822822
),
823823
shutdowns: map[string]client.NodeShutdown{
824-
"masters-0": {Status: client.ShutdownStarted},
824+
"masters-0": {Status: client.ShutdownInProgress},
825825
},
826826
maxUnavailable: 1,
827827
shardLister: migration.NewFakeShardLister(client.Shards{}),

pkg/controller/elasticsearch/migration/migrate_data.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (sm *ShardMigration) ShutdownStatus(ctx context.Context, podName string) (s
4848
return shutdown.NodeShutdownStatus{}, err
4949
}
5050
if migrating {
51-
return shutdown.NodeShutdownStatus{Status: esclient.ShutdownStarted}, nil
51+
return shutdown.NodeShutdownStatus{Status: esclient.ShutdownInProgress}, nil
5252
}
5353
return shutdown.NodeShutdownStatus{Status: esclient.ShutdownComplete}, nil
5454
}

pkg/controller/elasticsearch/shutdown/node.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func logStatus(logger logr.Logger, podName string, shutdown esclient.NodeShutdow
131131
switch shutdown.Status {
132132
case esclient.ShutdownComplete:
133133
logger.Info("Node shutdown complete, can start node deletion", "type", shutdown.Type, "node", podName)
134-
case esclient.ShutdownStarted:
134+
case esclient.ShutdownInProgress:
135135
logger.V(1).Info("Node shutdown not over yet, hold off with node deletion", "type", shutdown.Type, "node", podName)
136136
case esclient.ShutdownStalled:
137137
logger.Info("Node shutdown stalled, user intervention maybe required if condition persists", "type", shutdown.Type, "explanation", shutdown.ShardMigration.Explanation, "node", podName)

pkg/controller/elasticsearch/shutdown/node_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestNodeShutdown_Clear(t *testing.T) {
133133
fixture: shutdownFixture,
134134
args: args{
135135
typ: esclient.Remove,
136-
status: &esclient.ShutdownStarted,
136+
status: &esclient.ShutdownInProgress,
137137
},
138138
wantErr: false,
139139
wantDelete: false,

0 commit comments

Comments
 (0)