diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index b15d2157f..e7e033c40 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -286,6 +286,22 @@ var _ = Describe("Central", func() { Expect(secretsStored).Should(ContainElements(expectedSecrets)) }) + It("should set ForceReconcile through admin API", func() { + if createdCentral == nil { + Fail("central not created") + } + + _, _, err := adminAPI.UpdateCentralById( + context.Background(), + createdCentral.Id, + private.CentralUpdateRequest{ForceReconcile: "true"}) + + Expect(err).To(BeNil()) + + privateCentral, _, err := client.PrivateAPI().GetCentral(context.Background(), createdCentral.Id) + Expect(err).To(BeNil()) + Expect(privateCentral.ForceReconcile).To(Equal("true")) + }) // TODO(ROX-11368): Add test to eventually reach ready state // TODO(ROX-11368): create test to check that Central and Scanner are healthy // TODO(ROX-11368): Create test to check Central is correctly exposed diff --git a/internal/dinosaur/pkg/handlers/admin_dinosaur.go b/internal/dinosaur/pkg/handlers/admin_dinosaur.go index 6fa5fad63..f9d3b499b 100644 --- a/internal/dinosaur/pkg/handlers/admin_dinosaur.go +++ b/internal/dinosaur/pkg/handlers/admin_dinosaur.go @@ -288,12 +288,7 @@ func updateCentralRequest(request *dbapi.CentralRequest, strategicPatch []byte) if err != nil { return fmt.Errorf("unmarshalling strategic merge patch: %w", err) } - // only keep central and scanner keys - for k := range patchMap { - if k != "central" && k != "scanner" { - delete(patchMap, k) - } - } + patchBytes, err := json.Marshal(patchMap) if err != nil { return fmt.Errorf("marshalling strategic merge patch: %w", err) @@ -308,12 +303,12 @@ func updateCentralRequest(request *dbapi.CentralRequest, strategicPatch []byte) scannerBytes = string(request.Scanner) } - var originalBytes = fmt.Sprintf("{\"central\":%s,\"scanner\":%s,\"forceReconcile\":\"%s\"}", centralBytes, scannerBytes, request.ForceReconcile) + var originalBytes = fmt.Sprintf("{\"central\":%s,\"scanner\":%s,\"force_reconcile\":\"%s\"}", centralBytes, scannerBytes, request.ForceReconcile) type Original struct { Central *dbapi.CentralSpec `json:"central,omitempty"` Scanner *dbapi.ScannerSpec `json:"scanner,omitempty"` - ForceReconcile string `json:"forceReconcile,omitempty"` + ForceReconcile string `json:"force_reconcile,omitempty"` } // apply the patch diff --git a/internal/dinosaur/pkg/handlers/admin_dinosaur_test.go b/internal/dinosaur/pkg/handlers/admin_dinosaur_test.go index ca2425e61..91ff0acd8 100644 --- a/internal/dinosaur/pkg/handlers/admin_dinosaur_test.go +++ b/internal/dinosaur/pkg/handlers/admin_dinosaur_test.go @@ -165,19 +165,19 @@ func Test_updateCentralRequest(t *testing.T) { patch: `{"scanner":{"analyzer":{"resources":{"limits":null}}}}`, wantScanner: `{"analyzer":{"resources":{"requests":{"cpu":"1","memory":"1"}},"scaling":{}},"db":{"resources":{}}}`, }, { - name: "replacing forceReconcile", - state: `{"forceReconcile":"foo"}`, - patch: `{"forceReconcile":"bar"}`, + name: "replacing force_reconcile", + state: `{"force_reconcile":"foo"}`, + patch: `{"force_reconcile":"bar"}`, wantForceReconcile: "bar", }, { - name: "unsetting forceReconcile", - state: `{"forceReconcile":"foo"}`, - patch: `{"forceReconcile":null}`, + name: "unsetting force_reconcile", + state: `{"force_reconcile":"foo"}`, + patch: `{"force_reconcile":null}`, wantForceReconcile: "", }, { - name: "setting forceReconcile to empty string", - state: `{"forceReconcile":"foo"}`, - patch: `{"forceReconcile":""}`, + name: "setting force_reconcile to empty string", + state: `{"force_reconcile":"foo"}`, + patch: `{"force_reconcile":""}`, wantForceReconcile: "", }, { name: "should fail if the patch is invalid json", @@ -217,6 +217,8 @@ func Test_updateCentralRequest(t *testing.T) { if len(tt.wantCentral) > 0 { assert.Equal(t, string(tt.wantCentral), string(request.Central)) } + + assert.Equal(t, tt.wantForceReconcile, request.ForceReconcile) } }) }