{"id":13615461,"url":"https://github.com/PrasadG193/kyaml2go","last_synced_at":"2025-04-13T21:30:53.141Z","repository":{"id":43635505,"uuid":"205634476","full_name":"PrasadG193/kyaml2go","owner":"PrasadG193","description":"K8s Go client code generator from Kubernetes resource yamls","archived":false,"fork":false,"pushed_at":"2021-11-09T11:31:04.000Z","size":406,"stargazers_count":284,"open_issues_count":4,"forks_count":29,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T18:18:19.871Z","etag":null,"topics":["client-go","client-go-sample","code-generator","codegen","examples","go","go-client","k8s","kubernetes","kubernetes-resource-yamls"],"latest_commit_sha":null,"homepage":"https://kyaml2go.prasadg.dev","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PrasadG193.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-01T05:42:24.000Z","updated_at":"2025-01-13T04:36:20.000Z","dependencies_parsed_at":"2022-09-23T05:03:53.134Z","dependency_job_id":null,"html_url":"https://github.com/PrasadG193/kyaml2go","commit_stats":null,"previous_names":["prasadg193/kgoclient-gen"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrasadG193%2Fkyaml2go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrasadG193%2Fkyaml2go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrasadG193%2Fkyaml2go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrasadG193%2Fkyaml2go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PrasadG193","download_url":"https://codeload.github.com/PrasadG193/kyaml2go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248786034,"owners_count":21161386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-go","client-go-sample","code-generator","codegen","examples","go","go-client","k8s","kubernetes","kubernetes-resource-yamls"],"created_at":"2024-08-01T20:01:14.015Z","updated_at":"2025-04-13T21:30:53.101Z","avatar_url":"https://github.com/PrasadG193.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# kyaml2go \u003csub\u003e(Pronounced as camel2go :camel:)\u003c/sub\u003e\n\n[![Build Status](https://travis-ci.org/PrasadG193/kyaml2go.svg?branch=master)](https://travis-ci.org/PrasadG193/kyaml2go)\n\nhttps://kyaml2go.prasadg.dev\n\nGo client code generator from Kubernetes resource specs yaml\n\n![https://github.com/PrasadG193/kyaml2go](./k2go.png)\n\n## Supported resources\n\nList of supported Kinds and Groups can be found here: https://github.com/PrasadG193/kyaml2go/blob/master/pkg/kube/map.go#L38\n\nkyaml2go also supports Custom Resources compatible with client-go v0.18.5 dep\n\n## Installation\n\n### Docker\n\n```\ndocker run --rm -i ghcr.io/prasadg193/kyaml2go:latest create \u003c testdata/secrets.yaml\n```\n\n### Install From Source\n\n#### Step 1: Clone the repo\n\n```bash\n$ git clone https://github.com/PrasadG193/kyaml2go.git\n```\n\n#### Step 2: Build binary using make\n\n```bash\n$ make\n```\n\n\n## Usage\n\nkyaml2go is available at https://kyaml2go.prasadg.dev\n\nAlternatively, you can also use CLI or docker image to generate code\n\n```bash\n$ kyaml2go --help\nNAME:\n   kyaml2go - Generate go code to manage Kubernetes resources using go-client sdks\n\nUSAGE:\n   kyaml2go [global options] command [command options] [arguments...]\n\nVERSION:\n   0.0.0\n\nCOMMANDS:\n   create   Generate code for creating a resource\n   update   Generate code for updating a resource\n   get      Generate code to get a resource object\n   delete   Generate code for deleting a resource\n   help, h  Shows a list of commands or help for one command\n\nGLOBAL OPTIONS:\n   --help, -h     show help\n   --version, -v  print the version\n\n\n$ kyaml2go create --help\nNAME:\n   kyaml2go create - Generate code for creating a resource\n\nUSAGE:\n   kyaml2go create [command options] [arguments...]\n\nOPTIONS:\n   --cr                      Resource is a Custom resource\n   --apis value              Custom resource api def package (without version)\n   --client value, -c value  Custom resource typed client package name\n   --scheme value, -s value  Custom resource scheme package name\n```\n\n## Examples\n\n### Generating code for native resources\n\n```bash\n$ docker run --rm -i ghcr.io/prasadg193/kyaml2go:latest create \u003c testdata/secrets.yaml\n\n// Auto-generated by kyaml2go - https://github.com/PrasadG193/kyaml2go\npackage main\n\nimport (\n        \"context\"\n        \"fmt\"\n        corev1 \"k8s.io/api/core/v1\"\n        metav1 \"k8s.io/apimachinery/pkg/apis/meta/v1\"\n        clientset \"k8s.io/client-go/kubernetes\"\n        \"k8s.io/client-go/tools/clientcmd\"\n        \"k8s.io/client-go/util/homedir\"\n        \"os\"\n        \"path/filepath\"\n)\n\nfunc main() {\n        // Create client\n        var kubeconfig string\n        kubeconfig, ok := os.LookupEnv(\"KUBECONFIG\")\n        if !ok {\n                kubeconfig = filepath.Join(homedir.HomeDir(), \".kube\", \"config\")\n        }\n\n        config, err := clientcmd.BuildConfigFromFlags(\"\", kubeconfig)\n        if err != nil {\n                panic(err)\n        }\n        client, err := clientset.NewForConfig(config)\n        if err != nil {\n                panic(err)\n        }\n        kubeclient := client.CoreV1().Secrets(\"default\")\n\n        // Create resource object\n        object := \u0026corev1.Secret{\n                TypeMeta: metav1.TypeMeta{\n                        Kind:       \"Secret\",\n                        APIVersion: \"v1\",\n                },\n                ObjectMeta: metav1.ObjectMeta{\n                        Name: \"test-secret\",\n                },\n                StringData: map[string]string{\n                        \"password\": \"1f2d1e2e67df\",\n                        \"username\": \"admin\",\n                },\n                Type: corev1.SecretType(\"Opaque\"),\n        }\n\n        // Manage resource\n        _, err = kubeclient.Create(context.TODO(), object, metav1.CreateOptions{})\n        if err != nil {\n                panic(err)\n        }\n        fmt.Println(\"Secret Created successfully!\")\n}\n\n```\n\n### Generating code for custom resources\n\n```bash\n$ docker run --rm -i ghcr.io/prasadg193/kyaml2go:latest create --cr --scheme \"k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme\" --apis \"k8s.io/sample-controller/pkg/apis/samplecontroller\" --client \"k8s.io/sample-controller/pkg/generated/clientset/versioned\" \u003c testdata/crs/foo.yaml\n\n// Auto-generated by kyaml2go - https://github.com/PrasadG193/kyaml2go\npackage main\n\nimport (\n        \"context\"\n        \"fmt\"\n        metav1 \"k8s.io/apimachinery/pkg/apis/meta/v1\"\n        \"k8s.io/client-go/tools/clientcmd\"\n        \"k8s.io/client-go/util/homedir\"\n        samplecontrollerv1alpha1 \"k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1\"\n        clientset \"k8s.io/sample-controller/pkg/generated/clientset/versioned\"\n        \"os\"\n        \"path/filepath\"\n)\n\nfunc main() {\n        // Create client\n        var kubeconfig string\n        kubeconfig, ok := os.LookupEnv(\"KUBECONFIG\")\n        if !ok {\n                kubeconfig = filepath.Join(homedir.HomeDir(), \".kube\", \"config\")\n        }\n\n        config, err := clientcmd.BuildConfigFromFlags(\"\", kubeconfig)\n        if err != nil {\n                panic(err)\n        }\n        client, err := clientset.NewForConfig(config)\n        if err != nil {\n                panic(err)\n        }\n        kubeclient := client.SamplecontrollerV1alpha1().Foos(\"default\")\n\n        // Create resource object\n        object := \u0026samplecontrollerv1alpha1.Foo{\n                TypeMeta: metav1.TypeMeta{\n                        Kind:       \"Foo\",\n                        APIVersion: \"samplecontroller.k8s.io/v1alpha1\",\n                },\n                ObjectMeta: metav1.ObjectMeta{\n                        Name: \"example-foo\",\n                },\n                Spec: samplecontrollerv1alpha1.FooSpec{\n                        DeploymentName: \"example-foo\",\n                        Replicas:       ptrint32(1),\n                },\n        }\n\n        // Manage resource\n        _, err = kubeclient.Create(context.TODO(), object, metav1.CreateOptions{})\n        if err != nil {\n                panic(err)\n        }\n        fmt.Println(\"Foo Created successfully!\")\n}\n\nfunc ptrint32(p int32) *int32 {\n        return \u0026p\n}\n```\n\n## Workflow/Algorithm:\nEnd-to-end workflow and algorithm to find imports can be found [here](https://docs.google.com/presentation/d/1_Es0d-QAkMMVdh8NiFCUMbKDQO76np-gCdTWlXLxAIY)\n\n## Contributing\n\nWe love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:\n- Reporting a bug\n- Discussing the current state of the code\n- Submitting a fix\n- Proposing new features\n\n## Credits\nThe Go Gopher is originally by [Renee French](http://reneefrench.blogspot.com/)\n\nThis artwork is borrowed from an awesome artwork collection by [Egon Elbre](https://github.com/egonelbre/gophers)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPrasadG193%2Fkyaml2go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPrasadG193%2Fkyaml2go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPrasadG193%2Fkyaml2go/lists"}