Skip to content
This repository was archived by the owner on Feb 9, 2025. It is now read-only.

Commit be0e3b3

Browse files
authored
Merge pull request #3 from DocPlanner/feat/cross-namespaced-credentials-optional-vhost
feat: Add cross-namespace credentials & make vhost optional on regex
2 parents 28663b1 + b84af87 commit be0e3b3

File tree

7 files changed

+598
-528
lines changed

7 files changed

+598
-528
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,30 @@ spec:
5858
# Configuration parameters to be able to connect with RabbitMQ
5959
rabbitConnection:
6060
url: "https://your-server.rmq.cloudamqp.com"
61-
vhost: "shared"
6261
queue: "your-queue-here"
6362
useRegex: true
6463

65-
# Setting credentials is optional.
66-
# ATTENTION: If set, BOT are required
64+
# (Optional) Vhost can be set (or not) when searching queues using regex patterns,
65+
# (Mandatory) Vhost is required for searches based on exact queue names.
66+
vhost: "shared"
67+
68+
# (Optional) Credentials to authenticate against endpoint.
69+
# If set, both are required
6770
credentials:
6871
username:
6972
secretRef:
7073
name: testing-secret
7174
key: RABBITMQ_USERNAME
75+
76+
# (Optional) Getting credentials from other namespace is possible too
77+
# When namespace is not defined, the same where this WorkloadAction CR is running will be used
78+
namespace: default
7279
password:
7380
secretRef:
7481
name: testing-secret
7582
key: RABBITMQ_PASSWORD
7683

77-
# Additional sources to get information from.
84+
# (Optional) Additional sources to get information from.
7885
# This sources can be used on condition.value
7986
additionalSources:
8087
- apiVersion: apps/v1
@@ -83,10 +90,13 @@ spec:
8390
namespace: default
8491

8592
# This is the condition that will trigger the execution of the action.
86-
# The 'key' field admits dot notation, and it's covered by gjson
87-
# Ref: https://github.com/tidwall/gjson
8893
condition:
94+
# The 'key' field admits dot notation, and it's covered by gjson
95+
# Ref: https://github.com/tidwall/gjson
8996
key: "test"
97+
98+
# Additional sources from 'additionalSources' field can be used here to craft complex values using the pattern:
99+
# [index]{{ gjson }}
90100
value: "something"
91101

92102
# Action to do with the workload when the condition is met

api/v1alpha1/workloadaction_types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ import (
2323

2424
// SecretKeyReferenceSpec represents a reference to a Secret resource in the same namespace
2525
type SecretKeyReferenceSpec struct {
26+
// Namespace of the Secret.
27+
Namespace string `json:"namespace,omitempty"`
28+
2629
// Name of the Secret.
2730
Name string `json:"name"`
2831

29-
// Key in the Secret, when not specified an implementation-specific default key is used.
30-
Key string `json:"key,omitempty"`
32+
// Key in the Secret.
33+
Key string `json:"key"`
3134
}
3235

3336
// SynchronizationSpec defines the spec of the synchronization section of a WorkloadAction
@@ -49,7 +52,7 @@ type RabbitConnectionCredentialsSpec struct {
4952
// RabbitConnectionSpec represents the connection settings to connect with RabbitMQ admin API
5053
type RabbitConnectionSpec struct {
5154
Url string `json:"url"`
52-
Vhost string `json:"vhost"`
55+
Vhost string `json:"vhost,omitempty"`
5356
Queue string `json:"queue"`
5457
UseRegex bool `json:"useRegex,omitempty"`
5558
Credentials RabbitConnectionCredentialsSpec `json:"credentials,omitempty"`

config/crd/bases/rabbit-stalker.docplanner.com_workloadactions.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,16 @@ spec:
153153
to a Secret resource in the same namespace
154154
properties:
155155
key:
156-
description: Key in the Secret, when not specified
157-
an implementation-specific default key is used.
156+
description: Key in the Secret.
158157
type: string
159158
name:
160159
description: Name of the Secret.
161160
type: string
161+
namespace:
162+
description: Namespace of the Secret.
163+
type: string
162164
required:
165+
- key
163166
- name
164167
type: object
165168
required:
@@ -174,13 +177,16 @@ spec:
174177
to a Secret resource in the same namespace
175178
properties:
176179
key:
177-
description: Key in the Secret, when not specified
178-
an implementation-specific default key is used.
180+
description: Key in the Secret.
179181
type: string
180182
name:
181183
description: Name of the Secret.
182184
type: string
185+
namespace:
186+
description: Namespace of the Secret.
187+
type: string
183188
required:
189+
- key
184190
- name
185191
type: object
186192
required:
@@ -201,7 +207,6 @@ spec:
201207
required:
202208
- queue
203209
- url
204-
- vhost
205210
type: object
206211
synchronization:
207212
description: SynchronizationSpec defines the behavior of synchronization

config/samples/rabbit-stalker_v1alpha1_workloadaction.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ spec:
1515
# Configuration
1616
rabbitConnection:
1717
url: "https://your-server.rmq.cloudamqp.com"
18-
vhost: "shared"
1918
queue: "your-queue-here"
2019
useRegex: true
2120

21+
# (Optional) Vhost can be set (or not) when searching queues using regex patterns,
22+
# (Mandatory) Vhost is required for searches based on exact queue names.
23+
vhost: "shared"
24+
2225
# (Optional) Credentials to authenticate against endpoint.
2326
# If set, both are required
2427
credentials:
2528
username:
2629
secretRef:
2730
name: testing-secret
2831
key: RABBITMQ_USERNAME
32+
33+
# (Optional) Getting credentials from other namespace is possible too
34+
# When namespace is not defined, the same where this WorkloadAction CR is running will be used
35+
namespace: default
2936
password:
3037
secretRef:
3138
name: testing-secret
@@ -46,7 +53,7 @@ spec:
4653
key: |-
4754
consumer_details.#(channel_details.node==rabbit@fancy-monk-sample-01).channel_details.node
4855
49-
# Additional sources can be used here to craft complex values using the following pattern:
56+
# Additional sources from 'additionalSources' field can be used here to craft complex values using the pattern:
5057
# [index]{{ gjson }}
5158
value: |-
5259
[0]{{ metadata.annotations.node }}

controllers/workloadaction_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package controllers
1919
import (
2020
"context"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"sigs.k8s.io/controller-runtime/pkg/builder"
2223
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
24+
"sigs.k8s.io/controller-runtime/pkg/predicate"
2325
"time"
2426

2527
"k8s.io/apimachinery/pkg/runtime"
@@ -126,7 +128,7 @@ func (r *WorkloadActionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
126128
return result, err
127129
}
128130
result = ctrl.Result{
129-
Requeue: true,
131+
//Requeue: true,
130132
RequeueAfter: RequeueTime,
131133
}
132134

@@ -153,6 +155,6 @@ func (r *WorkloadActionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
153155
// SetupWithManager sets up the controller with the Manager.
154156
func (r *WorkloadActionReconciler) SetupWithManager(mgr ctrl.Manager) error {
155157
return ctrl.NewControllerManagedBy(mgr).
156-
For(&rabbitstalkerv1alpha1.WorkloadAction{}).
158+
For(&rabbitstalkerv1alpha1.WorkloadAction{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
157159
Complete(r)
158160
}

controllers/workloadaction_status.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ const (
1111
// ConditionTypeWorkloadActionReady indicates that the WorkloadAction is ready to act or not
1212
ConditionTypeWorkloadActionReady = "WorkloadActionReady"
1313

14+
// Workload not found
15+
ConditionReasonWorkloadNotFound = "WorkloadNotFound"
16+
ConditionReasonWorkloadNotFoundMessage = "Workload resource was not found"
17+
1418
// Credentials not found
1519
ConditionReasonCredentialsNotFound = "CredentialsNotFound"
1620
ConditionReasonCredentialsNotFoundMessage = "Credentials secret or key not found"
1721

18-
// Credentials not valid
19-
//ConditionReasonCredentialsNotValid = "CredentialsNotValid"
20-
//ConditionReasonCredentialsNotValidMessage = "Credentials does not allow to authenticate"
22+
// Required field not found
23+
ConditionReasonRequiredFieldNotFound = "RequiredFieldNotFound"
24+
ConditionReasonRequiredFieldNotFoundMessage = "Required field not found. Is vhost set on literal queue name?"
2125

2226
// HTTPRequest failed
2327
ConditionReasonUrlParsingFailed = "UrlParsingFailed"
@@ -27,22 +31,22 @@ const (
2731
ConditionReasonHttpResponseNotSuccessful = "HttpRequestNotSuccessful"
2832
ConditionReasonHttpResponseNotSuccessfulMessage = "Http request returned status code: %d"
2933

34+
// Queue not found
35+
ConditionReasonQueueNotFound = "QueueNotFound"
36+
ConditionReasonQueueNotFoundMessage = "No queues were found with defined name"
37+
38+
// Condition value parsing failed
39+
ConditionReasonConditionValueParsingFailed = "ConditionValueParsingFailed"
40+
ConditionReasonConditionValueParsingFailedMessage = "Condition value parsing process failed"
41+
3042
// HTTPResponse not valid
3143
ConditionReasonHttpResponseNotValid = "HttpResponseNotValid"
3244
ConditionReasonHttpResponseNotValidMessage = "Response can not be parsed"
3345

34-
// Workload not found
35-
ConditionReasonWorkloadNotFound = "WorkloadNotFound"
36-
ConditionReasonWorkloadNotFoundMessage = "Workload resource was not found"
37-
3846
// Action not valid
3947
ConditionReasonInvalidAction = "InvalidAction"
4048
ConditionReasonInvalidActionMessage = "Action is invalid"
4149

42-
// Condition value parsing failed
43-
ConditionReasonConditionValueParsingFailed = "ConditionValueParsingFailed"
44-
ConditionReasonConditionValueParsingFailedMessage = "Condition value parsing process failed"
45-
4650
// Action execution failed
4751
ConditionReasonActionExecutionFailed = "ActionExecutionFailed"
4852
ConditionReasonActionExecutionFailedMessage = "Action failed during execution"

0 commit comments

Comments
 (0)