-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(health): add Rabbitmq topology resource customizations #22066
base: master
Are you sure you want to change the base?
Changes from 11 commits
74a1c33
e6e4629
9a3e8cc
2d951db
a9beb45
1c6ae59
64b9ce3
5004a62
16f2eb6
044ce56
17a3071
3da2012
d6006f8
fa665e4
844fa62
73a56e6
3666f7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local hs = {} | ||
if obj.status ~= nil then | ||
if obj.status.conditions ~= nil then | ||
|
||
for i, condition in ipairs(obj.status.conditions) do | ||
if condition.type ~= nil then | ||
if condition.type == "Ready" then | ||
if condition.status ~= nil and condition.reason ~= nil then | ||
if condition.status == "True" and condition.reason == "SuccessfulCreateOrUpdate" then | ||
hs.status = "Healthy" | ||
hs.message = "RabbitMQ binding ready" | ||
return hs | ||
end | ||
|
||
if condition.status == "False" and condition.reason == "FailedCreateOrUpdate" then | ||
hs.status = "Degraded" | ||
hs.message = "RabbitMQ binding failed to be created or updated" | ||
return hs | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
hs.status = "Unknown" | ||
hs.message = "RabbitMQ binding status is unknown" | ||
return hs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests: | ||
- healthStatus: | ||
status: Degraded | ||
message: RabbitMQ binding failed to be created or updated | ||
inputPath: testdata/degraded.yaml | ||
- healthStatus: | ||
status: Unknown | ||
message: RabbitMQ binding status is unknown | ||
inputPath: testdata/unknown.yaml | ||
- healthStatus: | ||
status: Healthy | ||
message: RabbitMQ binding ready | ||
inputPath: testdata/healthy.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Binding | ||
metadata: | ||
labels: | ||
app: example-rabbitmq | ||
name: example-rabbitmq | ||
namespace: example | ||
spec: | ||
destination: destination | ||
destinationType: queue | ||
rabbitmqClusterReference: | ||
name: example-rabbitmq | ||
routingKey: v1.example.request | ||
source: operation-requests | ||
vhost: / | ||
status: | ||
conditions: | ||
- lastTransitionTime: 2025-02-24T17:51:10Z | ||
reason: FailedCreateOrUpdate | ||
status: "False" | ||
type: Ready | ||
observedGeneration: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Binding | ||
metadata: | ||
labels: | ||
app: example-rabbitmq | ||
name: example-rabbitmq | ||
namespace: example | ||
spec: | ||
destination: destination | ||
destinationType: queue | ||
rabbitmqClusterReference: | ||
name: example-rabbitmq | ||
routingKey: v1.example.request | ||
source: operation-requests | ||
vhost: / | ||
status: | ||
conditions: | ||
- lastTransitionTime: 2025-02-24T17:51:10Z | ||
reason: SuccessfulCreateOrUpdate | ||
status: "True" | ||
type: Ready | ||
observedGeneration: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Binding | ||
metadata: | ||
labels: | ||
app: example-rabbitmq | ||
name: example-rabbitmq | ||
namespace: example | ||
spec: | ||
destination: destination | ||
destinationType: queue | ||
rabbitmqClusterReference: | ||
name: example-rabbitmq | ||
routingKey: v1.example.request | ||
source: operation-requests | ||
vhost: / | ||
status: {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local hs = {} | ||
if obj.status ~= nil then | ||
if obj.status.conditions ~= nil then | ||
|
||
for i, condition in ipairs(obj.status.conditions) do | ||
if condition.type ~= nil then | ||
if condition.type == "Ready" then | ||
if condition.status ~= nil and condition.reason ~= nil then | ||
if condition.status == "True" and condition.reason == "SuccessfulCreateOrUpdate" then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
hs.status = "Healthy" | ||
hs.message = "RabbitMQ exchange ready" | ||
return hs | ||
end | ||
|
||
if condition.status == "False" and condition.reason == "FailedCreateOrUpdate" then | ||
hs.status = "Degraded" | ||
hs.message = "RabbitMQ exchange failed to be created or updated" | ||
return hs | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
hs.status = "Unknown" | ||
hs.message = "RabbitMQ exchange status is unknown" | ||
return hs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests: | ||
- healthStatus: | ||
status: Degraded | ||
message: RabbitMQ exchange failed to be created or updated | ||
inputPath: testdata/degraded.yaml | ||
- healthStatus: | ||
status: Unknown | ||
message: RabbitMQ exchange status is unknown | ||
inputPath: testdata/unknown.yaml | ||
- healthStatus: | ||
status: Healthy | ||
message: RabbitMQ exchange ready | ||
inputPath: testdata/healthy.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Exchange | ||
metadata: | ||
generation: 3 | ||
name: example-rabbit | ||
namespace: example-rabbit | ||
spec: | ||
autoDelete: false | ||
durable: true | ||
name: example-rabbit | ||
rabbitmqClusterReference: | ||
name: example-rabbit | ||
type: topic | ||
vhost: / | ||
status: | ||
conditions: | ||
- lastTransitionTime: 2025-02-24T17:51:10Z | ||
reason: FailedCreateOrUpdate | ||
status: "False" | ||
type: Ready | ||
observedGeneration: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Exchange | ||
metadata: | ||
generation: 3 | ||
name: example-rabbit | ||
namespace: example-rabbit | ||
spec: | ||
autoDelete: false | ||
durable: true | ||
name: example-rabbit | ||
rabbitmqClusterReference: | ||
name: example-rabbit | ||
type: topic | ||
vhost: / | ||
status: | ||
conditions: | ||
- lastTransitionTime: 2025-02-24T17:51:10Z | ||
reason: SuccessfulCreateOrUpdate | ||
status: "True" | ||
type: Ready | ||
observedGeneration: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Exchange | ||
metadata: | ||
generation: 3 | ||
name: example-rabbit | ||
namespace: example-rabbit | ||
spec: | ||
autoDelete: false | ||
durable: true | ||
name: example-rabbit | ||
rabbitmqClusterReference: | ||
name: example-rabbit | ||
type: topic | ||
vhost: / | ||
status: {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local hs = {} | ||
if obj.status ~= nil then | ||
if obj.status.conditions ~= nil then | ||
|
||
for i, condition in ipairs(obj.status.conditions) do | ||
if condition.type ~= nil then | ||
if condition.type == "Ready" then | ||
if condition.status ~= nil and condition.reason ~= nil then | ||
if condition.status == "True" and condition.reason == "SuccessfulCreateOrUpdate" then | ||
hs.status = "Healthy" | ||
hs.message = "RabbitMQ permission ready" | ||
return hs | ||
end | ||
|
||
if condition.status == "False" and condition.reason == "FailedCreateOrUpdate" then | ||
hs.status = "Degraded" | ||
hs.message = "RabbitMQ permission failed to be created or updated" | ||
return hs | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
hs.status = "Unknown" | ||
hs.message = "RabbitMQ permission status is unknown" | ||
return hs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests: | ||
- healthStatus: | ||
status: Degraded | ||
message: RabbitMQ permission failed to be created or updated | ||
inputPath: testdata/degraded.yaml | ||
- healthStatus: | ||
status: Unknown | ||
message: RabbitMQ permission status is unknown | ||
inputPath: testdata/unknown.yaml | ||
- healthStatus: | ||
status: Healthy | ||
message: RabbitMQ permission ready | ||
inputPath: testdata/healthy.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Permission | ||
metadata: | ||
generation: 1 | ||
name: example-rabbit | ||
namespace: example-rabbit | ||
spec: | ||
permissions: | ||
configure: .* | ||
read: .* | ||
write: .* | ||
rabbitmqClusterReference: | ||
name: example-rabbit | ||
namespace: exmple-rabbit | ||
user: example_user | ||
vhost: / | ||
status: | ||
conditions: | ||
- lastTransitionTime: 2025-02-24T17:51:10Z | ||
reason: FailedCreateOrUpdate | ||
status: "False" | ||
type: Ready | ||
observedGeneration: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Permission | ||
metadata: | ||
generation: 1 | ||
name: example-rabbit | ||
namespace: example-rabbit | ||
spec: | ||
permissions: | ||
configure: .* | ||
read: .* | ||
write: .* | ||
rabbitmqClusterReference: | ||
name: example-rabbit | ||
namespace: exmple-rabbit | ||
user: example_user | ||
vhost: / | ||
status: | ||
conditions: | ||
- lastTransitionTime: 2025-02-24T17:51:10Z | ||
reason: SuccessfulCreateOrUpdate | ||
status: "True" | ||
type: Ready | ||
observedGeneration: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Permission | ||
metadata: | ||
generation: 1 | ||
name: example-rabbit | ||
namespace: example-rabbit | ||
spec: | ||
permissions: | ||
configure: .* | ||
read: .* | ||
write: .* | ||
rabbitmqClusterReference: | ||
name: example-rabbit | ||
namespace: exmple-rabbit | ||
user: example_user | ||
vhost: / | ||
status: {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local hs = {} | ||
if obj.status ~= nil then | ||
if obj.status.conditions ~= nil then | ||
|
||
for i, condition in ipairs(obj.status.conditions) do | ||
if condition.type ~= nil then | ||
if condition.type == "Ready" then | ||
if condition.status ~= nil and condition.reason ~= nil then | ||
if condition.status == "True" and condition.reason == "SuccessfulCreateOrUpdate" then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
hs.status = "Healthy" | ||
hs.message = "RabbitMQ policy ready" | ||
return hs | ||
end | ||
|
||
if condition.status == "False" and condition.reason == "FailedCreateOrUpdate" then | ||
hs.status = "Degraded" | ||
hs.message = "RabbitMQ policy failed to be created or updated" | ||
return hs | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
hs.status = "Unknown" | ||
hs.message = "RabbitMQ policy status is unknown" | ||
return hs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests: | ||
- healthStatus: | ||
status: Degraded | ||
message: RabbitMQ policy failed to be created or updated | ||
inputPath: testdata/degraded.yaml | ||
- healthStatus: | ||
status: Unknown | ||
message: RabbitMQ policy status is unknown | ||
inputPath: testdata/unknown.yaml | ||
- healthStatus: | ||
status: Healthy | ||
message: RabbitMQ policy ready | ||
inputPath: testdata/healthy.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: rabbitmq.com/v1beta1 | ||
kind: Policy | ||
metadata: | ||
namespace: example-rabbit | ||
name: example-rabbit | ||
spec: | ||
name: example-rabbit | ||
vhost: example-rabbit | ||
pattern: .* | ||
applyTo: queues | ||
definition: {} | ||
rabbitmqClusterReference: | ||
name: example-rabbit | ||
namespace: example-rabbit | ||
status: | ||
conditions: | ||
- lastTransitionTime: 2025-02-24T17:51:10Z | ||
reason: FailedCreateOrUpdate | ||
status: "False" | ||
type: Ready | ||
observedGeneration: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you combine the nested ifs into one, e.g. condition.type ~= nil even seems unnecessary if we check for condition.type == "Ready"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, looking at the source code, if a condition is returned, it will have the type, status and reason keys, so no need to "nil check" them.
I removed the nil checks for the condition components.