Skip to content

Commit

Permalink
feat: strict typed objects instead of api object (#4)
Browse files Browse the repository at this point in the history
* feat: use typed objects instead of api object

* chore: update readme
  • Loading branch information
Aatman authored Sep 8, 2021
1 parent 8928b29 commit 4c69ce8
Show file tree
Hide file tree
Showing 90 changed files with 1,405 additions and 129 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ metadata:
```
```
$ ./kube2cdk8s typescript -f temp.yaml
new cdk8s.ApiObject("", this, {
new k8s.KubeServiceAccount("", this, {
apiVersion: "v1",
kind: "ServiceAccount",
metadata: {
Expand Down Expand Up @@ -88,7 +88,7 @@ spec:
```
```
$ ./kube2cdk8s typescript -m true -f temp.yaml
new cdk8s.ApiObject("", this, {
new k8s.KubeDeployment("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down Expand Up @@ -122,7 +122,7 @@ new cdk8s.ApiObject("", this, {
},
});
new cdk8s.ApiObject("", this, {
new k8s.KubeDeployment("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ require (
github.com/pulumi/kube2pulumi v0.0.10
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.8.1
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
)
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210420210106-798c2154c571/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210505214959-0714010a04ed h1:V9kAVxLvz1lkufatrpHuUVyJ/5tR3Ms7rk951P4mI98=
golang.org/x/net v0.0.0-20210505214959-0714010a04ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -837,6 +837,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
new cdk8s.ApiObject(this, "", {
new k8s.KubeDeployment(this, "my-deployment", {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
new cdk8s.ApiObject(this, "", {
new k8s.KubeDeployment(this, "my-deployment", {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down Expand Up @@ -32,7 +32,7 @@ new cdk8s.ApiObject(this, "", {
},
});

new cdk8s.ApiObject(this, "", {
new k8s.KubeDeployment(this, "my-deployment-2", {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
new cdk8s.ApiObject(this, "", {
new k8s.KubeDeployment(this, "my-deployment", {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down Expand Up @@ -32,7 +32,7 @@ new cdk8s.ApiObject(this, "", {
},
});

new cdk8s.ApiObject(this, "", {
new k8s.KubeDeployment(this, "my-deployment-2", {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
new cdk8s.ApiObject(this, "", {
new k8s.KubeDeployment(this, "my-deployment", {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down Expand Up @@ -32,7 +32,7 @@ new cdk8s.ApiObject(this, "", {
},
});

new cdk8s.ApiObject(this, "", {
new k8s.KubeDeployment(this, "my-deployment-2", {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
new cdk8s.ApiObject(this, "", {
new k8s.KubeServiceAccount(this, "my-service-account", {
apiVersion: "v1",
kind: "ServiceAccount",
metadata: {
Expand Down
19 changes: 18 additions & 1 deletion pkg/kube2cdk8s/kube2cdk8s.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package kube2cdk8s

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/pulumi/kube2pulumi/pkg/kube2pulumi"
"github.com/smallcase/kube2cdk8s/util"
"github.com/spf13/viper"
)

func Kube2CDK8S(filePath string) (string, error) {
Expand All @@ -31,8 +34,22 @@ func Kube2CDK8S(filePath string) (string, error) {
}
output := strings.Join(lines, "\n")

viper.New()
viper.AddConfigPath("/tmp")
viper.SetConfigName(filepath.Base(filePath))
viper.SetConfigType("yaml")

if err := viper.ReadInConfig(); err != nil {
return "", err
}

n := viper.GetString("metadata.name")
k := viper.GetString("kind")

name := fmt.Sprintf("new k8s.Kube%s(this, \"%s\", {", k, n)

re := regexp.MustCompile("(?m)[\r\n]+^.*const.*$")
res := re.ReplaceAllString(output, `new cdk8s.ApiObject(this, "", {`)
res := re.ReplaceAllString(output, name)

defer os.Remove(path)

Expand Down
49 changes: 49 additions & 0 deletions vendor/golang.org/x/net/http2/ascii.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions vendor/golang.org/x/net/http2/headermap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions vendor/golang.org/x/net/http2/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 21 additions & 9 deletions vendor/golang.org/x/net/http2/transport.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion vendor/golang.org/x/net/http2/write.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions vendor/golang.org/x/sys/cpu/cpu.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/golang.org/x/sys/cpu/cpu_aix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4c69ce8

Please sign in to comment.