---
# System prepended metadata

title: yq/jq formula examples
tags: [fbc]

---

---
tags: fbc
title: yq/jq formula examples
---
# yq/jq formula examples
This document represents an attempt to collect the various use-cases we want to help operator authors achieve when releasing a new bundle version and updating catalog templates / FBC. These would be things that an author could automate as part of their bundle release process to provide bundle-publish...catalog-publish automation. 
Some are already filled in, but the TODO section captures the remaining cases. 

------

### TODO use-cases
1. [x] adding a `replaces` link between two versions on the same channel (worth having multiple examples to illustrate how it could have different ordering in different channels?)
2. removing all the bundle versions from an upgrade graph below a threshold (NB: does not include removing now-empty channels)
3. modifying a property of a bundle in the rendered FBC
4. [x] adding a property to a bundle version in the rendered FBC
```bash
   yq eval 'select(.name == "testoperator.v0.2.1" and .schema == "olm.bundle").properties += [{"type" : "olm.deprecated", "value" : "true"}]' -i  catalog.yaml
```

5. [x] in-place substitution of a bundle version (the CVE freshmaker problem) in the upgrade graph
-- for e.g. replacing the `replaces` value for a given, existing bundle version (opentelemetry-operator.v0.75.0) with a different target "foo"
```bash
yq eval 'select(.schema=="olm.channel" and .name == "alpha") as $channel | $channel.entries[] | select(.name == "opentelemetry-operator.v0.75.0") |= {"name" : .name, "replaces": "foo"} ' /tmp/example.yaml
```
6. 

------


#### converting SQLite catalog to `basic template`:
(captured in upstream docs also [here](https://github.com/operator-framework/operator-registry/pull/1082/files#diff-0299f965ef1d5dc96c54539eccbbcbf7a35e5f38255886bcbb6f8c39edf3364fR572-R583))
```bash!
opm render <catalogRef> -o yaml | yq eval -i 'select(.schema == "olm.bundle") = {"schema": .schema, "image": .image}' test.yaml - test.yaml
```

### adding new bundle to existing channel 

##### `semver template` add new v1.2.3 bundle to `candidates` channel archetype:

```bash!
yq eval '.candidate.bundles += [{"image" : "quay.io/exampleowner/exampleoperator:v1.2.3"}]'
```

```yaml=
schema: olm.semver
generatemajorchannels: true
generateminorchannels: true
candidate:
  bundles:
    - image: quay.io/exampleowner/exampleoperator:v0.1.0
    - image: quay.io/exampleowner/exampleoperator:v0.1.1
    - image: quay.io/exampleowner/exampleoperator:v0.1.2
    - image: quay.io/exampleowner/exampleoperator:v0.3.0
    - image: quay.io/exampleowner/exampleoperator:v1.0.0
    - image: quay.io/exampleowner/exampleoperator:v1.0.1
    - image: quay.io/exampleowner/exampleoperator:v1.1.0
    - image: quay.io/exampleowner/exampleoperator:v0.1.3
    - image: quay.io/exampleowner/exampleoperator:v0.2.0
    - image: quay.io/exampleowner/exampleoperator:v0.2.1
    - image: quay.io/exampleowner/exampleoperator:v0.2.2
    - image: quay.io/exampleowner/exampleoperator:v1.2.3
fast:
  bundles:
    - image: quay.io/exampleowner/exampleoperator:v0.2.1
    - image: quay.io/exampleowner/exampleoperator:v0.2.2
    - image: quay.io/exampleowner/exampleoperator:v0.3.0
    - image: quay.io/exampleowner/exampleoperator:v1.0.1
    - image: quay.io/exampleowner/exampleoperator:v1.1.0
stable:
  bundles:
    - image: quay.io/exampleowner/exampleoperator:v1.0.1
```

##### `basic template`/FBC add new `replaces` edge for a new v1.2.3 bundle from its predecessor version (both versions known):
```bash!
yq eval 'select(.schema == "olm.channel").entries += [{"name" : "exampleoperator:v1.2.3", "replaces": "exampleoperator:v0.2.0"}]'
```

```yaml=
---
schema: olm.package
name: exampleoperator
defaultChannel: stable
---
schema: olm.channel
package: exampleoperator
name: stable
entries:
  - name: exampleoperator:v0.1.0
  - name: exampleoperator:v0.2.0
    replaces: exampleoperator:v0.1.0
  - name: exampleoperator:v1.2.3
    replaces: exampleoperator:v0.2.0
---
schema: olm.bundle
image: quay.io/exampleowner/exampleoperator:v0.1.0
---
schema: olm.bundle
image: quay.io/exampleowner/exampleoperator:v0.2.0
```
