Skip to content

Commit f9b9df3

Browse files
author
dfradejas
committed
WIP
1 parent 7daba31 commit f9b9df3

16 files changed

+379
-133
lines changed

api/v1alpha1/common_types.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,3 @@ type SecretRef struct {
66
KeyUsername string `json:"keyUsername"`
77
KeyPassword string `json:"keyPassword"`
88
}
9-
10-
// Credentials TODO
11-
type Credentials struct {
12-
SyncInterval string `json:"syncInterval,omitempty"`
13-
SecretRef SecretRef `json:"secretRef"`
14-
}

api/v1alpha1/queryconnector_types.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@ import (
2323
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2424
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2525

26+
// Credentials TODO
27+
type QueryConnectorCredentials struct {
28+
SyncInterval string `json:"syncInterval,omitempty"`
29+
SecretRef SecretRef `json:"secretRef"`
30+
}
31+
2632
// QueryConnectorSpec defines the desired state of QueryConnector.
2733
type QueryConnectorSpec struct {
2834
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2935
// Important: Run "make" to regenerate code after modifying this file
3036

31-
URL string `json:"url"`
32-
Headers map[string]string `json:"headers,omitempty"`
33-
TlsSkipVerify bool `json:"tlsSkipVerify,omitempty"`
34-
Credentials Credentials `json:"credentials,omitempty"`
37+
URL string `json:"url"`
38+
Headers map[string]string `json:"headers,omitempty"`
39+
TlsSkipVerify bool `json:"tlsSkipVerify,omitempty"`
40+
Credentials QueryConnectorCredentials `json:"credentials,omitempty"`
3541
}
3642

3743
// QueryConnectorStatus defines the observed state of QueryConnector.

api/v1alpha1/ruleraction_types.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,27 @@ import (
2323
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2424
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2525

26+
// RulerActionCredentials TODO
27+
type RulerActionCredentials struct {
28+
SecretRef SecretRef `json:"secretRef"`
29+
}
30+
2631
// WebHook TODO
2732
type Webhook struct {
28-
Url string `json:"url"`
29-
Verb string `json:"verb"`
30-
Headers map[string]string `json:"headers,omitempty"`
31-
Validator string `json:"validator,omitempty"`
32-
Credentials Credentials `json:"credentials,omitempty"`
33+
Url string `json:"url"`
34+
Verb string `json:"verb"`
35+
Headers map[string]string `json:"headers,omitempty"`
36+
Validator string `json:"validator,omitempty"`
37+
Credentials RulerActionCredentials `json:"credentials,omitempty"`
3338
}
3439

3540
// RulerActionSpec defines the desired state of RulerAction.
3641
type RulerActionSpec struct {
3742
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3843
// Important: Run "make" to regenerate code after modifying this file
3944

40-
Webhook Webhook `json:"webhook"`
45+
Webhook Webhook `json:"webhook"`
46+
FiringInterval string `json:"firingInterval"`
4147
}
4248

4349
// RulerActionStatus defines the observed state of RulerAction.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 32 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ func main() {
155155
}
156156

157157
// Define pools
158-
var RulerActionCredentialsPool = &pools.CredentialsStore{
159-
Store: make(map[string]*pools.Credentials),
160-
}
161158
var QueryConnectorCredentialsPool = &pools.CredentialsStore{
162159
Store: make(map[string]*pools.Credentials),
163160
}
@@ -169,10 +166,9 @@ func main() {
169166
}
170167

171168
if err = (&controller.RulerActionReconciler{
172-
Client: mgr.GetClient(),
173-
Scheme: mgr.GetScheme(),
174-
CredentialsPool: RulerActionCredentialsPool,
175-
AlertsPool: AlertsPool,
169+
Client: mgr.GetClient(),
170+
Scheme: mgr.GetScheme(),
171+
AlertsPool: AlertsPool,
176172
}).SetupWithManager(mgr); err != nil {
177173
setupLog.Error(err, "unable to create controller", "controller", "RulerAction")
178174
os.Exit(1)

config/crd/bases/searchruler.prosimcorp.com_ruleractions.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ spec:
3939
spec:
4040
description: RulerActionSpec defines the desired state of RulerAction.
4141
properties:
42+
firingInterval:
43+
type: string
4244
webhook:
4345
description: WebHook TODO
4446
properties:
4547
credentials:
46-
description: Credentials TODO
48+
description: RulerActionCredentials TODO
4749
properties:
4850
secretRef:
4951
description: SecretReference TODO
@@ -59,8 +61,6 @@ spec:
5961
- keyUsername
6062
- name
6163
type: object
62-
syncInterval:
63-
type: string
6464
required:
6565
- secretRef
6666
type: object
@@ -79,6 +79,7 @@ spec:
7979
- verb
8080
type: object
8181
required:
82+
- firingInterval
8283
- webhook
8384
type: object
8485
status:

config/samples/searchruler_v1alpha1_ruleraction.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ metadata:
66
app.kubernetes.io/managed-by: kustomize
77
name: ruleraction-sample
88
spec:
9+
firingInterval: 1m
910
webhook:
10-
url: <URL>
11+
url: https://webhook.site/7688d5a6-af64-40d4-9991-01cb3b9035a7
1112
verb: POST
1213
headers: {}
1314
validator: alertmanager
14-
credentials:
15-
16-
# Interval to check secret credentials for any changes
17-
#syncInterval: 1m
18-
19-
secretRef:
20-
name: alertmanager-credentials
21-
keyUsername: username
22-
keyPassword: password
15+
# credentials:
16+
# secretRef:
17+
# name: alertmanager-credentials
18+
# keyUsername: username
19+
# keyPassword: password

config/samples/searchruler_v1alpha1_searchrule.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ spec:
8181
condition:
8282
# greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual or equal
8383
operator: "greaterThan"
84-
threshold: "500"
84+
threshold: "100"
8585
for: "15s"
8686

8787
# SearchAction item
8888
actionRef:
8989
name: ruleraction-sample
9090
data: |
9191
{{- $object := .object -}}
92-
{{- printf "Hi, I'm on fire: %s/%s" $object.metadata.namespace $object.metadata.name -}}
92+
{{- $value := .value -}}
93+
{{ printf "Hi, I'm on fire!" -}}
94+
{{ printf "Name: %s" $object.Name -}}
95+
{{ printf "Description: %s" $object.Spec.Description -}}
96+
{{ printf "Current value: %v" $value -}}

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ require (
1414
)
1515

1616
require (
17+
github.com/BurntSushi/toml v1.4.0 // indirect
18+
github.com/Masterminds/goutils v1.1.1 // indirect
19+
github.com/Masterminds/semver v1.5.0 // indirect
20+
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
1721
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
1822
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
1923
github.com/beorn7/perks v1.0.1 // indirect
@@ -43,11 +47,14 @@ require (
4347
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect
4448
github.com/google/uuid v1.6.0 // indirect
4549
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
50+
github.com/huandu/xstrings v1.5.0 // indirect
4651
github.com/imdario/mergo v0.3.6 // indirect
4752
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4853
github.com/josharian/intern v1.0.0 // indirect
4954
github.com/json-iterator/go v1.1.12 // indirect
5055
github.com/mailru/easyjson v0.7.7 // indirect
56+
github.com/mitchellh/copystructure v1.2.0 // indirect
57+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
5158
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5259
github.com/modern-go/reflect2 v1.0.2 // indirect
5360
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -72,6 +79,7 @@ require (
7279
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
7380
go.uber.org/multierr v1.11.0 // indirect
7481
go.uber.org/zap v1.26.0 // indirect
82+
golang.org/x/crypto v0.24.0 // indirect
7583
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
7684
golang.org/x/net v0.26.0 // indirect
7785
golang.org/x/oauth2 v0.21.0 // indirect

go.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
2+
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
3+
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
4+
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
5+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
6+
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
7+
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
8+
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
19
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
210
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
311
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
@@ -66,6 +74,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6674
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
6775
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
6876
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
77+
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
78+
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
6979
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
7080
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
7181
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
@@ -85,6 +95,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
8595
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
8696
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
8797
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
98+
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
99+
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
100+
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
101+
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
88102
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
89103
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
90104
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -164,6 +178,8 @@ go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
164178
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
165179
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
166180
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
181+
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
182+
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
167183
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
168184
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
169185
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=

internal/controller/queryconnector_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ func (r *QueryConnectorReconciler) Reconcile(ctx context.Context, req ctrl.Reque
121121
}
122122

123123
// 7. Sync credentials if defined
124-
if QueryConnectorResource.Spec.Credentials.SecretRef.Name != "" {
124+
emptyCredentials := searchrulerv1alpha1.QueryConnectorCredentials{}
125+
if QueryConnectorResource.Spec.Credentials != emptyCredentials {
125126
err = r.SyncCredentials(ctx, QueryConnectorResource)
126127
if err != nil {
127128
r.UpdateConditionKubernetesApiCallFailure(QueryConnectorResource)

0 commit comments

Comments
 (0)