Skip to content

Commit

Permalink
Fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaGirdhar committed Sep 25, 2023
1 parent 1f2e6b9 commit 0be7ec5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package requests

type Policy struct {
PolicyID string `json:"_id,omitempty"`
PrimaryTerm *int `json:"_primary_term,omitempty"`
SequenceNumber *int `json:"_seq_no,omitempty"`
Policy ISMPolicy `json:"policy"`
Expand Down
11 changes: 6 additions & 5 deletions opensearch-operator/pkg/reconcilers/ismpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ func (r *IsmPolicyReconciler) Reconcile() (retResult ctrl.Result, retErr error)
reason := "error creating opensearch client"
r.recorder.Event(r.instance, "Warning", opensearchError, reason)
}

// If PolicyID not provided explicitly, use metadata.name by default
if r.instance.Spec.PolicyID == "" {
r.instance.Spec.PolicyID = r.instance.Name
}
// Check ism policy state to make sure we don't touch preexisting ism policy
if r.instance.Status.ExistingISMPolicy == nil {
var exists bool
Expand Down Expand Up @@ -178,10 +181,7 @@ func (r *IsmPolicyReconciler) Reconcile() (retResult ctrl.Result, retErr error)
r.recorder.Event(r.instance, "Warning", opensearchAPIError, reason)
return
}
// If PolicyID not provided explicitly, use metadata.name by default
if r.instance.Spec.PolicyID == "" {
r.instance.Spec.PolicyID = r.instance.Metadata.name
}

ismResponse, retErr := services.GetPolicy(r.ctx, r.osClient, r.instance.Spec.PolicyID)
if retErr != nil && retErr != services.ErrNotFound {
reason = "failed to get policy from Opensearch API"
Expand Down Expand Up @@ -224,6 +224,7 @@ func (r *IsmPolicyReconciler) Reconcile() (retResult ctrl.Result, retErr error)

if r.instance.Spec.PolicyID != ismResponse.PolicyID {
reason = "can't change PolicyID"
r.recorder.Event(r.instance, "Warning", opensearchError, reason)
return
}
retErr = services.UpdateISMPolicy(r.ctx, r.osClient, *ismpolicy, seqno, priterm, r.instance.Spec.PolicyID)
Expand Down

0 comments on commit 0be7ec5

Please sign in to comment.