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

RFC: Add matchParams selector #618

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
138 changes: 138 additions & 0 deletions 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:
martyspiewak marked this conversation as resolved.
Show resolved Hide resolved

```yaml
selector:
matchFields:
- key: workload.spec.params[?(@.name=="promotion")].value #< ===== not so nice
jwntrs marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this example, the workload param would be ignored, as the value has been hard coded by the supply-chain author. Switch value to default to clarify that the workload param is allowed.

Suggested change
value: (gitops|regops)
default: (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"]
```