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

Chart.apiObjects doesn't include Helm, Include generated resources. #2258

Open
shinebayar-g opened this issue Nov 18, 2024 · 1 comment
Open
Labels
bug Something isn't working needs-triage Priority and effort undetermined yet

Comments

@shinebayar-g
Copy link

Description of the bug:

I noticed that my code was buggy because Chart.apiObjects didn't include Helm and Include resources.

Reproduction Steps:

import { App, Chart, Helm, Include } from 'cdk8s';
import { KubeNamespace } from './imports/k8s';

async function main() {
    const app = new App();
    const chart = new Chart(app, 'foo');

    new KubeNamespace(chart, 'ns', {
        metadata: {
            name: 'foo',
        },
    });

    const helm = new Helm(chart, 'chart', {
        repo: 'https://grafana.github.io/helm-charts',
        chart: 'alloy',
        releaseName: 'alloy',
        version: '0.10.0',
        namespace: 'foo',
    });

    const i = new Include(chart, 'include', {
        url: 'https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/refs/heads/main/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml',
    });

    // apiObjects only works when used as a direct reference.
    i.apiObjects.forEach((apiObject) => {
        console.warn('include kind:', apiObject.kind);
    });

    // apiObjects only works when used as a direct reference.
    helm.apiObjects.forEach((apiObject) => {
        console.warn('helm kind:', apiObject.kind);
    });

    // Only prints
    // chart kind: Namespace
    //  - foo/foo.k8s.yaml
    chart.apiObjects.forEach((apiObject) => {
        console.warn('chart kind:', apiObject.kind);
    });

    app.synth();
}

main();

Error Log:

Environment:

  • Framework Version:
  • OS:

Other:


This is 🐛 Bug Report

@shinebayar-g shinebayar-g added bug Something isn't working needs-triage Priority and effort undetermined yet labels Nov 18, 2024
@shinebayar-g
Copy link
Author

I think it kind of makes sense that apiObjects wouldn't return Helm, Include types because they're not ApiObject type..

I could use something like this, but it doesn't work.

chart.node.children.forEach((child) => {
  // But I can't do
  child.node.apiObjects
});

Fortunately I found out about this property exists child.node.host and it actually contains what I needed. But it's not defined in the typescript.

So it's turning out to be more like a feature request: How to iterate through all of the children's apiObjects recursively?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Priority and effort undetermined yet
Projects
None yet
Development

No branches or pull requests

1 participant