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

Fix handling of CRD YAML containing implicit block mappings #7

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ jobs:
values: |
fullnameOverride: prometheus-k8s
cleanPrometheusOperatorObjectNames: true

- name: 'Install a chart that has that use YAML implicit block mappings'
uses: './'
with:
release: 'clickhouse-operator'
namespace: 'clickhouse-operator'
chart: 'altinity-clickhouse-operator'
repo: https://docs.altinity.com/clickhouse-operator
version: 0.20.3
# needed to test CRD extraction logic for CRDs containing YAML implicit block mappings
upgrade-crds: true
43 changes: 25 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ function getInput(name, options) {
return val;
}

async function extractCRDs(chart, version, repo) {
const templateArgs = [
'template',
chart,
'--dependency-update',
'--include-crds',
];
if (version) {
templateArgs.push(`--version=${version}`);
}
if (repo) {
templateArgs.push(`--repo=${repo}`);
}
let crds = [];
const output = await exec.getExecOutput('helm', templateArgs, {silent: true});
yaml.loadAll(output.stdout, doc => {
if (doc && doc.kind == 'CustomResourceDefinition') {
core.debug(`found CRD ${doc.metadata.name}`);
crds.push(doc);
}
});
return crds;
}

/**
* Run executes the helm deployment.
*/
Expand Down Expand Up @@ -92,21 +116,11 @@ async function run() {
`--namespace=${namespace}`,
];

// Used for upgradeCRDs
const templateArgs = [
'template',
chart,
'--dependency-update',
'--include-crds',
];

if (version) {
args.push(`--version=${version}`);
templateArgs.push(`--version=${version}`);
}
if (repo) {
args.push(`--repo=${repo}`);
templateArgs.push(`--repo=${repo}`);
}
if (timeout) {
args.push(`--timeout=${timeout}`);
Expand All @@ -128,14 +142,7 @@ async function run() {
// to just the CRDs.
// Output the CRDs to a new file and then kubectl apply them.
if (upgradeCRDs) {
let crds = [];
const output = await exec.getExecOutput('helm', templateArgs, {silent: true});
yaml.loadAll(output.stdout, doc => {
if (doc && doc.kind == 'CustomResourceDefinition') {
core.debug(`found CRD ${doc.metadata.name}`);
crds.push(doc);
}
});
const crds = await extractCRDs(chart, version, repo);
if (crds.length != 0) {
const crdsFile = `${outputsDir}/crds.yml`;
const crdsYAML = yamlDumpAll(crds);
Expand Down
4 changes: 2 additions & 2 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading