cdk8s-team/cdk8s-plus

HPA - Typescript - Maximum call stack size exceeded

segal90 opened this issue · 2 comments

With the following code HPA got stuck in infinite recursion:

const app = new App();
const chart = new Chart(app, 'test', {namespace: 'test'});
const deployment = new Deployment(chart, 'deployment');
const volumeMounts = [{ volume: Volume.fromEmptyDir(deployment, 'test-volume','test'), path: './test'}];

deployment.addContainer({
  image: 'ubuntu',
  name: 'test',
  volumeMounts,
});

new HorizontalPodAutoscaler(chart, 'HPA', {
  target: deployment,
  maxReplicas: 5,
});
app.synth();

error message:

(node:1258041) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
    at Function.[Symbol.hasInstance] (<anonymous>)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:10:12)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at resolve (/home/<strip>/node_modules/cdk8s/src/_resolve.ts:32:17)
    at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
    at processPromiseRejections (internal/process/promises.js:247:11)
    at processTicksAndRejections (internal/process/task_queues.js:96:32)

Without volumeMounts it works perfectly.

Taking a look at this. It seems like it might be something in our packaging process. I'm able to reproduce this when using cdk8s+ from NPM but when building & linking cdk8s-plus repo locally it's successful.

Reproduction here: https://github.com/ryparker/cdk8s-hpa-max-call-stack-error

It seems to me like a circular dependency on use of Lazy.any(). I'm still not sure why yarn linking the actual repo doesn't produce the error.