From 2f51067e7559ae705d823b979eb8244cf24678c1 Mon Sep 17 00:00:00 2001 From: niv8 <84956605+niv8@users.noreply.github.com> Date: Tue, 10 Dec 2024 12:44:43 +0200 Subject: [PATCH] psmdb.percona.com/PerconaServerMongoDB resource customization (#20628) Signed-off-by: Niv Amitai --- .../PerconaServerMongoDB/health.lua | 18 +++++++++++++ .../PerconaServerMongoDB/health_test.yaml | 25 +++++++++++++++++++ .../PerconaServerMongoDB/testdata/error.yaml | 25 +++++++++++++++++++ .../testdata/initializing.yaml | 25 +++++++++++++++++++ .../PerconaServerMongoDB/testdata/paused.yaml | 25 +++++++++++++++++++ .../PerconaServerMongoDB/testdata/ready.yaml | 25 +++++++++++++++++++ .../testdata/stopping.yaml | 25 +++++++++++++++++++ .../testdata/unknown.yaml | 10 ++++++++ 8 files changed, 178 insertions(+) create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health.lua create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health_test.yaml create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/error.yaml create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/initializing.yaml create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/paused.yaml create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/ready.yaml create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/stopping.yaml create mode 100644 resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/unknown.yaml diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health.lua b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health.lua new file mode 100644 index 0000000000000..48ef1a8aea9d6 --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health.lua @@ -0,0 +1,18 @@ +local hs = {} +if obj.status ~= nil then + local state_map = { + initializing = "Progressing", + ready = "Healthy", + error = "Degraded", + stopping = "Progressing", + paused = "Suspended" + } + + hs.status = state_map[obj.status.state] or "Unknown" + hs.message = obj.status.ready .. "/" .. obj.status.size .. " node(s) are ready" + return hs +end + +hs.status = "Unknown" +hs.message = "Cluster status is unknown" +return hs diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health_test.yaml b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health_test.yaml new file mode 100644 index 0000000000000..7949e34ec4ce9 --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/health_test.yaml @@ -0,0 +1,25 @@ +tests: +- healthStatus: + status: Progressing + message: "0/9 node(s) are ready" + inputPath: testdata/initializing.yaml +- healthStatus: + status: Healthy + message: "9/9 node(s) are ready" + inputPath: testdata/ready.yaml +- healthStatus: + status: Suspended + message: "0/9 node(s) are ready" + inputPath: testdata/paused.yaml +- healthStatus: + status: Progressing + message: "6/9 node(s) are ready" + inputPath: testdata/stopping.yaml +- healthStatus: + status: Degraded + message: "0/9 node(s) are ready" + inputPath: testdata/error.yaml +- healthStatus: + status: Unknown + message: "0/0 node(s) are ready" + inputPath: testdata/unknown.yaml diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/error.yaml b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/error.yaml new file mode 100644 index 0000000000000..74914f3c55ca8 --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/error.yaml @@ -0,0 +1,25 @@ +apiVersion: psmdb.percona.com/v1 +kind: PerconaServerMongoDB +metadata: + name: cluster +spec: {} +status: + mongos: + ready: 0 + size: 3 + status: error + observedGeneration: 1 + ready: 0 + replsets: + cfg: + initialized: true + ready: 0 + size: 3 + status: error + rs0: + initialized: true + ready: 0 + size: 3 + status: error + size: 9 + state: error diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/initializing.yaml b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/initializing.yaml new file mode 100644 index 0000000000000..a59e055f3d7e7 --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/initializing.yaml @@ -0,0 +1,25 @@ +apiVersion: psmdb.percona.com/v1 +kind: PerconaServerMongoDB +metadata: + name: cluster +spec: {} +status: + mongos: + ready: 0 + size: 3 + status: initializing + observedGeneration: 1 + ready: 0 + replsets: + cfg: + initialized: false + ready: 0 + size: 3 + status: initializing + rs0: + initialized: false + ready: 0 + size: 3 + status: initializing + size: 9 + state: initializing diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/paused.yaml b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/paused.yaml new file mode 100644 index 0000000000000..722cc2536fbce --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/paused.yaml @@ -0,0 +1,25 @@ +apiVersion: psmdb.percona.com/v1 +kind: PerconaServerMongoDB +metadata: + name: cluster +spec: {} +status: + mongos: + ready: 0 + size: 3 + status: paused + observedGeneration: 1 + ready: 0 + replsets: + cfg: + initialized: true + ready: 0 + size: 3 + status: paused + rs0: + initialized: true + ready: 0 + size: 3 + status: paused + size: 9 + state: paused diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/ready.yaml b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/ready.yaml new file mode 100644 index 0000000000000..9d3b62a7fb640 --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/ready.yaml @@ -0,0 +1,25 @@ +apiVersion: psmdb.percona.com/v1 +kind: PerconaServerMongoDB +metadata: + name: cluster +spec: {} +status: + mongos: + ready: 3 + size: 3 + status: ready + observedGeneration: 1 + ready: 9 + replsets: + cfg: + initialized: true + ready: 3 + size: 3 + status: ready + rs0: + initialized: true + ready: 3 + size: 3 + status: ready + size: 9 + state: ready diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/stopping.yaml b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/stopping.yaml new file mode 100644 index 0000000000000..d4f7f3ae03eba --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/stopping.yaml @@ -0,0 +1,25 @@ +apiVersion: psmdb.percona.com/v1 +kind: PerconaServerMongoDB +metadata: + name: cluster +spec: {} +status: + mongos: + ready: 2 + size: 3 + status: stopping + observedGeneration: 1 + ready: 6 + replsets: + cfg: + initialized: true + ready: 2 + size: 3 + status: stopping + rs0: + initialized: true + ready: 2 + size: 3 + status: stopping + size: 9 + state: stopping diff --git a/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/unknown.yaml b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/unknown.yaml new file mode 100644 index 0000000000000..7b06350e18023 --- /dev/null +++ b/resource_customizations/psmdb.percona.com/PerconaServerMongoDB/testdata/unknown.yaml @@ -0,0 +1,10 @@ +apiVersion: psmdb.percona.com/v1 +kind: PerconaServerMongoDB +metadata: + name: cluster +spec: {} +status: + observedGeneration: 1 + ready: 0 + size: 0 + state: ""