cdk8s-team / cdk8s

Define Kubernetes native apps and abstractions using object-oriented programming
https://cdk8s.io
Apache License 2.0
4.29k stars 290 forks source link

cdk8s dasm: convert a yaml manifest to a cdk8s chart #141

Open eladb opened 4 years ago

eladb commented 4 years ago

We propose a new command called cdk8s dasm that will take a k8s yaml as input and will generate code (in one of the supported programming languages) which will synthesize the same manifest output (as much as possible).

It's nice way to migrate from manifests to cdk8s.

See the cdk-dasm as an example.

carltonmason commented 4 years ago

This would be awesome feature!

pgollucci commented 4 years ago

Yes definitely this one. 👍

moises-perez-tfs commented 3 years ago

I was exploring to find a feature like this. Our use case is to automate the management (add, remove) of Identity Mappings in the aws-auth ConfigMap in EKS. Is this feature also going to be available in code (not just command) to enable automation?

iliapolo commented 3 years ago

@moises-perez-tfs We still don't have a concrete plan for this feature. Noted that it would be good to have it available via an API as well :)

github-actions[bot] commented 3 years ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

Chriscbr commented 3 years ago

Keep

Hunter-Thompson commented 3 years ago

I wrote a little something to help make this a bit easier. The following project can convert your YAML to an APIObject.

It uses kube2pulumi as a base.

https://github.com/smallcase/kube2cdk8s

eladb commented 3 years ago

@Hunter-Thompson very cool! Curious - why did you need to use kube2pulumi as a base?

Hunter-Thompson commented 3 years ago

@Hunter-Thompson very cool! Curious - why did you need to use kube2pulumi as a base?

I first convert it to a Pulumi object, then replace the Pulumi specific things with cdk8s specific declarations. Its a hack, but since both the API's are the same, it works :)

1st result :

import * as pulumi from "@pulumi/pulumi";
import * as kubernetes from "@pulumi/kubernetes";

const frontendNginxPod = new kubernetes.core.v1.Pod("frontendNginxPod", {
    apiVersion: "v1",
    kind: "Pod",
    metadata: {
        namespace: "frontend",
        name: "nginx",
    },
    spec: {
        containers: [{
            name: "nginx",
            image: "nginx:1.14-alpine",
            resources: {
                limits: {
                    memory: "20Mi",
                    cpu: 0.2,
                },
            },
        }],
    },
});

After parsing :

new k8s.KubePod(this, "nginx", {
    metadata: {
        namespace: "frontend",
        name: "nginx",
    },
    spec: {
        containers: [{
            name: "nginx",
            image: "nginx:1.14-alpine",
            resources: {
                limits: {
                    memory: "20Mi",
                    cpu: 0.2,
                },
            },
        }],
    },
});
github-actions[bot] commented 2 years ago

This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.

github-actions[bot] commented 2 years ago

Closing this issue as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen.

gkarthiks commented 2 years ago

I am working on some use cases that need to append resources regularly. I am using cdk8s on go language. Looking for this kind of feature on the code. Say, read an existing YAML manifest and append that with additional data and put it back. So that the GitOps Engine will look at the change and applies that on to the cluster.

Definitely a needed feature...

hemzaz commented 1 year ago

Waiting for this feature :)

jmreicha commented 1 year ago

Take it this is never going to happen now with the creator working on a different project?

iliapolo commented 1 year ago

@jmreicha

We don't currently have this on our immediate roadmap. There is third-party project that might help you out though: https://github.com/smallcase/kube2cdk8s

iliapolo commented 1 year ago

For those interested in this in order to augment existing YAML manifests with resources defined in code, have a look at the Include construct, which can help with that.