From 19b816c1e17a543482114e9b637c316e0fba3f40 Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Fri, 30 Aug 2024 16:26:54 +0200 Subject: [PATCH 1/2] plugins/ism: add omitempty to Conditions fiels in Trasistion struct Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + plugins/ism/api_policies.go | 2 +- plugins/ism/api_policies_test.go | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index feffc1ba4..3369a502c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Removed ### Fixed +- Fix ISM Transition to omitempty Conditions field ([#609](https://github.com/opensearch-project/opensearch-go/pull/609)) ### Security diff --git a/plugins/ism/api_policies.go b/plugins/ism/api_policies.go index 523cc1e6b..4a6af0cc3 100644 --- a/plugins/ism/api_policies.go +++ b/plugins/ism/api_policies.go @@ -264,5 +264,5 @@ type PolicyStateTransitionConditionCron struct { // PolicyStateTransition is a sub type of PolicyState containing information about transition to other states type PolicyStateTransition struct { StateName string `json:"state_name"` - Conditions *PolicyStateTransitionCondition `json:"conditions"` + Conditions *PolicyStateTransitionCondition `json:"conditions,omitempty"` } diff --git a/plugins/ism/api_policies_test.go b/plugins/ism/api_policies_test.go index a315f7717..819f67267 100644 --- a/plugins/ism/api_policies_test.go +++ b/plugins/ism/api_policies_test.go @@ -69,16 +69,29 @@ func TestPoliciesClient(t *testing.T) { Source: "The index {{ctx.index}} failed during policy execution.", }, }, - DefaultState: "test", + DefaultState: "transition", States: []ism.PolicyState{ ism.PolicyState{ - Name: "test", + Name: "delete", Actions: []ism.PolicyStateAction{ ism.PolicyStateAction{ Delete: &ism.PolicyStateDelete{}, }, }, }, + ism.PolicyState{ + Name: "transition", + Actions: []ism.PolicyStateAction{ + ism.PolicyStateAction{ + Close: &ism.PolicyStateClose{}, + }, + }, + Transitions: &[]ism.PolicyStateTransition{ + ism.PolicyStateTransition{ + StateName: "delete", + }, + }, + }, }, Template: []ism.Template{ ism.Template{ From b2562295ca7dff9bf888c4c8d7956366d0fd598f Mon Sep 17 00:00:00 2001 From: Jakob Hahn Date: Fri, 30 Aug 2024 16:56:28 +0200 Subject: [PATCH 2/2] plugins/ism: fix allocaation field types Signed-off-by: Jakob Hahn --- CHANGELOG.md | 1 + plugins/ism/api_policies.go | 8 ++++---- plugins/ism/api_policies_test.go | 22 ++++++++++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3369a502c..2e4b67e6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fix ISM Transition to omitempty Conditions field ([#609](https://github.com/opensearch-project/opensearch-go/pull/609)) +- Fix ISM Allocation field types ([#609](https://github.com/opensearch-project/opensearch-go/pull/609)) ### Security diff --git a/plugins/ism/api_policies.go b/plugins/ism/api_policies.go index 4a6af0cc3..0b7787ddd 100644 --- a/plugins/ism/api_policies.go +++ b/plugins/ism/api_policies.go @@ -226,10 +226,10 @@ type PolicyStateIndexPriority struct { // PolicyStateAllocation represents the allocation action type PolicyStateAllocation struct { - Require string `json:"require,omitempty"` - Include string `json:"include,omitempty"` - Exclude string `json:"exclude,omitempty"` - WaitFor string `json:"wait_for,omitempty"` + Require map[string]string `json:"require,omitempty"` + Include map[string]string `json:"include,omitempty"` + Exclude map[string]string `json:"exclude,omitempty"` + WaitFor *bool `json:"wait_for,omitempty"` } // PolicyStateRollup represents the rollup action diff --git a/plugins/ism/api_policies_test.go b/plugins/ism/api_policies_test.go index 819f67267..2de7ffb20 100644 --- a/plugins/ism/api_policies_test.go +++ b/plugins/ism/api_policies_test.go @@ -72,10 +72,20 @@ func TestPoliciesClient(t *testing.T) { DefaultState: "transition", States: []ism.PolicyState{ ism.PolicyState{ - Name: "delete", + Name: "allocation", Actions: []ism.PolicyStateAction{ ism.PolicyStateAction{ - Delete: &ism.PolicyStateDelete{}, + Allocation: &ism.PolicyStateAllocation{ + Require: map[string]string{"temp": "warm"}, + Include: map[string]string{"test": "warm"}, + Exclude: map[string]string{"test2": "warm"}, + WaitFor: opensearch.ToPointer(true), + }, + }, + }, + Transitions: &[]ism.PolicyStateTransition{ + ism.PolicyStateTransition{ + StateName: "transition", }, }, }, @@ -92,6 +102,14 @@ func TestPoliciesClient(t *testing.T) { }, }, }, + ism.PolicyState{ + Name: "delete", + Actions: []ism.PolicyStateAction{ + ism.PolicyStateAction{ + Delete: &ism.PolicyStateDelete{}, + }, + }, + }, }, Template: []ism.Template{ ism.Template{