Skip to content

[BUG] SnapshotPolicy CRD - Cannot set optional snapshotConfig fields explicitly to false #1172

@FaustoLavezzari

Description

@FaustoLavezzari

What is the bug?

The SnapshotConfig struct defines three boolean fields (IgnoreUnavailable, IncludeGlobalState, Partial) as non-pointer bool types with the omitempty JSON tag. This causes explicitly set false values to be omitted during JSON serialization.

While this is not critical for OpenSearch functionality itself (since most defaults are already false or can be overridden during restore), it causes synchronization issues with GitOps tools like ArgoCD. When a user explicitly sets these fields to false in their manifest, ArgoCD expects them to exist in the cluster resource, but they got ommited due to the omitempty tag. This leaves the application in a perpetual "OutOfSync" status, requiring manual intervention or sync policies to ignore these fields.

How can one reproduce the bug?

  1. Create an OpensearchSnapshotPolicy resource with explicit false values:
  apiVersion: opensearch.opster.io/v1
  kind: OpensearchSnapshotPolicy
  metadata:
    name: test-snapshot-policy
  spec:
    opensearchCluster:
      name: my-cluster
    policyName: test-policy
    snapshotConfig:
      repository: my-repo
      ignoreUnavailable: false       # Explicitly set to false
      includeGlobalState: false      # Explicitly set to false
      partial: false                            # Explicitly set to false
    creation:
      schedule:
        cron:
          expression: "0 0 * * *"
          timezone: "UTC"
  1. Apply the resource and check the actual snapshot policy created in OpenSearch
  2. Observe that the three boolean fields are not present in the resource created on the cluster

What is the expected behavior?

Resource should show the fields with a false value even if false is the default for the API

What is your host/environment?

operator version 2.8.0
k8s version v1.28.11
opensearch version 2.19.3

Do you have any additional context?

file with issue

IgnoreUnavailable bool `json:"ignoreUnavailable,omitempty"`

This docs mentions that optional booleans should always use pointers https://github.com/kubernetes/community/blob/a26e098b39b6ec14ae4aa97ebc0eb8c7e2e39f0c/contributors/devel/sig-architecture/api-conventions.md?plain=1#L895

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions