Skip to content

Instantly share code, notes, and snippets.

View pivotaljohn's full-sized avatar
💭
🌤

John S. Ryan pivotaljohn

💭
🌤
View GitHub Profile
@pivotaljohn
pivotaljohn / path_to_yaml.yaml
Last active August 1, 2022 22:26
From a dot-path notation to a YAML structure.
#@ load("@ytt:yaml", "yaml")
#@ load("@ytt:regexp", "regexp")
#@ load("@ytt:overlay", "overlay")
#@ def as_dict(parts, leaf):
#@ if len(parts) == 0:
#@ return leaf
#@ end
#@ return {parts[0]: as_dict(parts[1:], leaf)}
#@ end
@pivotaljohn
pivotaljohn / template.yml
Last active July 19, 2022 16:46
Post-processing Data Values
#@ load("@ytt:data", "data")
#@ load("@ytt:yaml", "yaml")
#@ load("@ytt:struct", "struct")
#@ profiles = struct.make(full="full", is_any_enabled=lambda p: False)
#@ def grypeValues(grype):
#@ newGrype = yaml.decode(yaml.encode(grype))
#@
#@ if not profiles.is_any_enabled([profiles.full]) and not "metadataStore" in newGrype:
@pivotaljohn
pivotaljohn / existing-config.yml
Last active July 14, 2022 21:36
Overlaying a variety of kinds of resources
apiVersion: apps/v1
kind: Deployment
metadata:
name: foodb
namespace: knative-serving
labels:
app.kubernetes.io/name: knative-serving
app.kubernetes.io/version: 1.0
app.kubernetes.io/component: database
spec: {}
@pivotaljohn
pivotaljohn / config.yml
Last active June 30, 2022 14:40
Transform flat keyset into a list
#@ load("@ytt:data", "data")
#@ load("parse-input.star", "fruit_from_struct")
---
fruits: #@ fruit_from_struct(data.values)
@pivotaljohn
pivotaljohn / config.yml
Created June 30, 2022 13:59
Insert options for an array, when it exists.
#@ load("@ytt:data", "data")
--- #@ data.values
@pivotaljohn
pivotaljohn / .gitlab-ci.yml
Last active June 14, 2022 22:22
Native ytt equivalent of GitLab's !reference
#! .gitlab-ci.yml
#@ load("@ytt:template", "template")
#@ load("helpers.lib.yaml", "setup", "teardown")
test:
script:
- #@ template.replace(setup())
- echo running my own command
- #@ template.replace(teardown())
@pivotaljohn
pivotaljohn / config.yml
Created May 22, 2022 16:23
Using an overlay within an overlay
---
vlans:
- vlan-id: 10
- vlan-id: 20
- vlan-id: 30
some_other_configuration: #! some other config here
@pivotaljohn
pivotaljohn / config.yml
Last active May 22, 2022 15:34
Replacing an array item (rather than appending)
kind: SecretProviderClass
metadata:
namespace: default
name: db_credentials
spec:
provider: aws
parameters:
objects: |
- objectName: TO_BE_REPLACED_BY_YTT
objectType: "secretsmanager"
@pivotaljohn
pivotaljohn / images-tmpl.yml
Last active April 25, 2022 22:03
Using the example as the default contents of an array.
#@ load("@ytt:data", "data")
#@ def get_package_repository(repository_name, package_name):
#@ if repository_name == "":
#@ for repository in data.values.repositories:
#@ for package in data.values.repositories[repository].packages:
#@ if package.name == package_name:
#@ return data.values.repositories[repository]
#@ end
#@ end
@pivotaljohn
pivotaljohn / config.yaml
Created April 20, 2022 15:49
Extracting environment variable-set config for a Backstage app.
#@ load("@ytt:data", "data")
#@ def removeprefix(prefix, s):
#@ return s[len(prefix):] if s.startswith(prefix) else s
#@ end
#@ def config_key_for(auth_var_expr):
#@ var_name_parts = \
#@ removeprefix("..._", auth_var_expr) \
#@ .split("_")