Skip to content

Commit 74fc4f8

Browse files
authored
fix(sm): allow string for probes in check composition (#71)
* fix(sm): allow string for probes in check composition The SM Check expects probe IDs for the probes, in Terraform the `grafana_synthetic_monitoring_probes` data source can be used to grab those based on the probe name. Crossplane (Upjet) doesn't have a 'data source' concept so that is not possible. The grafana-data function[1] aims to provide the translation from name to ID. To accommodate for that, the XRD will need to allow for probes to be names, then the function can replace those with IDs in the composite. [1] https://github.com/grafana/crossplane-function-grafana-data/ * fix: implement IntOrString according to CRD docs * fix: must be anyOf * fix: correctly patch item * fix: s/number/integer
1 parent 7c13cad commit 74fc4f8

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

generator/namespaced.libsonnet

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,58 @@ local renameGroup(obj) =
2828
},
2929
};
3030

31+
local addProbeNamesToSMCheck(obj) =
32+
if obj.definition.metadata.name == 'xchecks.sm.grafana.net.namespaced'
33+
then obj + {
34+
definition+: {
35+
local versions = super.spec.versions,
36+
spec+: {
37+
versions:
38+
local patch = {
39+
properties+: {
40+
probes+: {
41+
items: {
42+
// ref: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#intorstring
43+
'x-kubernetes-int-or-string': true,
44+
anyOf: [
45+
{ type: 'integer' },
46+
{ type: 'string' },
47+
],
48+
},
49+
},
50+
},
51+
};
52+
std.map(
53+
function(version)
54+
version + {
55+
schema+: {
56+
openAPIV3Schema+: {
57+
properties+: {
58+
spec+: {
59+
properties+: {
60+
parameters+: {
61+
properties+: {
62+
forProvider+: patch,
63+
initProvider+: patch,
64+
},
65+
},
66+
},
67+
},
68+
},
69+
},
70+
},
71+
},
72+
versions,
73+
),
74+
},
75+
},
76+
}
77+
else obj;
78+
3179
std.foldr(
3280
std.map,
3381
[
82+
addProbeNamesToSMCheck,
3483
renameGroup,
3584
cngen.fromCRD,
3685
],

packages/grafana-namespaced-sm/CompositeResourceDefinition-Check.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ spec:
9292
(Set of Number) List of probe location IDs where this target will be checked from.
9393
List of probe location IDs where this target will be checked from.
9494
items:
95-
type: number
95+
anyOf:
96+
- type: integer
97+
- type: string
98+
x-kubernetes-int-or-string: true
9699
type: array
97100
x-kubernetes-list-type: set
98101
settings:
@@ -916,7 +919,10 @@ spec:
916919
(Set of Number) List of probe location IDs where this target will be checked from.
917920
List of probe location IDs where this target will be checked from.
918921
items:
919-
type: number
922+
anyOf:
923+
- type: integer
924+
- type: string
925+
x-kubernetes-int-or-string: true
920926
type: array
921927
x-kubernetes-list-type: set
922928
settings:

0 commit comments

Comments
 (0)