Skip to content

Commit

Permalink
Invalid CRD types for ISM actions and a nil pointer fix (#788)
Browse files Browse the repository at this point in the history
### Description

This fixes a few bugs found while testing the ISMPolicy custom
resources.

### Issues Resolved
_List any issues this PR will resolve, e.g. Closes [...]._ 

### Check List
- [x] Commits are signed per the DCO using --signoff 
- [x] Unittest added for the new/changed functionality and all unit
tests are successful
- [x] Customer-visible features documented
- [x] No linter warnings (`make lint`)

If CRDs are changed:
- [x] CRD YAMLs updated (`make manifests`) and also copied into the helm
chart
- [x] Changes to CRDs documented

Please refer to the [PR
guidelines](https://github.com/opensearch-project/opensearch-k8s-operator/blob/main/docs/developing.md#submitting-a-pr)
before submitting this pull request.

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](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin).

FYI @IshaGirdhar

---------

Signed-off-by: Casper Thygesen <cth@trifork.com>
  • Loading branch information
cthtrifork committed Apr 26, 2024
1 parent 3ebcf30 commit 5fa7f0c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ spec:
type: object
readOnly:
description: Sets a managed index to be read only.
type: string
type: object
readWrite:
description: Sets a managed index to be writeable.
type: string
type: object
replicaCount:
description: Sets the number of replicas to assign to
an index.
Expand Down Expand Up @@ -349,7 +349,8 @@ spec:
- snapshot
type: object
timeout:
description: The timeout period for the action.
description: The timeout period for the action. Accepts
time units for minutes, hours, and days.
type: string
type: object
type: array
Expand Down
10 changes: 7 additions & 3 deletions opensearch-operator/api/v1/opensearchism_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ type Action struct {
// Opens a managed index.
Open *Open `json:"open,omitempty"`
// Sets a managed index to be read only.
ReadOnly *string `json:"readOnly,omitempty"`
ReadOnly *ReadOnly `json:"readOnly,omitempty"`
// Sets a managed index to be writeable.
ReadWrite *string `json:"readWrite,omitempty"`
ReadWrite *ReadWrite `json:"readWrite,omitempty"`
// Sets the number of replicas to assign to an index.
ReplicaCount *ReplicaCount `json:"replicaCount,omitempty"`
// The retry configuration for the action.
Expand All @@ -124,7 +124,7 @@ type Action struct {
Shrink *Shrink `json:"shrink,omitempty"`
// Back up your cluster’s indexes and state
Snapshot *Snapshot `json:"snapshot,omitempty"`
// The timeout period for the action.
// The timeout period for the action. Accepts time units for minutes, hours, and days.
Timeout *string `json:"timeout,omitempty"`
}

Expand Down Expand Up @@ -161,6 +161,10 @@ type Allocation struct {

type Close struct{}

type ReadOnly struct{}

type ReadWrite struct{}

type Delete struct{}

type ForceMerge struct {
Expand Down
34 changes: 32 additions & 2 deletions opensearch-operator/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ spec:
type: object
readOnly:
description: Sets a managed index to be read only.
type: string
type: object
readWrite:
description: Sets a managed index to be writeable.
type: string
type: object
replicaCount:
description: Sets the number of replicas to assign to
an index.
Expand Down Expand Up @@ -349,7 +349,8 @@ spec:
- snapshot
type: object
timeout:
description: The timeout period for the action.
description: The timeout period for the action. Accepts
time units for minutes, hours, and days.
type: string
type: object
type: array
Expand Down
8 changes: 6 additions & 2 deletions opensearch-operator/opensearch-gateway/requests/IsmPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ type Action struct {
// Opens a managed index.
Open *Open `json:"open,omitempty"`
// Sets a managed index to be read only.
ReadOnly *string `json:"read_only,omitempty"`
ReadOnly *ReadOnly `json:"read_only,omitempty"`
// Sets a managed index to be writeable.
ReadWrite *string `json:"read_write,omitempty"`
ReadWrite *ReadWrite `json:"read_write,omitempty"`
// Sets the number of replicas to assign to an index.
ReplicaCount *ReplicaCount `json:"replica_count,omitempty"`
// The retry configuration for the action.
Expand Down Expand Up @@ -130,6 +130,10 @@ type Allocation struct {

type Close struct{}

type ReadOnly struct{}

type ReadWrite struct{}

type Delete struct{}

type ForceMerge struct {
Expand Down
12 changes: 7 additions & 5 deletions opensearch-operator/pkg/reconcilers/ismpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ func (r *IsmPolicyReconciler) CreateISMPolicyRequest() (*requests.Policy, error)
}
var indexPri *requests.IndexPriority
if action.IndexPriority != nil {
indexPri.Priority = action.IndexPriority.Priority
indexPri = &requests.IndexPriority{
Priority: action.IndexPriority.Priority,
}
}
var snapshot *requests.Snapshot
if action.Snapshot != nil {
Expand Down Expand Up @@ -455,13 +457,13 @@ func (r *IsmPolicyReconciler) CreateISMPolicyRequest() (*requests.Policy, error)
if action.Timeout != nil {
timeOut = action.Timeout
}
var readWrite *string
var readWrite *requests.ReadWrite
if action.ReadWrite != nil {
readWrite = action.ReadWrite
readWrite = &requests.ReadWrite{}
}
var readOnly *string
var readOnly *requests.ReadOnly
if action.ReadOnly != nil {
readOnly = action.ReadOnly
readOnly = &requests.ReadOnly{}
}
actions = append(actions, requests.Action{
ReplicaCount: replicaCount,
Expand Down

0 comments on commit 5fa7f0c

Please sign in to comment.