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

feat: multiple configs #1

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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