opensearch-project / opensearch-k8s-operator

OpenSearch Kubernetes Operator
Apache License 2.0
387 stars 202 forks source link

OpenSearchISMPolicy - shrink action has a maxShardSize required property which is invalid #750

Closed cthtrifork closed 6 months ago

cthtrifork commented 7 months ago

I have the following OpenSearchISMPolicy

apiVersion: opensearch.opster.io/v1
kind: OpenSearchISMPolicy
metadata:
  name: platypus-otto-shared
spec:
  opensearchCluster:
    name: opensearch
  _meta:
    description: platypus-otto-shared
  policyId: platypus-otto-shared
  description: A sample description of the policy
  states:
    - name: hot
      actions:
        - indexPriority:
            priority: 100
      transitions:
        - conditions:
            minIndexAge: 400d
          stateName: warm
    - name: warm
      actions:
        - shrink:
            numNewShards: 1
          forceMerge:
            maxNumSegments: 1
      transitions:
        - conditions:
            minIndexAge: 800d
          stateName: cold
    - name: cold
      actions:
        - readOnly: {}
      transitions:
        - conditions:
            minIndexAge: 3650d
          stateName: delete
    - name: delete
      actions:
        - delete: {}
      transitions: []
  defaultState: hot
  ismTemplate:
    priority: 1
    indexPatterns:
      - otto-reading_*

And I am receving the following error when validating the schema:

stdin - OpenSearchISMPolicy platypus-otto-shared is invalid: problem validating schema. Check JSON formatting: jsonschema: '/spec/states/1/actions/0/shrink' does not validate with file:///.../v1.26.5-standalone-strict/opensearchismpolicy-opensearch-v1.json#/properties/spec/properties/states/items/properties/actions/items/properties/shrink/required: missing properties: 'maxShardSize'

The error is saying that the maxShardSize property is required, but the maxShardSize property is not required in the shrink action for all permutations of how it can be used. See the official documentation:

https://opensearch.org/docs/latest/im-plugin/ism/policies/#shrink image

You are already handling the properties here: opensearch-operator/pkg/reconcilers/ismpolicy.go

But we need to update the schema.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check here.

prudhvigodithi commented 6 months ago

Thanks @cthtrifork LGTM. Adding @bbarani @salyh @jochenkressin @pchmielnik @bbarani