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

Add support to Deno #2171

Open
Alvise88 opened this issue May 13, 2022 · 4 comments
Open

Add support to Deno #2171

Alvise88 opened this issue May 13, 2022 · 4 comments
Labels
@component/cdk8s-core Issue related to cdk8s-core effort/large 1+ weeks feature-request New/Enhanced functionality wanted priority/p2 Dependent on community feedback. PR's are welcome :)

Comments

@Alvise88
Copy link

Even with the latest version of deno it doesn't seem possible to use cdk8s.

Deno: v1.21.3

import { Chart } from "https://esm.sh/cdk8s@2.2.85";
import {Construct} from "https://esm.sh/constructs@10.0.130";

class MyChart extends Chart {
  constructor(scope: Construct, ns: string) {
    super(scope, ns);

    // add contents here
  }
}

/**
 * hello-world.js
 */
function capitalize(word: string) {
  return word.charAt(0).toUpperCase() + word.slice(1);
}

function hello(name: string) {
  return "Hello " + capitalize(name);
}

console.log(hello("john"));
console.log(hello("Sarah"));
console.log(hello("kai"));

/**
 * Output:
 *
 * Hello John
 * Hello Sarah
 * Hello Kai
 */
deno --unstable run stack.ts
Uncaught SyntaxError: The requested module 'https://esm.sh/cdk8s@2.2.85' does not provide an export named 'Chart'
import { Chart } from "https://esm.sh/cdk8s@2.2.85";
@iliapolo iliapolo added feature-request New/Enhanced functionality wanted priority/p2 Dependent on community feedback. PR's are welcome :) effort/large 1+ weeks labels Sep 14, 2022
@y12studio
Copy link

It seems like recent version already support cdk8s and cdk8s+.

docker run -i --entrypoint sh docker.io/denoland/deno:1.30.3 <<\EOF
deno run -A - <<\EOOF
import * as kplus from 'npm:cdk8s-plus-25'
import * as cdk8s from 'npm:cdk8s'
const app = new cdk8s.App()
const chart = new cdk8s.Chart(app, 'ch101')
const deploy203 = new kplus.Deployment(chart, 'd203', {
    replicas: 2,
    containers: [
        { 
            image: 'nginx', 
            securityContext: { ensureNonRoot: false, readOnlyRootFilesystem: false}
        }
    ],
})
new kplus.Service(chart, 'srv987', {
        selector: deploy203, 
        ports: [ { port: 80, targetPort: 8080}]
    });
console.log(app.synthYaml())
EOOF
EOF

output

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ch101-d203-c886a9fd
spec:
  minReadySeconds: 0
  progressDeadlineSeconds: 600
  replicas: 2
  selector:
    matchLabels:
      cdk8s.io/metadata.addr: ch101-d203-c8cfa8e5
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        cdk8s.io/metadata.addr: ch101-d203-c8cfa8e5
    spec:
      automountServiceAccountToken: false
      containers:
        - image: nginx
          imagePullPolicy: Always
          name: main
          resources:
            limits:
              cpu: 1500m
              memory: 2048Mi
            requests:
              cpu: 1000m
              memory: 512Mi
          securityContext:
            allowPrivilegeEscalation: false
            privileged: false
            readOnlyRootFilesystem: false
            runAsNonRoot: false
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      securityContext:
        fsGroupChangePolicy: Always
        runAsNonRoot: true
      setHostnameAsFQDN: false
---
apiVersion: v1
kind: Service
metadata:
  name: ch101-srv987-c8aad50a
spec:
  externalIPs: []
  ports:
    - port: 80
      targetPort: 8080
  selector:
    cdk8s.io/metadata.addr: ch101-d203-c8cfa8e5
  type: ClusterIP

@shinebayar-g
Copy link

shinebayar-g commented Apr 5, 2023

I've been using cdk8s with Deno for a while now since they introduced npm support. Code itself runs fine, but there are some gaps. For example CLI installation npm install -g cdk8s-cli and cdk8s init typescript-app both assumes you're using NodeJS. But I don't see any technical difficulties supporting Deno at this point.

Edit:

Posting from slack for visibility.

cdk8s package itself was working fine for me. From #1978

# cdk8s.yaml:
language: typescript
app: deno run --allow-env --allow-write --allow-read main.ts
imports:
  - k8s

I believe deno equivalent of npx cdk8s synth is deno run --allow-env --allow-read npm:cdk8s-cli synth But I get this error.

Error: ENOENT: no such file or directory, readdir
    at __node_internal_captureLargerStackTrace (ext:deno_node/internal/errors.ts:91:11)
    at __node_internal_uvException (ext:deno_node/internal/errors.ts:184:12)
    at denoErrorToNodeError (ext:deno_node/internal/errors.ts:1845:16)
    at Object.readdirSync (ext:deno_node/_fs/_fs_readdir.ts:73:15)
....

So I still needed to use node/npm for cdk8s-cli

@rassie
Copy link

rassie commented Apr 25, 2023

I've no idea whether I'm doing something wrong, but even though a simple cdk8s examples work without a problem with Deno, I've stumbled upon the following with Helm:

error: Uncaught ReferenceError: require is not defined
const { http, https } = require('follow-redirects');

with error location being node_modules/.deno/cdk8s@2.7.56/node_modules/cdk8s/lib/_loadurl.js:8:25.

@shepherdjerred
Copy link

shepherdjerred commented Dec 14, 2024

I've been using cdk8s with Deno for quite a while in https://github.com/shepherdjerred/homelab/tree/main/cdk8s

A few points:

My deployment is fairly advanced. It uses many CRDs, Helm charts, and custom pod/deployment definitions. Here's an example manifest generated with cdk8s & deno: https://gist.github.com/shepherdjerred/ca123e870840ed190dbb294846f29f19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@component/cdk8s-core Issue related to cdk8s-core effort/large 1+ weeks feature-request New/Enhanced functionality wanted priority/p2 Dependent on community feedback. PR's are welcome :)
Projects
None yet
Development

No branches or pull requests

6 participants