Skip to content

Commit

Permalink
fix issue #3: Print out warning for undefined fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtuna committed Jul 5, 2016
1 parent bea0e4b commit 1c0673a
Show file tree
Hide file tree
Showing 9 changed files with 1,021 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Godeps/Godeps.json

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

52 changes: 49 additions & 3 deletions cli/app/app.go
Expand Up @@ -39,11 +39,46 @@ import (
"k8s.io/kubernetes/pkg/util/intstr"

"github.com/ghodss/yaml"
"github.com/fatih/structs"
)

type ProjectAction func(project *project.Project, c *cli.Context)

const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789"
var unsupportedKey = map[string]string {
"Build": "",
"CapAdd": "",
"CapDrop": "",
"CPUSet": "",
"CPUShares": "",
"ContainerName": "",
"Devices": "",
"DNS": "",
"DNSSearch": "",
"Dockerfile": "",
"DomainName": "",
"Entrypoint": "",
"EnvFile": "",
"Hostname": "",
"LogDriver": "",
"MemLimit": "",
"MemSwapLimit": "",
"Net": "",
"Pid": "",
"Uts": "",
"Ipc": "",
"ReadOnly": "",
"StdinOpen": "",
"SecurityOpt": "",
"Tty": "",
"User": "",
"VolumeDriver": "",
"VolumesFrom": "",
"Expose": "",
"ExternalLinks": "",
"LogOpt": "",
"ExtraHosts": "",
}

// RandStringBytes generates randomly n-character string
func RandStringBytes(n int) string {
Expand Down Expand Up @@ -243,6 +278,9 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
var serviceLinks []string

for name, service := range p.Configs {

checkUnsupportedKey(*service)

rc := &api.ReplicationController{
TypeMeta: unversioned.TypeMeta{
Kind: "ReplicationController",
Expand Down Expand Up @@ -681,6 +719,17 @@ func ProjectKuberConvert(p *project.Project, c *cli.Context) {
}
}

func checkUnsupportedKey(service project.ServiceConfig) {
s := structs.New(service)
for _, f := range s.Fields() {
if f.IsExported() && !f.IsZero() {
if _, ok := unsupportedKey[f.Name()]; ok {
fmt.Println("WARNING: Unsupported key " + f.Name() + " - ignoring")
}
}
}
}

func print(name, trailing string, data []byte, toStdout, generateYaml bool, outFile string) {
file := fmt.Sprintf("%s-%s.json", name, trailing)
if generateYaml {
Expand All @@ -696,9 +745,6 @@ func print(name, trailing string, data []byte, toStdout, generateYaml bool, outF
if toStdout {
fmt.Fprintf(os.Stdout, "%s%s\n", string(data), separator)
} else {
//if err := ioutil.WriteFile(file, []byte(data), 0644); err != nil {
// logrus.Fatalf("Failed to write %s: %v", trailing, err)
//}
f, err := os.OpenFile(file, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0644)
if err != nil {
logrus.Fatalf("error opening file: %v", err)
Expand Down
23 changes: 23 additions & 0 deletions vendor/github.com/fatih/structs/.gitignore

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

11 changes: 11 additions & 0 deletions vendor/github.com/fatih/structs/.travis.yml

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

21 changes: 21 additions & 0 deletions vendor/github.com/fatih/structs/LICENSE

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

163 changes: 163 additions & 0 deletions vendor/github.com/fatih/structs/README.md

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

0 comments on commit 1c0673a

Please sign in to comment.