Skip to content

Commit

Permalink
Merge pull request #117 from MUzairS15/MUzairS15/selectors
Browse files Browse the repository at this point in the history
extract selectors
  • Loading branch information
Mohd Uzair authored Aug 5, 2024
2 parents 1fc3002 + db2a1c1 commit a57345c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 100 deletions.
38 changes: 1 addition & 37 deletions schemas/constructs/v1alpha3/relationship.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,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"
}
}
}
Expand Down
149 changes: 86 additions & 63 deletions schemas/constructs/v1alpha3/selectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +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": {
"from": {
"selector": {
"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",
Expand Down Expand Up @@ -45,91 +46,113 @@
},
"patch": {
"type": "object",
"additionalProperties": false,
"properties": {
"patchStrategy": {
"type": "string",
"enum": [
"replace"
]
"allOf": [
{
"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": [
"merge",
"strategic",
"add",
"remove",
"copy",
"move",
"test"
],
"default": "add"
}
}
},
"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 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.",
"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."
}
}
}
}
}
}

0 comments on commit a57345c

Please sign in to comment.