From f8c080f2647062edcf651d551f57455a9e493eb5 Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Mon, 14 Feb 2022 12:00:15 -0500 Subject: [PATCH 01/12] Create rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 138 +++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 rfc/rfc-0000-match-params.md diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md new file mode 100644 index 000000000..a01cf5f79 --- /dev/null +++ b/rfc/rfc-0000-match-params.md @@ -0,0 +1,138 @@ +# Meta +[meta]: #meta +- Name: Match params in field selector +- Start Date: 2022-02-14 +- Author(s): @jwntrs +- Status: Draft +- RFC Pull Request: +- Supersedes: N/A + +# Summary +[summary]: #summary + +The [template switching RFC](https://github.com/vmware-tanzu/cartographer/pull/75) introduced the ability to match templates based on fields in the workload. However matching on params is not well defined. It is currently not possible to match on a field in the supply chain, and matching on fields in the workload is complex. You would need to define something as follows: + +```yaml + selector: + matchFields: + - key: workload.spec.params[name == promotion].value #< ===== does this even work? + operator: In + values: ["gitops"] +``` + +Lets introduce a top level params key: + +```yaml + selector: + matchFields: + - key: params.promotion #< ===== use something like this instead + operator: In + values: ["gitops"] +``` + + +# Motivation +[motivation]: #motivation + +We should be able to match against supply chain params in our field selectors. + +# What it is +[what-it-is]: #what-it-is + +```yaml +apiVersion: kontinue.io/v1alpha1 +kind: ClusterSupplyChain +metadata: + name: responsible-ops +spec: + selector: + app: web + params: + - name: promotion #< ===== params can be set here + value: (gitops|regops) + resources: + ... + - name: promote + templateRef: + kind: ClusterTemplate + options: + - name: git-promotion + selector: + matchFields: + - key: params.promotion #< ===== introduce top level `params` that relies on our param hierarchy + operator: In + values: ["gitops"] + - name: registry-promotion + selector: + matchFields: + - key: params.promotion + operator: In + values: ["regops"] + +--- +apiVersion: kontinue.io/v1alpha1 +kind: Workload +metadata: + name: petclinic + labels: + app: web +spec: + params: + - name: promotion #< ===== params can also be set here + value: (gitops|regops) + source: + git: + url: https://github.com/spring-projects/spring-petclinic.git + ref: + branch: main +``` + +# How it Works +[how-it-works]: #how-it-works + +Compute the available params from the workload and supply chain based on the [param hierarchy](https://cartographer.sh/docs/v0.2.0/architecture/#parameter-hierarchy) and pass it to the field matcher as `params`. + +# Migration +[migration]: #migration + +N/A + +# Drawbacks +[drawbacks]: #drawbacks + +Ultimately we want our template `selector` and top-level supply chain `selector` to work the same. However, if we introduce params into the matching context, then it would cause some divergence in these two cases. + +The top level selector we only have access to params defined in the workload. + +The template selectors would have access to params from the workload as well as the supply chain. + +Neither selector would have access to params from the templates. + + +# Alternatives +[alternatives]: #alternatives + +??? + +# Prior Art +[prior-art]: #prior-art + +??? + +# Unresolved Questions +[unresolved-questions]: #unresolved-questions + +??? + +# Spec. Changes (OPTIONAL) +[spec-changes]: #spec-changes + +```yaml + selector: + matchFields: + - key: params.promotion #< =================== introduce top level `params` + operator: In + values: ["gitops"] +``` + + From cf6e95b6d19acf88572ac98e88a50c30c6d0301d Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Tue, 15 Feb 2022 09:29:24 -0500 Subject: [PATCH 02/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index a01cf5f79..2837beb5c 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -15,7 +15,7 @@ The [template switching RFC](https://github.com/vmware-tanzu/cartographer/pull/7 ```yaml selector: matchFields: - - key: workload.spec.params[name == promotion].value #< ===== does this even work? + - key: workload.spec.params[?(@.name=="promotion")].value #< ===== not so nice operator: In values: ["gitops"] ``` From 1e5b89b95e90c09da7fcf41158bf1523ebcfdd60 Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:16:00 -0500 Subject: [PATCH 03/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index 2837beb5c..7de960b9b 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -15,7 +15,7 @@ The [template switching RFC](https://github.com/vmware-tanzu/cartographer/pull/7 ```yaml selector: matchFields: - - key: workload.spec.params[?(@.name=="promotion")].value #< ===== not so nice + - key: workload.spec.params[?(@.name=="promotion")].default #< ===== not so nice operator: In values: ["gitops"] ``` @@ -49,7 +49,7 @@ spec: app: web params: - name: promotion #< ===== params can be set here - value: (gitops|regops) + default: (gitops|regops) resources: ... - name: promote From 9408cd4688e13094ab01615e3808b10cf19d0651 Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:16:40 -0500 Subject: [PATCH 04/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index 7de960b9b..2a1d7f821 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -48,7 +48,7 @@ spec: selector: app: web params: - - name: promotion #< ===== params can be set here + - name: promotion #< ===== default params can be set here default: (gitops|regops) resources: ... @@ -78,7 +78,7 @@ metadata: app: web spec: params: - - name: promotion #< ===== params can also be set here + - name: promotion #< ===== params can be overriden here value: (gitops|regops) source: git: From 72b1eccf75ba1e9181fa1140d8912edf7996b92b Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:17:57 -0500 Subject: [PATCH 05/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index 2a1d7f821..26a048e2e 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -15,7 +15,7 @@ The [template switching RFC](https://github.com/vmware-tanzu/cartographer/pull/7 ```yaml selector: matchFields: - - key: workload.spec.params[?(@.name=="promotion")].default #< ===== not so nice + - key: workload.spec.params[?(@.name=="promotion")].value #< ===== not so nice operator: In values: ["gitops"] ``` From d037ce4847f559c47bb299e618ff2639ce5266a4 Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:18:41 -0500 Subject: [PATCH 06/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index 26a048e2e..3430502ad 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -34,7 +34,7 @@ Lets introduce a top level params key: # Motivation [motivation]: #motivation -We should be able to match against supply chain params in our field selectors. +We should be able to match against default supply chain params in our field selectors. # What it is [what-it-is]: #what-it-is From 4ae95c4126f64eb3d79b4908bae2aeccd6e0f2ff Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:28:50 -0500 Subject: [PATCH 07/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index 3430502ad..4c86495ca 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -1,6 +1,6 @@ # Meta [meta]: #meta -- Name: Match params in field selector +- Name: Add matchParams selector - Start Date: 2022-02-14 - Author(s): @jwntrs - Status: Draft @@ -20,12 +20,12 @@ The [template switching RFC](https://github.com/vmware-tanzu/cartographer/pull/7 values: ["gitops"] ``` -Lets introduce a top level params key: +Lets introduce a matchParams selector: ```yaml selector: - matchFields: - - key: params.promotion #< ===== use something like this instead + matchParams: #< ===== use something like this instead + - key: promotion operator: In values: ["gitops"] ``` @@ -58,14 +58,14 @@ spec: options: - name: git-promotion selector: - matchFields: - - key: params.promotion #< ===== introduce top level `params` that relies on our param hierarchy + matchParams: #< ===== introduce `matchParams` selector (uses param hierarchy) + - key: promotion operator: In values: ["gitops"] - name: registry-promotion selector: - matchFields: - - key: params.promotion + matchParams: + - key: promotion operator: In values: ["regops"] @@ -90,7 +90,7 @@ spec: # How it Works [how-it-works]: #how-it-works -Compute the available params from the workload and supply chain based on the [param hierarchy](https://cartographer.sh/docs/v0.2.0/architecture/#parameter-hierarchy) and pass it to the field matcher as `params`. +Compute the available params from the workload and supply chain based on the [param hierarchy](https://cartographer.sh/docs/v0.2.0/architecture/#parameter-hierarchy) and pass it to the params matcher. # Migration [migration]: #migration @@ -100,11 +100,11 @@ N/A # Drawbacks [drawbacks]: #drawbacks -Ultimately we want our template `selector` and top-level supply chain `selector` to work the same. However, if we introduce params into the matching context, then it would cause some divergence in these two cases. +Ultimately we want our template `selector` and top-level supply chain `selector` to work the same. However, if we introduce a matchParams selector, then it would cause some divergence in these two cases. -The top level selector we only have access to params defined in the workload. +The top level selector only has access to params defined in the workload. -The template selectors would have access to params from the workload as well as the supply chain. +The template selectors would have access to params from the workload as well as default values from the supply chain. Neither selector would have access to params from the templates. @@ -129,8 +129,8 @@ Neither selector would have access to params from the templates. ```yaml selector: - matchFields: - - key: params.promotion #< =================== introduce top level `params` + matchParams: + - key: promotion #< =================== introduce top level `params` operator: In values: ["gitops"] ``` From 417552ccc16ce34278250ec80687274f59f6a9bd Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:29:46 -0500 Subject: [PATCH 08/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index 4c86495ca..044474d16 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -129,8 +129,8 @@ Neither selector would have access to params from the templates. ```yaml selector: - matchParams: - - key: promotion #< =================== introduce top level `params` + matchParams: #< =================== introduce `matchParams` selector + - key: promotion operator: In values: ["gitops"] ``` From aa321f81fe535b67eee22af60848a56664eefc78 Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:35:59 -0500 Subject: [PATCH 09/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index 044474d16..b908083c4 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -20,7 +20,7 @@ The [template switching RFC](https://github.com/vmware-tanzu/cartographer/pull/7 values: ["gitops"] ``` -Lets introduce a matchParams selector: +Lets introduce a matchParams selector to the template, as well as the top level blueprint: ```yaml selector: From f9defcaa8e50f87204c6a954ff06617484ee0768 Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Sat, 19 Feb 2022 07:37:34 -0500 Subject: [PATCH 10/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index b908083c4..cc99887b6 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -20,7 +20,7 @@ The [template switching RFC](https://github.com/vmware-tanzu/cartographer/pull/7 values: ["gitops"] ``` -Lets introduce a matchParams selector to the template, as well as the top level blueprint: +Lets introduce a matchParams selector: ```yaml selector: @@ -47,6 +47,7 @@ metadata: spec: selector: app: web + params: - name: promotion #< ===== default params can be set here default: (gitops|regops) From 0708f9de25e6b8b47b9666782e427b65473f8fa4 Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Tue, 22 Feb 2022 10:54:27 -0500 Subject: [PATCH 11/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index cc99887b6..b80d27f24 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -34,7 +34,7 @@ Lets introduce a matchParams selector: # Motivation [motivation]: #motivation -We should be able to match against default supply chain params in our field selectors. +We should be able to match against default supply chain params in our field selectors, and provide a simpler syntax for matching against workload params. # What it is [what-it-is]: #what-it-is @@ -46,8 +46,13 @@ metadata: name: responsible-ops spec: selector: - app: web - + matchLabels: + app: web + matchParams: #< ===== convenience matcher for workload params + - key: language + operator: In + values: ["java"] + params: - name: promotion #< ===== default params can be set here default: (gitops|regops) From c557c5d7291b3801941cc7e95d5deb16f1005a1b Mon Sep 17 00:00:00 2001 From: Joshua Winters Date: Tue, 22 Feb 2022 10:56:47 -0500 Subject: [PATCH 12/12] Update rfc-0000-match-params.md --- rfc/rfc-0000-match-params.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rfc/rfc-0000-match-params.md b/rfc/rfc-0000-match-params.md index b80d27f24..a05d43d99 100644 --- a/rfc/rfc-0000-match-params.md +++ b/rfc/rfc-0000-match-params.md @@ -48,7 +48,7 @@ spec: selector: matchLabels: app: web - matchParams: #< ===== convenience matcher for workload params + matchParams: #< ===== introduce convenience matcher for workload params - key: language operator: In values: ["java"] @@ -101,7 +101,7 @@ Compute the available params from the workload and supply chain based on the [pa # Migration [migration]: #migration -N/A +For the top level `matchParams` selector, this assumes we've already migrated the top level selector to use `matchLabels`. # Drawbacks [drawbacks]: #drawbacks @@ -135,7 +135,7 @@ Neither selector would have access to params from the templates. ```yaml selector: - matchParams: #< =================== introduce `matchParams` selector + matchParams: #< =================== introduce `matchParams` selector for templates and top level selector - key: promotion operator: In values: ["gitops"]