Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch trust settings: Only add them to the update payload if there are changes. #859

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/859.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/deployment: Avoid sending an update for trust settings if they have not changed.
```
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
return nil, diags
}

var esState *ElasticsearchTF

Check failure on line 64 in ec/ecresource/deploymentresource/elasticsearch/v2/elasticsearch_payload.go

View workflow job for this annotation

GitHub Actions / Unit

other declaration of esState) (typecheck)

Check failure on line 64 in ec/ecresource/deploymentresource/elasticsearch/v2/elasticsearch_payload.go

View workflow job for this annotation

GitHub Actions / Unit

other declaration of esState) (typecheck)

Check failure on line 64 in ec/ecresource/deploymentresource/elasticsearch/v2/elasticsearch_payload.go

View workflow job for this annotation

GitHub Actions / Unit

other declaration of esState) (typecheck)
if state != nil {
esState, diags = objectToElasticsearch(ctx, *state)
if diags.HasError() {
Expand All @@ -73,6 +73,14 @@
return nil, nil
}

var esState *ElasticsearchTF

Check failure on line 76 in ec/ecresource/deploymentresource/elasticsearch/v2/elasticsearch_payload.go

View workflow job for this annotation

GitHub Actions / Unit

esState redeclared in this block

Check failure on line 76 in ec/ecresource/deploymentresource/elasticsearch/v2/elasticsearch_payload.go

View workflow job for this annotation

GitHub Actions / Unit

esState redeclared in this block

Check failure on line 76 in ec/ecresource/deploymentresource/elasticsearch/v2/elasticsearch_payload.go

View workflow job for this annotation

GitHub Actions / Unit

esState redeclared in this block
if state != nil {
esState, diags = objectToElasticsearch(ctx, *state)
if diags.HasError() {
return nil, diags
}
}

templatePayload := EnrichElasticsearchTemplate(payloadFromUpdate(updateResources), dtID, version, useNodeRoles)

payload, diags := es.payload(ctx, templatePayload, esState)
Expand Down Expand Up @@ -168,11 +176,14 @@
res.Plan.AutoscalingEnabled = ec.Bool(es.Autoscale.ValueBool())
}

res.Settings, ds = elasticsearchTrustAccountPayload(ctx, es.TrustAccount, res.Settings)
diags.Append(ds...)
// Only add trust settings to update payload if trust has changed
if state == nil || !es.TrustAccount.Equal(state.TrustAccount) || !es.TrustExternal.Equal(state.TrustExternal) {
gigerdo marked this conversation as resolved.
Show resolved Hide resolved
res.Settings, ds = elasticsearchTrustAccountPayload(ctx, es.TrustAccount, res.Settings)
diags.Append(ds...)

res.Settings, ds = elasticsearchTrustExternalPayload(ctx, es.TrustExternal, res.Settings)
diags.Append(ds...)
res.Settings, ds = elasticsearchTrustExternalPayload(ctx, es.TrustExternal, res.Settings)
diags.Append(ds...)
}

res.Settings, ds = elasticsearchKeystoreContentsPayload(ctx, es.KeystoreContents, res.Settings, state)
diags.Append(ds...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,127 @@ func Test_writeElasticsearch(t *testing.T) {
},
}),
},
{
name: "don't put trust settings into the payload if they haven't changed",
args: args{
esPlan: Elasticsearch{
RefId: ec.String("main-elasticsearch"),
ResourceId: ec.String(mock.ValidClusterID),
Region: ec.String("some-region"),
TrustAccount: ElasticsearchTrustAccounts{
{
AccountId: ec.String("id1"),
TrustAllowlist: []string{"a", "b"},
},
{
AccountId: ec.String("id2"),
TrustAll: ec.Bool(true),
},
},
TrustExternal: ElasticsearchTrustExternals{
{
RelationshipId: ec.String("id3"),
TrustAll: ec.Bool(true),
},
{
RelationshipId: ec.String("id4"),
TrustAllowlist: []string{"c", "d"},
},
},
Strategy: ec.String("rolling_all"),
HotTier: &ElasticsearchTopology{
id: "hot_content",
Size: ec.String("2g"),
ZoneCount: 1,
},
},
esState: &Elasticsearch{
RefId: ec.String("main-elasticsearch"),
ResourceId: ec.String(mock.ValidClusterID),
Region: ec.String("some-region"),
TrustAccount: ElasticsearchTrustAccounts{
{
AccountId: ec.String("id1"),
TrustAllowlist: []string{"a", "b"},
},
{
AccountId: ec.String("id2"),
TrustAll: ec.Bool(true),
},
},
TrustExternal: ElasticsearchTrustExternals{
{
RelationshipId: ec.String("id3"),
TrustAll: ec.Bool(true),
},
{
RelationshipId: ec.String("id4"),
TrustAllowlist: []string{"c", "d"},
},
},
Strategy: ec.String("rolling_all"),
HotTier: &ElasticsearchTopology{
id: "hot_content",
Size: ec.String("2g"),
ZoneCount: 1,
},
},
updatePayloads: testutil.UpdatePayloadsFromTemplate(t, "../../testdata/template-aws-io-optimized-v2.json"),
templateID: "aws-io-optimized-v2",
version: "7.7.0",
useNodeRoles: false,
},
want: EnrichWithEmptyTopologies(tp770(), &models.ElasticsearchPayload{
Region: ec.String("some-region"),
RefID: ec.String("main-elasticsearch"),
Settings: &models.ElasticsearchClusterSettings{
DedicatedMastersThreshold: 6,
},
Plan: &models.ElasticsearchClusterPlan{
AutoscalingEnabled: ec.Bool(false),
Elasticsearch: &models.ElasticsearchConfiguration{
Version: "7.7.0",
},
DeploymentTemplate: &models.DeploymentTemplateReference{
ID: ec.String("aws-io-optimized-v2"),
},
Transient: &models.TransientElasticsearchPlanConfiguration{
Strategy: &models.PlanStrategy{
Rolling: &models.RollingStrategyConfig{GroupBy: "__all__"},
},
},
ClusterTopology: []*models.ElasticsearchClusterTopologyElement{
{
ID: "hot_content",
ZoneCount: 1,
InstanceConfigurationID: "aws.data.highio.i3",
Size: &models.TopologySize{
Resource: ec.String("memory"),
Value: ec.Int32(2048),
},
NodeType: &models.ElasticsearchNodeType{
Data: ec.Bool(true),
Ingest: ec.Bool(true),
Master: ec.Bool(true),
},
Elasticsearch: &models.ElasticsearchConfiguration{
NodeAttributes: map[string]string{"data": "hot"},
},
TopologyElementControl: &models.TopologyElementControl{
Min: &models.TopologySize{
Resource: ec.String("memory"),
Value: ec.Int32(1024),
},
},
AutoscalingMax: &models.TopologySize{
Value: ec.Int32(118784),
Resource: ec.String("memory"),
},
},
},
},
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading