Skip to content
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

fix: expression schema error & rename #2196

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions chart/tests/role_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ tests:
enabled: true
translate:
- path: "test"
expression:
toHost: "test"
expression: "test"
release:
name: my-release
namespace: my-namespace
Expand Down
16 changes: 16 additions & 0 deletions chart/tests/statefulset_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,19 @@ tests:
- equal:
path: kind
value: StatefulSet

- it: sync custom resources
set:
sync:
toHost:
customResources:
test.cert-manager.io:
enabled: true
translate:
- path: spec.dnsNames[*]
expression: "value.startsWith('www.') ? value.slice(4) : value"
reverseExpression: '"www."+value'
asserts:
- equal:
path: kind
value: StatefulSet
54 changes: 5 additions & 49 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3195,35 +3195,19 @@
"type": "object"
},
"TranslatePatch": {
"oneOf": [
{
"required": [
"expression"
],
"title": "expression"
},
{
"required": [
"reference"
],
"title": "reference"
},
{
"required": [
"labels"
],
"title": "labels"
}
],
"properties": {
"path": {
"type": "string",
"description": "Path is the path within the patch to target. If the path is not found within the patch, the patch is not applied."
},
"expression": {
"$ref": "#/$defs/TranslatePatchExpression",
"type": "string",
"description": "Expression transforms the value according to the given JavaScript expression."
},
"reverseExpression": {
"type": "string",
"description": "ReverseExpression transforms the value according to the given JavaScript expression."
},
"reference": {
"$ref": "#/$defs/TranslatePatchReference",
"description": "Reference treats the path value as a reference to another object and will rewrite it based on the chosen mode\nautomatically. In single-namespace mode this will translate the name to \"vxxxxxxxxx\" to avoid conflicts with\nother names, in multi-namespace mode this will not translate the name."
Expand All @@ -3236,34 +3220,6 @@
"additionalProperties": false,
"type": "object"
},
"TranslatePatchExpression": {
"oneOf": [
{
"required": [
"toHost"
],
"title": "toHost"
},
{
"required": [
"fromHost"
],
"title": "fromHost"
}
],
"properties": {
"toHost": {
"type": "string",
"description": "ToHost is the expression to apply when retrieving a change from virtual to host."
},
"fromHost": {
"type": "string",
"description": "FromHost is the patch to apply when retrieving a change from host to virtual."
}
},
"additionalProperties": false,
"type": "object"
},
"TranslatePatchLabels": {
"properties": {},
"additionalProperties": false,
Expand Down
13 changes: 8 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,18 @@ type TranslatePatch struct {
Path string `json:"path,omitempty"`

// Expression transforms the value according to the given JavaScript expression.
Expression *TranslatePatchExpression `json:"expression,omitempty" jsonschema:"oneof_required=expression"`
Expression string `json:"expression,omitempty"`

// ReverseExpression transforms the value according to the given JavaScript expression.
ReverseExpression string `json:"reverseExpression,omitempty"`

// Reference treats the path value as a reference to another object and will rewrite it based on the chosen mode
// automatically. In single-namespace mode this will translate the name to "vxxxxxxxxx" to avoid conflicts with
// other names, in multi-namespace mode this will not translate the name.
Reference *TranslatePatchReference `json:"reference,omitempty" jsonschema:"oneof_required=reference"`
Reference *TranslatePatchReference `json:"reference,omitempty"`

// Labels treats the path value as a labels selector.
Labels *TranslatePatchLabels `json:"labels,omitempty" jsonschema:"oneof_required=labels"`
Labels *TranslatePatchLabels `json:"labels,omitempty"`
}

type TranslatePatchLabels struct{}
Expand Down Expand Up @@ -539,10 +542,10 @@ type TranslatePatchReference struct {

type TranslatePatchExpression struct {
// ToHost is the expression to apply when retrieving a change from virtual to host.
ToHost string `json:"toHost,omitempty" jsonschema:"oneof_required=toHost"`
ToHost string `json:"toHost,omitempty"`

// FromHost is the patch to apply when retrieving a change from host to virtual.
FromHost string `json:"fromHost,omitempty" jsonschema:"oneof_required=fromHost"`
FromHost string `json:"fromHost,omitempty"`
}

type SyncFromHostCustomResource struct {
Expand Down
Loading