Skip to content

Bug: SnapshotPolicy deletion schedule incorrectly uses creation schedule #1121

@daimon243

Description

@daimon243

Description

The OpensearchSnapshotPolicy CRD has a bug where the deletion schedule incorrectly uses the creation schedule values instead of the deletion schedule values.

Environment

Steps to Reproduce

  1. Create an OpensearchSnapshotPolicy with different creation and deletion schedules:
apiVersion: opensearch.opster.io/v1
kind: OpensearchSnapshotPolicy
metadata:
  name: test-policy
  namespace: default
spec:
  opensearchCluster:
    name: test-cluster
  policyName: test-policy
  creation:
    schedule:
      cron:
        expression: "0 6 * * *"  # 6:00 AM
        timezone: "UTC"
    timeLimit: "2h"
  deletion:
    schedule:
      cron:
        expression: "0 8 * * *"  # 8:00 AM (different from creation)
        timezone: "UTC"
    timeLimit: "2h"
    deleteCondition:
      maxAge: "180d"
      minCount: 1
  1. Apply the policy and check the actual OpenSearch snapshot policy via Dev Tools:
GET _plugins/_sm/policies/test-policy

Expected Behavior

The deletion schedule should be 0 8 * * * (8:00 AM) as specified in the CRD.

Actual Behavior

The deletion schedule is 0 6 * * * (6:00 AM), which matches the creation schedule.

Root Cause

In opensearch-operator/pkg/reconcilers/snapshotpolicy.go at lines 311-312, the code incorrectly uses:

Expression: r.instance.Spec.Creation.Schedule.Cron.Expression,
Timezone:   r.instance.Spec.Creation.Schedule.Cron.Timezone,

Instead of:

Expression: r.instance.Spec.Deletion.Schedule.Cron.Expression,
Timezone:   r.instance.Spec.Deletion.Schedule.Cron.Timezone,

Impact

  • Snapshot deletion may occur at the wrong time
  • Users cannot properly schedule deletion to occur after creation completion
  • This defeats the purpose of having separate creation and deletion schedules

Proposed Solution

I can provide a PR with:

  1. Correct the deletion schedule to use r.instance.Spec.Deletion.Schedule instead of r.instance.Spec.Creation.Schedule
  2. Add nil check for r.instance.Spec.Deletion.Schedule to prevent panic
  3. Add unit tests to prevent regression

Additional Context

This bug was introduced in PR #1018 which added snapshot policy support. The deletion schedule logic was incorrectly copied from the creation schedule logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions