From 4501ff20967f206691e64aa031fa360284f533e8 Mon Sep 17 00:00:00 2001 From: rkthtrifork Date: Fri, 7 Jun 2024 11:02:25 +0200 Subject: [PATCH] Rewrote ISM Policy reconciler --- .github/workflows/cheetah-release.yaml | 21 ++ .github/workflows/docker-create-snapshot.yaml | 55 +++++ .../opensearch-gateway/requests/IsmPolicy.go | 9 +- .../responses/ISMPolicyResponse.go | 5 - .../opensearch-gateway/responses/IsmPolicy.go | 10 + .../services/os_ism_service.go | 33 +-- .../pkg/reconcilers/indextemplate.go | 7 +- .../pkg/reconcilers/ismpolicy.go | 196 ++++++++---------- .../pkg/reconcilers/ismpolicy_test.go | 16 +- 9 files changed, 199 insertions(+), 153 deletions(-) create mode 100644 .github/workflows/cheetah-release.yaml create mode 100644 .github/workflows/docker-create-snapshot.yaml delete mode 100644 opensearch-operator/opensearch-gateway/responses/ISMPolicyResponse.go create mode 100644 opensearch-operator/opensearch-gateway/responses/IsmPolicy.go diff --git a/.github/workflows/cheetah-release.yaml b/.github/workflows/cheetah-release.yaml new file mode 100644 index 00000000..07ed3b0a --- /dev/null +++ b/.github/workflows/cheetah-release.yaml @@ -0,0 +1,21 @@ +name: Cheetah Release +on: + workflow_dispatch: + push: + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +permissions: + contents: read + packages: write + +jobs: + create-snapshot: + uses: ./.github/workflows/docker-create-snapshot.yaml + with: + context: opensearch-operator + image-name: opensearch-k8s-operator + secrets: + TRIFORK_GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/docker-create-snapshot.yaml b/.github/workflows/docker-create-snapshot.yaml new file mode 100644 index 00000000..3bc0191c --- /dev/null +++ b/.github/workflows/docker-create-snapshot.yaml @@ -0,0 +1,55 @@ +name: Docker Create Snapshot + +on: + workflow_call: + inputs: + image-name: + description: The name of the image to create a snapshot for + required: true + type: string + context: + description: The directory to run the workflow inside + required: false + type: string + default: . + dockerfile-path: + description: The path to the Dockerfile. Defaults to {context}/Dockerfile + required: false + type: string + secrets: + TRIFORK_GITHUB_PAT: + description: A personal access token with permission to publish a package to the Trifork GitHub container registry + required: true + +jobs: + create-snapshot: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Log in to the container registry + uses: docker/login-action@1220aa36aaf257e736f1d64e3b87c4878665836f + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.TRIFORK_GITHUB_PAT }} + + - name: Get package suffix + id: get-package-suffix + run: echo "branch-name=$(echo '${{ github.ref_name }}' | sed 's/[^a-zA-Z0-9]/-/g')" >> $GITHUB_OUTPUT + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3 + + - name: Build and push Docker image + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5 + with: + context: ${{ inputs.context }} + file: ${{ inputs.dockerfile-path }} + platforms: linux/amd64 + tags: ghcr.io/trifork/${{ inputs.image-name }}:2.6.0-${{ steps.get-package-suffix.outputs.branch-name }}-SNAPSHOT-${{ github.run_number }} + push: true + secrets: | + GITHUB_ACTOR=${{ github.actor }} + GITHUB_TOKEN=${{ secrets.TRIFORK_GITHUB_PAT }} \ No newline at end of file diff --git a/opensearch-operator/opensearch-gateway/requests/IsmPolicy.go b/opensearch-operator/opensearch-gateway/requests/IsmPolicy.go index 2f820a0a..023fc79e 100644 --- a/opensearch-operator/opensearch-gateway/requests/IsmPolicy.go +++ b/opensearch-operator/opensearch-gateway/requests/IsmPolicy.go @@ -1,14 +1,11 @@ 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"` +type ISMPolicy struct { + Policy ISMPolicySpec `json:"policy"` } // ISMPolicySpec is the specification for the ISM policy for OS. -type ISMPolicy struct { +type ISMPolicySpec struct { // The default starting state for each index that uses this policy. DefaultState string `json:"default_state"` // A human-readable description of the policy. diff --git a/opensearch-operator/opensearch-gateway/responses/ISMPolicyResponse.go b/opensearch-operator/opensearch-gateway/responses/ISMPolicyResponse.go deleted file mode 100644 index 753314cc..00000000 --- a/opensearch-operator/opensearch-gateway/responses/ISMPolicyResponse.go +++ /dev/null @@ -1,5 +0,0 @@ -package responses - -import "github.com/Opster/opensearch-k8s-operator/opensearch-operator/opensearch-gateway/requests" - -type GetISMPoliciesResponse requests.Policy diff --git a/opensearch-operator/opensearch-gateway/responses/IsmPolicy.go b/opensearch-operator/opensearch-gateway/responses/IsmPolicy.go new file mode 100644 index 00000000..29174466 --- /dev/null +++ b/opensearch-operator/opensearch-gateway/responses/IsmPolicy.go @@ -0,0 +1,10 @@ +package responses + +import "github.com/Opster/opensearch-k8s-operator/opensearch-operator/opensearch-gateway/requests" + +type GetISMPolicyResponse struct { + PolicyID string `json:"_id"` + PrimaryTerm int `json:"_primary_term"` + SequenceNumber int `json:"_seq_no"` + Policy requests.ISMPolicySpec +} diff --git a/opensearch-operator/opensearch-gateway/services/os_ism_service.go b/opensearch-operator/opensearch-gateway/services/os_ism_service.go index d82c0e90..040e2e26 100644 --- a/opensearch-operator/opensearch-gateway/services/os_ism_service.go +++ b/opensearch-operator/opensearch-gateway/services/os_ism_service.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/Opster/opensearch-k8s-operator/opensearch-operator/opensearch-gateway/requests" + "github.com/Opster/opensearch-k8s-operator/opensearch-operator/opensearch-gateway/responses" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/opensearch-project/opensearch-go/opensearchutil" @@ -16,7 +17,7 @@ import ( var ErrNotFound = errors.New("policy not found") // ShouldUpdateISMPolicy checks if the passed policy is same as existing or needs update -func ShouldUpdateISMPolicy(ctx context.Context, newPolicy, existingPolicy requests.Policy) (bool, error) { +func ShouldUpdateISMPolicy(ctx context.Context, newPolicy, existingPolicy requests.ISMPolicy) (bool, error) { if cmp.Equal(newPolicy, existingPolicy, cmpopts.EquateEmpty()) { return false, nil } @@ -27,23 +28,8 @@ func ShouldUpdateISMPolicy(ctx context.Context, newPolicy, existingPolicy reques return true, nil } -// PolicyExists checks if the passed policy already exists or not -func PolicyExists(ctx context.Context, service *OsClusterClient, policyName string) (bool, error) { - resp, err := service.GetISMConfig(ctx, policyName) - if err != nil { - return false, err - } - defer resp.Body.Close() - if resp.StatusCode == 404 { - return false, nil - } else if resp.IsError() { - return false, fmt.Errorf("response from API is %s", resp.Status()) - } - return true, nil -} - // GetPolicy fetches the passed policy -func GetPolicy(ctx context.Context, service *OsClusterClient, policyName string) (*requests.Policy, error) { +func GetPolicy(ctx context.Context, service *OsClusterClient, policyName string) (*responses.GetISMPolicyResponse, error) { resp, err := service.GetISMConfig(ctx, policyName) if err != nil { return nil, err @@ -51,10 +37,11 @@ func GetPolicy(ctx context.Context, service *OsClusterClient, policyName string) defer resp.Body.Close() if resp.StatusCode == 404 { return nil, ErrNotFound - } else if resp.IsError() { + } + if resp.IsError() { return nil, fmt.Errorf("response from API is %s", resp.Status()) } - ismResponse := requests.Policy{} + ismResponse := responses.GetISMPolicyResponse{} if resp != nil && resp.Body != nil { err := json.NewDecoder(resp.Body).Decode(&ismResponse) if err != nil { @@ -66,7 +53,7 @@ func GetPolicy(ctx context.Context, service *OsClusterClient, policyName string) } // CreateISMPolicy creates the passed policy -func CreateISMPolicy(ctx context.Context, service *OsClusterClient, ismpolicy requests.Policy, policyId string) error { +func CreateISMPolicy(ctx context.Context, service *OsClusterClient, ismpolicy requests.ISMPolicy, policyId string) error { spec := opensearchutil.NewJSONReader(ismpolicy) resp, err := service.PutISMConfig(ctx, policyId, spec) if err != nil { @@ -80,15 +67,15 @@ func CreateISMPolicy(ctx context.Context, service *OsClusterClient, ismpolicy re } // UpdateISMPolicy updates the given policy -func UpdateISMPolicy(ctx context.Context, service *OsClusterClient, ismpolicy requests.Policy, seqno, primterm *int, policyName string) error { +func UpdateISMPolicy(ctx context.Context, service *OsClusterClient, ismpolicy requests.ISMPolicy, seqno, primterm *int, policyId string) error { spec := opensearchutil.NewJSONReader(ismpolicy) - resp, err := service.UpdateISMConfig(ctx, policyName, *seqno, *primterm, spec) + resp, err := service.UpdateISMConfig(ctx, policyId, *seqno, *primterm, spec) if err != nil { return err } defer resp.Body.Close() if resp.IsError() { - return fmt.Errorf("failed to create ism policy: %s", resp.String()) + return fmt.Errorf("failed to update ism policy: %s", resp.String()) } return nil } diff --git a/opensearch-operator/pkg/reconcilers/indextemplate.go b/opensearch-operator/pkg/reconcilers/indextemplate.go index 1ae6f62a..819c674d 100644 --- a/opensearch-operator/pkg/reconcilers/indextemplate.go +++ b/opensearch-operator/pkg/reconcilers/indextemplate.go @@ -151,9 +151,9 @@ func (r *IndexTemplateReconciler) Reconcile() (result ctrl.Result, err error) { return } - templateName = r.instance.Name - if r.instance.Spec.Name != "" { - templateName = r.instance.Spec.Name + templateName = r.instance.Spec.Name + if templateName != "" { + templateName = r.instance.Name } // Check index template state to make sure we don't touch preexisting index templates @@ -173,6 +173,7 @@ func (r *IndexTemplateReconciler) Reconcile() (result ctrl.Result, err error) { }) if err != nil { reason = fmt.Sprintf("failed to update status: %s", err) + // r.logger.Error(retErr, reason) should this be added? r.recorder.Event(r.instance, "Warning", statusError, reason) return } diff --git a/opensearch-operator/pkg/reconcilers/ismpolicy.go b/opensearch-operator/pkg/reconcilers/ismpolicy.go index f2954d45..269d9202 100644 --- a/opensearch-operator/pkg/reconcilers/ismpolicy.go +++ b/opensearch-operator/pkg/reconcilers/ismpolicy.go @@ -13,6 +13,8 @@ import ( "github.com/Opster/opensearch-k8s-operator/opensearch-operator/pkg/reconcilers/util" "github.com/cisco-open/operator-tools/pkg/reconciler" "github.com/go-logr/logr" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "k8s.io/utils/pointer" @@ -22,7 +24,8 @@ import ( ) const ( - ismPolicyExists = "ism policy already exists in Opensearch" + opensearchIsmPolicyExists = "ism policy already exists in Opensearch" + opensearchIsmPolicyNameMismatch = "OpensearchISMPolicyNameMismatch" ) type IsmPolicyReconciler struct { @@ -58,6 +61,7 @@ func NewIsmReconciler( func (r *IsmPolicyReconciler) Reconcile() (retResult ctrl.Result, retErr error) { var reason string var policyId string + defer func() { if !pointer.BoolDeref(r.updateStatus, true) { return @@ -79,16 +83,16 @@ func (r *IsmPolicyReconciler) Reconcile() (retResult ctrl.Result, retErr error) instance.Status.State = opsterv1.OpensearchISMPolicyCreated instance.Status.PolicyId = policyId } - if reason == ismPolicyExists { + if reason == opensearchIsmPolicyExists { instance.Status.State = opsterv1.OpensearchISMPolicyIgnored } }) + if err != nil { r.logger.Error(err, "failed to update status") } }() - var err error r.cluster, retErr = util.FetchOpensearchCluster(r.client, r.ctx, types.NamespacedName{ Name: r.instance.Spec.OpensearchRef.Name, Namespace: r.instance.Namespace, @@ -109,27 +113,26 @@ func (r *IsmPolicyReconciler) Reconcile() (retResult ctrl.Result, retErr error) } return } + // Check cluster ref has not changed - if r.instance.Status.ManagedCluster != nil { - if *r.instance.Status.ManagedCluster != r.cluster.UID { - reason = "cannot change the cluster a role refers to" - retErr = fmt.Errorf("%s", reason) - r.recorder.Event(r.instance, "Warning", opensearchRefMismatch, reason) + managedCluster := r.instance.Status.ManagedCluster + if managedCluster != nil && *managedCluster != r.cluster.UID { + reason = "cannot change the cluster a role refers to" + retErr = fmt.Errorf("%s", reason) + r.recorder.Event(r.instance, "Warning", opensearchRefMismatch, reason) + return + } + if pointer.BoolDeref(r.updateStatus, true) { + retErr = r.client.UdateObjectStatus(r.instance, func(object client.Object) { + object.(*opsterv1.OpenSearchISMPolicy).Status.ManagedCluster = &r.cluster.UID + }) + if retErr != nil { + reason = fmt.Sprintf("failed to update status: %s", retErr) + r.recorder.Event(r.instance, "Warning", statusError, reason) return } - } else { - if pointer.BoolDeref(r.updateStatus, true) { - retErr = r.client.UdateObjectStatus(r.instance, func(object client.Object) { - instance := object.(*opsterv1.OpenSearchISMPolicy) - instance.Status.ManagedCluster = &r.cluster.UID - }) - if retErr != nil { - reason = fmt.Sprintf("failed to update status: %s", retErr) - r.recorder.Event(r.instance, "Warning", statusError, reason) - return - } - } } + // Check cluster is ready if r.cluster.Status.Phase != opsterv1.PhaseRunning { r.logger.Info("opensearch cluster is not running, requeueing") @@ -142,122 +145,100 @@ func (r *IsmPolicyReconciler) Reconcile() (retResult ctrl.Result, retErr error) return } - r.osClient, err = util.CreateClientForCluster(r.client, r.ctx, r.cluster, r.osClientTransport) - if err != nil { - reason := "error creating opensearch client" + r.osClient, retErr = util.CreateClientForCluster(r.client, r.ctx, r.cluster, r.osClientTransport) + if retErr != nil { + reason = "error creating opensearch client" r.recorder.Event(r.instance, "Warning", opensearchError, reason) - retResult = ctrl.Result{ - Requeue: true, - RequeueAfter: 30 * time.Second, - } - retErr = err return } - // If PolicyID not provided explicitly, use metadata.name by default + // If PolicyID is not provided explicitly, use metadata.name by default policyId = r.instance.Spec.PolicyID - if r.instance.Spec.PolicyID == "" { + if policyId == "" { 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 - exists, retErr = services.PolicyExists(r.ctx, r.osClient, policyId) - if retErr != nil { - reason = "failed to get policy status from Opensearch API" - r.logger.Error(retErr, reason) - r.recorder.Event(r.instance, "Warning", opensearchAPIError, reason) - return - } - if pointer.BoolDeref(r.updateStatus, true) { - retErr = r.client.UdateObjectStatus(r.instance, func(object client.Object) { - instance := object.(*opsterv1.OpenSearchISMPolicy) - instance.Status.ExistingISMPolicy = &exists - }) - if retErr != nil { - reason = fmt.Sprintf("failed to update status: %s", retErr) - r.recorder.Event(r.instance, "Warning", statusError, reason) - return - } - } else { - // Emit an event for unit testing assertion - r.recorder.Event(r.instance, "Normal", "UnitTest", fmt.Sprintf("exists is %t", exists)) - return - } - } - // If ism policy is existing do nothing - if *r.instance.Status.ExistingISMPolicy { - reason = ismPolicyExists - return - } - - ismpolicy, retErr := r.CreateISMPolicyRequest() - if retErr != nil { + newPolicy, err := r.CreateISMPolicy() + if err != nil { reason = "failed to get create the ism policy request" - r.logger.Error(retErr, reason) + r.logger.Error(err, reason) r.recorder.Event(r.instance, "Warning", opensearchAPIError, reason) return } - existingPolicy, retErr := services.GetPolicy(r.ctx, r.osClient, policyId) - if retErr != nil && retErr != services.ErrNotFound { - reason = "failed to get policy from Opensearch API" - r.logger.Error(retErr, reason) - r.recorder.Event(r.instance, "Warning", opensearchAPIError, reason) - return - } - if errors.Is(retErr, services.ErrNotFound) { - r.logger.V(1).Info(fmt.Sprintf("policy %s not found, creating.", r.instance.Spec.PolicyID)) - retErr = services.CreateISMPolicy(r.ctx, r.osClient, *ismpolicy, policyId) + existingPolicy, err := services.GetPolicy(r.ctx, r.osClient, policyId) + // If not exists, create + if errors.Is(err, services.ErrNotFound) { + request := requests.ISMPolicy{ + Policy: *newPolicy, + } + retErr = services.CreateISMPolicy(r.ctx, r.osClient, request, policyId) if retErr != nil { reason = "failed to create ism policy" - r.logger.Error(retErr, reason) + r.logger.Error(err, reason) r.recorder.Event(r.instance, "Warning", opensearchAPIError, reason) return } - r.recorder.Event(r.instance, "Normal", opensearchAPIUpdated, "policy created in opensearch") - return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, retErr + // Mark the ISM Policy as not pre-existing (created by the operator) + r.client.UdateObjectStatus(r.instance, func(object client.Object) { + object.(*opsterv1.OpenSearchISMPolicy).Status.ExistingISMPolicy = pointer.Bool(false) + }) + return ctrl.Result{ + Requeue: true, + RequeueAfter: 30 * time.Second, + }, nil } - priterm := existingPolicy.PrimaryTerm - seqno := existingPolicy.SequenceNumber - // Reset - existingPolicy.PrimaryTerm = nil - existingPolicy.SequenceNumber = nil - shouldUpdate, retErr := services.ShouldUpdateISMPolicy(r.ctx, *ismpolicy, *existingPolicy) - if retErr != nil { - reason = "failed to compare the policies" - r.logger.Error(retErr, reason) + // If other error, report + if err != nil { + reason = "failed to get create the ism policy request" + r.logger.Error(err, reason) r.recorder.Event(r.instance, "Warning", opensearchAPIError, reason) return } - if !shouldUpdate { - r.logger.V(1).Info(fmt.Sprintf("policy %s is in sync", r.instance.Spec.PolicyID)) - return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, retErr + // If the ISM policy exists in OpenSearch cluster and it is marked as pre-existing + if r.instance.Status.ExistingISMPolicy == nil || *r.instance.Status.ExistingISMPolicy { + r.client.UdateObjectStatus(r.instance, func(object client.Object) { + object.(*opsterv1.OpenSearchISMPolicy).Status.ExistingISMPolicy = pointer.Bool(true) + }) + reason = opensearchIsmPolicyExists + r.logger.Error(errors.New("ISM Policy already exists in Opensearch"), reason) + return ctrl.Result{ + Requeue: true, + RequeueAfter: 30 * time.Second, + }, nil } - // the policyId is immutable, so check the old name (r.instance.Status.PolicyId) against the new - if r.instance.Status.PolicyId != "" && policyId != r.instance.Status.PolicyId { - reason = "can't change PolicyID" - r.recorder.Event(r.instance, "Warning", opensearchError, reason) - return + // Return if there are no changes + if r.instance.Spec.PolicyID == existingPolicy.PolicyID && cmp.Equal(*newPolicy, existingPolicy.Policy, cmpopts.EquateEmpty()) { + r.logger.V(1).Info(fmt.Sprintf("user %s is in sync", r.instance.Name)) + return ctrl.Result{ + Requeue: true, + RequeueAfter: 30 * time.Second, + }, nil + } + request := requests.ISMPolicy{ + Policy: *newPolicy, } - retErr = services.UpdateISMPolicy(r.ctx, r.osClient, *ismpolicy, seqno, priterm, policyId) - if retErr != nil { + err = services.UpdateISMPolicy(r.ctx, r.osClient, request, &existingPolicy.SequenceNumber, &existingPolicy.PrimaryTerm, existingPolicy.PolicyID) + if err != nil { reason = "failed to update ism policy with Opensearch API" - r.logger.Error(retErr, reason) + r.logger.Error(err, reason) r.recorder.Event(r.instance, "Warning", opensearchAPIError, reason) + return } r.recorder.Event(r.instance, "Normal", opensearchAPIUpdated, "policy updated in opensearch") - return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, retErr + return ctrl.Result{ + Requeue: true, + RequeueAfter: 30 * time.Second, + }, nil } -func (r *IsmPolicyReconciler) CreateISMPolicyRequest() (*requests.Policy, error) { - policy := requests.ISMPolicy{ +func (r *IsmPolicyReconciler) CreateISMPolicy() (*requests.ISMPolicySpec, error) { + policy := requests.ISMPolicySpec{ DefaultState: r.instance.Spec.DefaultState, Description: r.instance.Spec.Description, } @@ -515,10 +496,8 @@ func (r *IsmPolicyReconciler) CreateISMPolicyRequest() (*requests.Policy, error) policy.States = append(policy.States, requests.State{Actions: actions, Name: state.Name, Transitions: transitions}) } } - ismPolicy := requests.Policy{ - Policy: policy, - } - return &ismPolicy, nil + + return &policy, nil } // Delete ISM policy from the OS cluster @@ -527,10 +506,12 @@ func (r *IsmPolicyReconciler) Delete() error { if r.instance.Status.ExistingISMPolicy == nil { return nil } + if *r.instance.Status.ExistingISMPolicy { r.logger.Info("policy was pre-existing; not deleting") return nil } + var err error r.cluster, err = util.FetchOpensearchCluster(r.client, r.ctx, types.NamespacedName{ Name: r.instance.Spec.OpensearchRef.Name, @@ -544,15 +525,18 @@ func (r *IsmPolicyReconciler) Delete() error { // If the opensearch cluster doesn't exist, we don't need to delete anything return nil } + r.osClient, err = util.CreateClientForCluster(r.client, r.ctx, r.cluster, r.osClientTransport) if err != nil { return err } + // If PolicyID not provided explicitly, use metadata.name by default policyId := r.instance.Spec.PolicyID - if r.instance.Spec.PolicyID == "" { + if policyId == "" { policyId = r.instance.Name } + err = services.DeleteISMPolicy(r.ctx, r.osClient, policyId) if err != nil { return err diff --git a/opensearch-operator/pkg/reconcilers/ismpolicy_test.go b/opensearch-operator/pkg/reconcilers/ismpolicy_test.go index 22351613..68acabb4 100644 --- a/opensearch-operator/pkg/reconcilers/ismpolicy_test.go +++ b/opensearch-operator/pkg/reconcilers/ismpolicy_test.go @@ -176,7 +176,7 @@ var _ = Describe("ism policy reconciler", func() { When("existing status is nil", func() { var localExtraCalls = 4 BeforeEach(func() { - policyRequest := requests.ISMPolicy{ + policyRequest := requests.ISMPolicySpec{ DefaultState: "abc", Description: "test", } @@ -208,7 +208,7 @@ var _ = Describe("ism policy reconciler", func() { cluster.Namespace, instance.Name, ), - httpmock.NewJsonResponderOrPanic(200, responses.GetISMPoliciesResponse{ + httpmock.NewJsonResponderOrPanic(200, responses.GetISMPolicyResponse{ Policy: policyRequest, }).Then( httpmock.NewStringResponder(404, "does not exist"), @@ -256,7 +256,7 @@ var _ = Describe("ism policy reconciler", func() { When("policy exists in opensearch and is the same", func() { BeforeEach(func() { - policyRequest := requests.ISMPolicy{ + policyRequest := requests.ISMPolicySpec{ DefaultState: "", Description: "", } @@ -268,10 +268,8 @@ var _ = Describe("ism policy reconciler", func() { cluster.Namespace, instance.Name, ), - httpmock.NewJsonResponderOrPanic(200, responses.GetISMPoliciesResponse{ + httpmock.NewJsonResponderOrPanic(200, responses.GetISMPolicyResponse{ Policy: policyRequest, - SequenceNumber: seqno, - PrimaryTerm: seqno, }).Once(failMessage), ) }) @@ -284,7 +282,7 @@ var _ = Describe("ism policy reconciler", func() { When("policy exists in opensearch and is not the same", func() { BeforeEach(func() { recorder = record.NewFakeRecorder(1) - policyRequest := requests.ISMPolicy{ + policyRequest := requests.ISMPolicySpec{ DefaultState: "policy", Description: "test-policy", } @@ -296,10 +294,8 @@ var _ = Describe("ism policy reconciler", func() { cluster.Namespace, instance.Name, ), - httpmock.NewJsonResponderOrPanic(200, responses.GetISMPoliciesResponse{ + httpmock.NewJsonResponderOrPanic(200, responses.GetISMPolicyResponse{ Policy: policyRequest, - SequenceNumber: seqno, - PrimaryTerm: seqno, PolicyID: "test-policy", }).Once(failMessage), )