Skip to content

Commit 0a3e135

Browse files
maltesanderclaude
andcommitted
refactor: Extract config_map build step and adopt v2 configOverrides
Move the rolegroup ConfigMap and `config.json` building out of the controller into a dedicated `controller/build/config_map.rs`. The build step now takes the `ValidatedCluster` and only uses the `OpaCluster` for the owner reference and object metadata, no longer reading `spec` for config content. To carry the merged `configOverrides` through `ValidatedCluster`, migrate `OpaConfigOverrides.config_json` from the non-mergeable `config_overrides::JsonConfigOverrides` to the v2 `JsonOrKeyValueConfigOverrides`, which: - implements `Merge`, so role- and role-group-level overrides are merged once in the validate step (role group wins) and stored on `OpaRoleGroupConfig`; - preserves the previous apply order (role patch first, then role group on top) via the v2 `JsonConfigOverrides` sequence; - applies infallibly, removing the config-override error path; - is CRD-safe (raw object schema), unlike the v2 `JsonConfigOverrides` enum whose `JsonPatch` variant cannot be rendered into a structural CRD schema. `ValidatedCluster` gains a `cluster_config` holding `user_info` so the ConfigMap build no longer needs the raw spec for `user-info-fetcher.json`. Add unit tests covering the default `config.json` and role/role-group override precedence. Regenerate extra/crds.yaml. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 49cf10e commit 0a3e135

6 files changed

Lines changed: 434 additions & 479 deletions

File tree

extra/crds.yaml

Lines changed: 12 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,69 +1136,11 @@ spec:
11361136
available config files and settings for the specific product.
11371137
properties:
11381138
config.json:
1139+
default:
1140+
jsonMergePatch: {}
11391141
description: Overrides for the OPA `config.json` file.
1140-
nullable: true
1141-
oneOf:
1142-
- required:
1143-
- jsonMergePatch
1144-
- required:
1145-
- jsonPatches
1146-
- required:
1147-
- userProvided
1148-
properties:
1149-
jsonMergePatch:
1150-
description: |-
1151-
Can be set to arbitrary YAML content, which is converted to JSON and used as
1152-
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch.
1153-
type: object
1154-
x-kubernetes-preserve-unknown-fields: true
1155-
jsonPatches:
1156-
description: |-
1157-
List of [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patches.
1158-
1159-
Can be used when more flexibility is needed, e.g. to only modify elements
1160-
in a list based on a condition.
1161-
1162-
A patch looks something like
1163-
1164-
`{"op": "test", "path": "/0/name", "value": "Andrew"}`
1165-
1166-
or
1167-
1168-
`{"op": "add", "path": "/0/happy", "value": true}`
1169-
items:
1170-
type: string
1171-
type: array
1172-
userProvided:
1173-
description: |-
1174-
Override the entire config file with the specified JSON document.
1175-
1176-
Please note that you can in-line JSON into YAML as follows:
1177-
1178-
```yaml
1179-
# ... other YAML content
1180-
userProvided: {
1181-
"myString": "test",
1182-
"myList": ["test"],
1183-
"myBool": true,
1184-
"my": {"nested.field.with.dots": 42}
1185-
}
1186-
```
1187-
1188-
As an alternative you can also stick to YAML:
1189-
1190-
```yaml
1191-
# ... other YAML content
1192-
userProvided:
1193-
myString: test
1194-
myList: [test]
1195-
myBool: true
1196-
my:
1197-
nested.field.with.dots: 42
1198-
```
1199-
type: object
1200-
x-kubernetes-preserve-unknown-fields: true
12011142
type: object
1143+
x-kubernetes-preserve-unknown-fields: true
12021144
type: object
12031145
envOverrides:
12041146
additionalProperties:
@@ -1755,69 +1697,11 @@ spec:
17551697
available config files and settings for the specific product.
17561698
properties:
17571699
config.json:
1700+
default:
1701+
jsonMergePatch: {}
17581702
description: Overrides for the OPA `config.json` file.
1759-
nullable: true
1760-
oneOf:
1761-
- required:
1762-
- jsonMergePatch
1763-
- required:
1764-
- jsonPatches
1765-
- required:
1766-
- userProvided
1767-
properties:
1768-
jsonMergePatch:
1769-
description: |-
1770-
Can be set to arbitrary YAML content, which is converted to JSON and used as
1771-
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch.
1772-
type: object
1773-
x-kubernetes-preserve-unknown-fields: true
1774-
jsonPatches:
1775-
description: |-
1776-
List of [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patches.
1777-
1778-
Can be used when more flexibility is needed, e.g. to only modify elements
1779-
in a list based on a condition.
1780-
1781-
A patch looks something like
1782-
1783-
`{"op": "test", "path": "/0/name", "value": "Andrew"}`
1784-
1785-
or
1786-
1787-
`{"op": "add", "path": "/0/happy", "value": true}`
1788-
items:
1789-
type: string
1790-
type: array
1791-
userProvided:
1792-
description: |-
1793-
Override the entire config file with the specified JSON document.
1794-
1795-
Please note that you can in-line JSON into YAML as follows:
1796-
1797-
```yaml
1798-
# ... other YAML content
1799-
userProvided: {
1800-
"myString": "test",
1801-
"myList": ["test"],
1802-
"myBool": true,
1803-
"my": {"nested.field.with.dots": 42}
1804-
}
1805-
```
1806-
1807-
As an alternative you can also stick to YAML:
1808-
1809-
```yaml
1810-
# ... other YAML content
1811-
userProvided:
1812-
myString: test
1813-
myList: [test]
1814-
myBool: true
1815-
my:
1816-
nested.field.with.dots: 42
1817-
```
1818-
type: object
1819-
x-kubernetes-preserve-unknown-fields: true
18201703
type: object
1704+
x-kubernetes-preserve-unknown-fields: true
18211705
type: object
18221706
envOverrides:
18231707
additionalProperties:
@@ -3029,69 +2913,11 @@ spec:
30292913
available config files and settings for the specific product.
30302914
properties:
30312915
config.json:
2916+
default:
2917+
jsonMergePatch: {}
30322918
description: Overrides for the OPA `config.json` file.
3033-
nullable: true
3034-
oneOf:
3035-
- required:
3036-
- jsonMergePatch
3037-
- required:
3038-
- jsonPatches
3039-
- required:
3040-
- userProvided
3041-
properties:
3042-
jsonMergePatch:
3043-
description: |-
3044-
Can be set to arbitrary YAML content, which is converted to JSON and used as
3045-
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch.
3046-
type: object
3047-
x-kubernetes-preserve-unknown-fields: true
3048-
jsonPatches:
3049-
description: |-
3050-
List of [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patches.
3051-
3052-
Can be used when more flexibility is needed, e.g. to only modify elements
3053-
in a list based on a condition.
3054-
3055-
A patch looks something like
3056-
3057-
`{"op": "test", "path": "/0/name", "value": "Andrew"}`
3058-
3059-
or
3060-
3061-
`{"op": "add", "path": "/0/happy", "value": true}`
3062-
items:
3063-
type: string
3064-
type: array
3065-
userProvided:
3066-
description: |-
3067-
Override the entire config file with the specified JSON document.
3068-
3069-
Please note that you can in-line JSON into YAML as follows:
3070-
3071-
```yaml
3072-
# ... other YAML content
3073-
userProvided: {
3074-
"myString": "test",
3075-
"myList": ["test"],
3076-
"myBool": true,
3077-
"my": {"nested.field.with.dots": 42}
3078-
}
3079-
```
3080-
3081-
As an alternative you can also stick to YAML:
3082-
3083-
```yaml
3084-
# ... other YAML content
3085-
userProvided:
3086-
myString: test
3087-
myList: [test]
3088-
myBool: true
3089-
my:
3090-
nested.field.with.dots: 42
3091-
```
3092-
type: object
3093-
x-kubernetes-preserve-unknown-fields: true
30942919
type: object
2920+
x-kubernetes-preserve-unknown-fields: true
30952921
type: object
30962922
envOverrides:
30972923
additionalProperties:
@@ -3648,69 +3474,11 @@ spec:
36483474
available config files and settings for the specific product.
36493475
properties:
36503476
config.json:
3477+
default:
3478+
jsonMergePatch: {}
36513479
description: Overrides for the OPA `config.json` file.
3652-
nullable: true
3653-
oneOf:
3654-
- required:
3655-
- jsonMergePatch
3656-
- required:
3657-
- jsonPatches
3658-
- required:
3659-
- userProvided
3660-
properties:
3661-
jsonMergePatch:
3662-
description: |-
3663-
Can be set to arbitrary YAML content, which is converted to JSON and used as
3664-
[RFC 7396](https://datatracker.ietf.org/doc/html/rfc7396) JSON merge patch.
3665-
type: object
3666-
x-kubernetes-preserve-unknown-fields: true
3667-
jsonPatches:
3668-
description: |-
3669-
List of [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) JSON patches.
3670-
3671-
Can be used when more flexibility is needed, e.g. to only modify elements
3672-
in a list based on a condition.
3673-
3674-
A patch looks something like
3675-
3676-
`{"op": "test", "path": "/0/name", "value": "Andrew"}`
3677-
3678-
or
3679-
3680-
`{"op": "add", "path": "/0/happy", "value": true}`
3681-
items:
3682-
type: string
3683-
type: array
3684-
userProvided:
3685-
description: |-
3686-
Override the entire config file with the specified JSON document.
3687-
3688-
Please note that you can in-line JSON into YAML as follows:
3689-
3690-
```yaml
3691-
# ... other YAML content
3692-
userProvided: {
3693-
"myString": "test",
3694-
"myList": ["test"],
3695-
"myBool": true,
3696-
"my": {"nested.field.with.dots": 42}
3697-
}
3698-
```
3699-
3700-
As an alternative you can also stick to YAML:
3701-
3702-
```yaml
3703-
# ... other YAML content
3704-
userProvided:
3705-
myString: test
3706-
myList: [test]
3707-
myBool: true
3708-
my:
3709-
nested.field.with.dots: 42
3710-
```
3711-
type: object
3712-
x-kubernetes-preserve-unknown-fields: true
37133480
type: object
3481+
x-kubernetes-preserve-unknown-fields: true
37143482
type: object
37153483
envOverrides:
37163484
additionalProperties:

0 commit comments

Comments
 (0)