Skip to content

Commit

Permalink
feat: multiple configs (#1)
Browse files Browse the repository at this point in the history
* feat: multiple configs

* chore: remove temp file at the end
  • Loading branch information
Aatman authored Sep 8, 2021
1 parent 21b83ab commit 9f7f265
Show file tree
Hide file tree
Showing 9 changed files with 610 additions and 21 deletions.
122 changes: 120 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ $ pulumi plugin install resource kubernetes v2.4.2

## Usage

```
$ go test
$ go build
```
```
$ printf 'apiVersion: v1
kind: ServiceAccount
metadata:
name: my-service-account
namespace: my-namespace' > temp.yaml
```

```
$ go build
$ ./kube2cdk8s typescript -f temp.yaml
new cdk8s.ApiObject("", this, {
apiVersion: "v1",
Expand All @@ -38,3 +40,119 @@ new cdk8s.ApiObject("", this, {
},
});
```
```
printf '---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
namespace: my-namespace
spec:
selector:
matchLabels:
app: my-deployment
replicas: 3
template:
metadata:
labels:
app: my-deployment
spec:
containers:
- name: my-deployment
image: my-image
imagePullPolicy: Always
ports:
- containerPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment-2
namespace: my-namespace-2
spec:
selector:
matchLabels:
app: my-deployment-2
replicas: 4
template:
metadata:
labels:
app: my-deployment-2
spec:
containers:
- name: my-deployment-2
image: my-image-2
imagePullPolicy: Always
ports:
- containerPort: 8080' > temp.yaml
```
```
$ ./kube2cdk8s typescript -m true -f temp.yaml
new cdk8s.ApiObject("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "my-deployment",
namespace: "my-namespace",
},
spec: {
selector: {
matchLabels: {
app: "my-deployment",
},
},
replicas: 3,
template: {
metadata: {
labels: {
app: "my-deployment",
},
},
spec: {
containers: [{
name: "my-deployment",
image: "my-image",
imagePullPolicy: "Always",
ports: [{
containerPort: 8080,
}],
}],
},
},
},
});
new cdk8s.ApiObject("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "my-deployment-2",
namespace: "my-namespace-2",
},
spec: {
selector: {
matchLabels: {
app: "my-deployment-2",
},
},
replicas: 4,
template: {
metadata: {
labels: {
app: "my-deployment-2",
},
},
spec: {
containers: [{
name: "my-deployment-2",
image: "my-image-2",
imagePullPolicy: "Always",
ports: [{
containerPort: 8080,
}],
}],
},
},
},
});
```
17 changes: 15 additions & 2 deletions cmd/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,30 @@ func TSCommand() *cobra.Command {
Long: "convert k8s yaml to typescript",
RunE: func(cmd *cobra.Command, args []string) error {
filePath := viper.GetString("file")
multiple := viper.GetBool("multiple")

var result string

if filePath == "" {
log.Fatal("-f, --file is required")
}

data, err := kube2cdk8s.Kube2CDK8S(filePath)
if multiple {
result, err := kube2cdk8s.Kube2CDK8SMultiple(filePath)
if err != nil {
return err
}

fmt.Print(result)
return nil
}

result, err := kube2cdk8s.Kube2CDK8S(filePath)
if err != nil {
return err
}

fmt.Print(data)
fmt.Print(result)
return nil
}}

Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import (
"github.com/spf13/viper"
)

var manifestFile string
var (
manifestFile string
multiple bool
)

func configureCLI() *cobra.Command {
rootCmd := &cobra.Command{Use: "kube2cdk8s", Long: "converts k8s yaml to cdk8s"}
Expand All @@ -38,6 +41,12 @@ func configureCLI() *cobra.Command {
log.Println(err)
}

rootCmd.PersistentFlags().BoolVarP(&multiple, "multiple", "m", false, "convert multiple yamls seperated by ---")
err = viper.BindPFlag("multiple", rootCmd.PersistentFlags().Lookup("multiple"))
if err != nil {
log.Println(err)
}

return rootCmd
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
new cdk8s.ApiObject("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "my-deployment",
namespace: "my-namespace",
},
spec: {
selector: {
matchLabels: {
app: "my-deployment",
},
},
replicas: 3,
template: {
metadata: {
labels: {
app: "my-deployment",
},
},
spec: {
containers: [{
name: "my-deployment",
image: "my-image",
imagePullPolicy: "Always",
ports: [{
containerPort: 8080,
}],
}],
},
},
},
});

new cdk8s.ApiObject("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "my-deployment-2",
namespace: "my-namespace-2",
},
spec: {
selector: {
matchLabels: {
app: "my-deployment-2",
},
},
replicas: 4,
template: {
metadata: {
labels: {
app: "my-deployment-2",
},
},
spec: {
containers: [{
name: "my-deployment-2",
image: "my-image-2",
imagePullPolicy: "Always",
ports: [{
containerPort: 8080,
}],
}],
},
},
},
});





Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
new cdk8s.ApiObject("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "my-deployment",
namespace: "my-namespace",
},
spec: {
selector: {
matchLabels: {
app: "my-deployment",
},
},
replicas: 3,
template: {
metadata: {
labels: {
app: "my-deployment",
},
},
spec: {
containers: [{
name: "my-deployment",
image: "my-image",
imagePullPolicy: "Always",
ports: [{
containerPort: 8080,
}],
}],
},
},
},
});

new cdk8s.ApiObject("", this, {
apiVersion: "apps/v1",
kind: "Deployment",
metadata: {
name: "my-deployment-2",
namespace: "my-namespace-2",
},
spec: {
selector: {
matchLabels: {
app: "my-deployment-2",
},
},
replicas: 4,
template: {
metadata: {
labels: {
app: "my-deployment-2",
},
},
spec: {
containers: [{
name: "my-deployment-2",
image: "my-image-2",
imagePullPolicy: "Always",
ports: [{
containerPort: 8080,
}],
}],
},
},
},
});


Loading

0 comments on commit 9f7f265

Please sign in to comment.