From 75f5c2a6bf5c0682764878f731b39c015da167d5 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Sat, 27 Jul 2024 21:07:01 +0530 Subject: [PATCH 1/5] extract selectors Signed-off-by: MUzairS15 --- schemas/constructs/v1alpha3/relationship.json | 46 +----- schemas/constructs/v1alpha3/selectors.json | 136 ++++++++++-------- 2 files changed, 76 insertions(+), 106 deletions(-) diff --git a/schemas/constructs/v1alpha3/relationship.json b/schemas/constructs/v1alpha3/relationship.json index dc712593fc..6118a1fb7c 100644 --- a/schemas/constructs/v1alpha3/relationship.json +++ b/schemas/constructs/v1alpha3/relationship.json @@ -57,51 +57,7 @@ } }, "selectors": { - "type": "array", - "description": "Selectors are organized as an array, with each item containing a distinct set of selectors that share a common functionality. This structure allows for flexibility in defining relationships, even when different components are involved.", - "$comment": "Sets of selectors are interpreted as a logical OR. Properties within a selector are interpreted as a logical OR, while the `allow` and `deny` properties are interpreted a logical AND.", - "items": { - "type": "object", - "description": "Optional selectors used to match Components. Absence of a selector means that it is applied to all Components.", - "additionalProperties": false, - "required": [ - "allow" - ], - "properties": { - "deny": { - "type": "object", - "description": "Optional selectors used to define relationships which should not be created / is restricted.", - "required": [ - "to", - "from" - ], - "properties": { - "from": { - "$ref": "./selectors.json#/definitions/from" - }, - "to": { - "$ref": "./selectors.json#/definitions/to" - } - } - }, - "allow": { - "type": "object", - "description": "Selectors used to define relationships which are allowed.", - "required": [ - "to", - "from" - ], - "properties": { - "from": { - "$ref": "./selectors.json#/definitions/from" - }, - "to": { - "$ref": "./selectors.json#/definitions/to" - } - } - } - } - } + "$ref": "./selectors.json#/definitions/selectors" } } } \ No newline at end of file diff --git a/schemas/constructs/v1alpha3/selectors.json b/schemas/constructs/v1alpha3/selectors.json index 2f23978cb7..68919cfdff 100644 --- a/schemas/constructs/v1alpha3/selectors.json +++ b/schemas/constructs/v1alpha3/selectors.json @@ -4,7 +4,8 @@ "description": "Reusable relationships selectors schema elements", "$comment": "Sets of selectors are interpreted as a locical OR, while sets of allow/deny are interpreted a logical AND.", "definitions": { - "from": { + "selector": { + "description": "Describes the component which are invloved in the relationship, along with set of actions to perform.", "type": "array", "items": { "type": "object", @@ -45,90 +46,103 @@ }, "patch": { "type": "object", - "additionalProperties": false, - "properties": { - "patchStrategy": { - "type": "string", - "enum": [ - "replace" - ] + "allOf": [ + { + "properties": { + "patchStrategy": { + "type": "string", + "enum": [ + "replace" + ] + } + } }, - "mutatorRef": { - "type": "array", - "items": { - "type": "array", - "items": { - "type": "string" + { + "oneOf": [ + { + "properties": { + "mutatorRef": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + }, + "description": "The sequence of mutatorRef and mutatedRef must match. eg: mutatorRef: [[config, url], [config, name]], mutatedRef: [[configPatch, value], [name]]. The value [config, url] will be patched at [configPatch, value]. Similarly [config,name] will be patched at [name]." + }, + "description": "JSON ref to value from where patch should be applied." + } + } }, - "description": "The sequence of mutatorRef and mutatedRef must match. eg: mutatorRef: [[config, url], [config, name]], mutatedRef: [[configPatch, value], [name]]. The value [config, url] will be patched at [configPatch, value]. Similarly [config,name] will be patched at [name]." - }, - "description": "JSON ref to value from where patch should be applied." + { + "properties": { + "mutatedRef": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + }, + "description": "JSONPath (https://en.wikipedia.org/wiki/JSONPath) to property to be patched." + } + } + } + } + ] } - } - } + ] + }, + "additionalProperties": false, + "properties": {} }, "description": "Optional fields that are a part of the `from` selector. Absence of a field has an implied * meaning." } }, - "to": { + "selectors": { "type": "array", + "description": "Selectors are organized as an array, with each item containing a distinct set of selectors that share a common functionality. This structure allows for flexibility in defining relationships, even when different components are involved.", + "$comment": "Sets of selectors are interpreted as a logical OR. Properties within a selector are interpreted as a logical OR, while the `allow` and `deny` properties are interpreted a logical AND.", "items": { "type": "object", + "description": "Optional selectors used to match Components. Absence of a selector means that it is applied to all Components.", "additionalProperties": false, + "required": [ + "allow" + ], "properties": { - "kind": { - "type": "string" - }, - "model": { - "$ref": "../v1beta1/model.json", - "description": "Model of the implicated component. Learn more at https://docs.meshery.io/concepts/models" - }, - "id": { - "$ref": "../core.json#/definitions/uuid", - "description": "Identifier of the implicated component. Learn more at https://docs.meshery.io/concepts/relationships" - }, - "match": { + "deny": { + "description": "Optional selectors used to define relationships which should not be created / is restricted.", "type": "object", - "additionalProperties": false, + "required": [ + "to", + "from" + ], "properties": { - "id": { - "$ref": "../core.json#/definitions/uuid", - "description": "Identifier of the implicated component. Learn more at https://docs.meshery.io/concepts/relationships" + "from": { + "$ref": "#/definitions/selector" }, - "self": { - "description": "Defines paths which should be matched with 'kind'.", - "type": "array", - "items": { - "type": "string" - } - }, - "kind": { - "description": "Optional property which defines paths which should be matched with 'self'. Here 'kind' is valid Component 'kind' belonging to the above specifed model. eg: If model is Kubernetes, valid 'kind' are 'Pod', 'Secret'. If the value for all paths of 'self' & 'kind' along with the value of all paths inside 'to.match.self' & 'to.match.kind are equal then the component with 'kind' act as an binded component. eg: ClusterRole, ClusterRoleBinding and ServiceAccount. If the paths for ClusterRole & ClusterRoleBinding and ServiceAccount & ClusterRoleBinding are equal then ClusterRoleBinding acts as an binding. Make sure the 'kind' value in 'from' and 'to' should be equal.", - "type": "array", - "items": { - "type": "string" - } + "to": { + "$ref": "#/definitions/selector" } } }, - "patch": { + "allow": { + "description": "Selectors used to define relationships which are allowed.", "type": "object", - "additionalProperties": false, + "required": [ + "to", + "from" + ], "properties": { - "patchStrategy": { - "type": "string", - "enum": [ - "replace" - ] + "from": { + "$ref": "#/definitions/selector" }, - "mutatedRef": { - "type": "string", - "description": "JSONPath (https://en.wikipedia.org/wiki/JSONPath) to property to be patched." + "to": { + "$ref": "#/definitions/selector" } } } - }, - "description": "Optional fields that are a part of the `to` selector. Absence of a field has an implied * meaning." + } } } } From 86cf5619cd8538dfe4d71227727ca6137808d5dc Mon Sep 17 00:00:00 2001 From: Lee Calcote Date: Fri, 2 Aug 2024 19:33:14 -0500 Subject: [PATCH 2/5] Apply suggestions from code review Signed-off-by: Lee Calcote --- schemas/constructs/v1alpha3/selectors.json | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/schemas/constructs/v1alpha3/selectors.json b/schemas/constructs/v1alpha3/selectors.json index 68919cfdff..662ed91946 100644 --- a/schemas/constructs/v1alpha3/selectors.json +++ b/schemas/constructs/v1alpha3/selectors.json @@ -2,10 +2,10 @@ "$id": "https://schemas.meshery.io/selectors.json", "$schema": "http://json-schema.org/draft-07/schema#", "description": "Reusable relationships selectors schema elements", - "$comment": "Sets of selectors are interpreted as a locical OR, while sets of allow/deny are interpreted a logical AND.", + "$comment": "Sets of selectors are interpreted as a logical OR, while sets of allow/deny are interpreted a logical AND.", "definitions": { "selector": { - "description": "Describes the component which are invloved in the relationship, along with set of actions to perform.", + "description": "Describes the component(s) which are involved in the relationship along with a set of actions to perform upon selection match.", "type": "array", "items": { "type": "object", @@ -50,9 +50,18 @@ { "properties": { "patchStrategy": { + "description": "patchStrategy allows you to make specific changes to a resource using a standard JSON Patch format (RFC 6902). \n\nadd: Inserts a value into an array or adds a member to an object.\nreplace: Replaces a value.\nmerge: Combines the values of the target location with the values from the patch. If the target location doesn't exist, it is created.\nstrategic:specific to Kubernetes and understands the structure of Kubernetes objects. It can handle complex changes like updating lists and maps, as well as preserving default values. However, it's not supported for custom resources. For custom resources, only JSON Patch and Merge Patch are typically supported.\nremove: Removes a value.\ncopy: Copies a value from one location to another.\nmove: Moves a value from one location to another.\ntest: Tests that a value at the target location is equal to a specified value." + "$comment": "Array Indexing: When working with arrays, be aware that Kubernetes uses zero-based indexing in JSON patch paths.\nMerge Patch vs. JSON Patch: Merge patches are less flexible than JSON patches and do not support all the same operations.\nStrategic Merge Patch: For some Kubernetes resources, you can also use the strategic type for a strategic merge patch, which understands the structure of Kubernetes objects and can handle complex operations." "type": "string", "enum": [ - "replace" + "replace", + "merge", + "strategic", + "add", + "remove", + "copy", + "move", + "test" ] } } From 0c3ba5dd4aba481e66beb6c29cf057e0c3b62f39 Mon Sep 17 00:00:00 2001 From: Mohd Uzair Date: Sat, 3 Aug 2024 17:01:04 +0530 Subject: [PATCH 3/5] Apply suggestions from code review Signed-off-by: Mohd Uzair --- schemas/constructs/v1alpha3/selectors.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schemas/constructs/v1alpha3/selectors.json b/schemas/constructs/v1alpha3/selectors.json index 662ed91946..a564954dd2 100644 --- a/schemas/constructs/v1alpha3/selectors.json +++ b/schemas/constructs/v1alpha3/selectors.json @@ -54,7 +54,7 @@ "$comment": "Array Indexing: When working with arrays, be aware that Kubernetes uses zero-based indexing in JSON patch paths.\nMerge Patch vs. JSON Patch: Merge patches are less flexible than JSON patches and do not support all the same operations.\nStrategic Merge Patch: For some Kubernetes resources, you can also use the strategic type for a strategic merge patch, which understands the structure of Kubernetes objects and can handle complex operations." "type": "string", "enum": [ - "replace", + "merge", "strategic", "add", @@ -110,7 +110,7 @@ "selectors": { "type": "array", "description": "Selectors are organized as an array, with each item containing a distinct set of selectors that share a common functionality. This structure allows for flexibility in defining relationships, even when different components are involved.", - "$comment": "Sets of selectors are interpreted as a logical OR. Properties within a selector are interpreted as a logical OR, while the `allow` and `deny` properties are interpreted a logical AND.", + "$comment": "Sets of selectors are interpreted as a logical UNION. Properties within a selector `allow` and `deny` are interpreted as logical AND, while 'from' and 'to' represents a UNION of set of combinatorial pairs.", "items": { "type": "object", "description": "Optional selectors used to match Components. Absence of a selector means that it is applied to all Components.", From 2416dacb5aac3d71620ded7fc24b915a7fb8d3e1 Mon Sep 17 00:00:00 2001 From: Mohd Uzair Date: Sat, 3 Aug 2024 17:05:39 +0530 Subject: [PATCH 4/5] add default patchStrategy value. Signed-off-by: Mohd Uzair --- schemas/constructs/v1alpha3/selectors.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/schemas/constructs/v1alpha3/selectors.json b/schemas/constructs/v1alpha3/selectors.json index a564954dd2..a30ce81305 100644 --- a/schemas/constructs/v1alpha3/selectors.json +++ b/schemas/constructs/v1alpha3/selectors.json @@ -50,11 +50,10 @@ { "properties": { "patchStrategy": { - "description": "patchStrategy allows you to make specific changes to a resource using a standard JSON Patch format (RFC 6902). \n\nadd: Inserts a value into an array or adds a member to an object.\nreplace: Replaces a value.\nmerge: Combines the values of the target location with the values from the patch. If the target location doesn't exist, it is created.\nstrategic:specific to Kubernetes and understands the structure of Kubernetes objects. It can handle complex changes like updating lists and maps, as well as preserving default values. However, it's not supported for custom resources. For custom resources, only JSON Patch and Merge Patch are typically supported.\nremove: Removes a value.\ncopy: Copies a value from one location to another.\nmove: Moves a value from one location to another.\ntest: Tests that a value at the target location is equal to a specified value." + "description": "patchStrategy allows you to make specific changes to a resource using a standard JSON Patch format (RFC 6902). \n\nadd: Inserts a value into an array or adds a member to an object.\nreplace: Replaces a value.\nmerge: Combines the values of the target location with the values from the patch. If the target location doesn't exist, it is created.\nstrategic:specific to Kubernetes and understands the structure of Kubernetes objects. It can handle complex changes like updating lists and maps, as well as preserving default values. However, it's not supported for custom resources. For custom resources, only JSON Patch and Merge Patch are typically supported.\nremove: Removes a value.\ncopy: Copies a value from one location to another.\nmove: Moves a value from one location to another.\ntest: Tests that a value at the target location is equal to a specified value." "$comment": "Array Indexing: When working with arrays, be aware that Kubernetes uses zero-based indexing in JSON patch paths.\nMerge Patch vs. JSON Patch: Merge patches are less flexible than JSON patches and do not support all the same operations.\nStrategic Merge Patch: For some Kubernetes resources, you can also use the strategic type for a strategic merge patch, which understands the structure of Kubernetes objects and can handle complex operations." "type": "string", - "enum": [ - + "enum": [ "merge", "strategic", "add", @@ -62,7 +61,8 @@ "copy", "move", "test" - ] + ], + "default": "add" } } }, @@ -155,4 +155,4 @@ } } } -} \ No newline at end of file +} From db2a1c1ecf8b568569ab5bf696390d6c6c064e16 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Mon, 5 Aug 2024 12:54:38 +0530 Subject: [PATCH 5/5] fix schema Signed-off-by: MUzairS15 --- schemas/constructs/v1alpha3/selectors.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schemas/constructs/v1alpha3/selectors.json b/schemas/constructs/v1alpha3/selectors.json index a30ce81305..69d475a533 100644 --- a/schemas/constructs/v1alpha3/selectors.json +++ b/schemas/constructs/v1alpha3/selectors.json @@ -50,8 +50,8 @@ { "properties": { "patchStrategy": { - "description": "patchStrategy allows you to make specific changes to a resource using a standard JSON Patch format (RFC 6902). \n\nadd: Inserts a value into an array or adds a member to an object.\nreplace: Replaces a value.\nmerge: Combines the values of the target location with the values from the patch. If the target location doesn't exist, it is created.\nstrategic:specific to Kubernetes and understands the structure of Kubernetes objects. It can handle complex changes like updating lists and maps, as well as preserving default values. However, it's not supported for custom resources. For custom resources, only JSON Patch and Merge Patch are typically supported.\nremove: Removes a value.\ncopy: Copies a value from one location to another.\nmove: Moves a value from one location to another.\ntest: Tests that a value at the target location is equal to a specified value." - "$comment": "Array Indexing: When working with arrays, be aware that Kubernetes uses zero-based indexing in JSON patch paths.\nMerge Patch vs. JSON Patch: Merge patches are less flexible than JSON patches and do not support all the same operations.\nStrategic Merge Patch: For some Kubernetes resources, you can also use the strategic type for a strategic merge patch, which understands the structure of Kubernetes objects and can handle complex operations." + "description": "patchStrategy allows you to make specific changes to a resource using a standard JSON Patch format (RFC 6902). \n\nadd: Inserts a value into an array or adds a member to an object.\nreplace: Replaces a value.\nmerge: Combines the values of the target location with the values from the patch. If the target location doesn't exist, it is created.\nstrategic:specific to Kubernetes and understands the structure of Kubernetes objects. It can handle complex changes like updating lists and maps, as well as preserving default values. However, it's not supported for custom resources. For custom resources, only JSON Patch and Merge Patch are typically supported.\nremove: Removes a value.\ncopy: Copies a value from one location to another.\nmove: Moves a value from one location to another.\ntest: Tests that a value at the target location is equal to a specified value.", + "$comment": "Array Indexing: When working with arrays, be aware that Kubernetes uses zero-based indexing in JSON patch paths.\nMerge Patch vs. JSON Patch: Merge patches are less flexible than JSON patches and do not support all the same operations.\nStrategic Merge Patch: For some Kubernetes resources, you can also use the strategic type for a strategic merge patch, which understands the structure of Kubernetes objects and can handle complex operations.", "type": "string", "enum": [ "merge",