kedge icon indicating copy to clipboard operation
kedge copied to clipboard

Output generated by `kedge init` is human unfriendly :-(

Open kadel opened this issue 8 years ago • 10 comments

The file generated by kedge init is not friendly for new users :-(

./kedge init -c DeploymentConfig -i tomaskral/nonroot-nginx -p 8080 --name demo

currently, it looks like this

containers:
- image: tomaskral/nonroot-nginx
controller: DeploymentConfig
name: demo
services:
- portMappings:
  - 8080

But something like this would look much better.

name: demo
controller: DeploymentConfig

containers:
- image: tomaskral/nonroot-nginx

services:
- portMappings:
  - "8080"

this is much easier to read and more importantly edit

ping @pradeepto

kadel avatar Oct 30 '17 13:10 kadel

@kadel Does make sense to me but my first and only thought was - "will it make users think that vertical space is mandatory?"

pradeepto avatar Nov 01 '17 03:11 pradeepto

@kadel Does make sense to me but my first and only thought was - "will it make users think that vertical space is mandatory?"

I don't think that. But if that is a concern, we can remove those empty lines. For me personally, it creates nice logical blocks, but it just something that I like to do. I don't have a strong opinion about that.

I'm convinced that ordering is important, it doesn't change anything, but it is much more logical.

kadel avatar Nov 01 '17 12:11 kadel

@kadel so we are marshalling this struct App so we don't control order of the fields marshalling, the library takes care of doing that. Inside struct I have defined the fields in the order you have mentioned.

surajssd avatar Nov 13 '17 13:11 surajssd

@kadel so we are marshalling this struct App so we don't control order of the fields marshalling, the library takes care of doing that. Inside struct I have defined the fields in the order you have mentioned.

But the important is how it looks like in the output file.

The way we have implemented this is maybe making it a bit easier for us, but it definitely makes it harder for new users and first-time kedge users. I don't think that this is a good tradeoff @pradeepto

kadel avatar Nov 13 '17 16:11 kadel

@kadel then we can move back to golang templates, if you suggest so!

surajssd avatar Nov 14 '17 05:11 surajssd

To maintain the sequence what we can do is that we define multiple structs:

type Name struct {
    Name string
}

type Controller struct {
    Controller string
}

type Containers struct {
    Containers []Container
}

type Services struct {
    Services   []Service
}

Now we define objects of each and define value as needed, now marshal each struct object into yaml and now keep those marshalled bytes, keep marshalling each struct object and appending up bytes, as we need keep adding empty lines or instructions in bytes.

So basically carefully craft the file. This might seem overkill and you might as well suggest why not go back to golang templating, but I don't have an answer for that.

surajssd avatar Dec 04 '17 06:12 surajssd

I still don't see what is the benefit of approach compare to templating. It would make sense if we could use types from type.go. But without that, I don't see any benefit of doing it like this.

kadel avatar Dec 11 '17 12:12 kadel

@kadel we are not using structs from types.go because

https://github.com/kedgeproject/kedge/blob/0f5093e8c6fbca005082a79cdaf0a60bbc41ada7/cmd/init.go#L34-L45

surajssd avatar Dec 11 '17 13:12 surajssd

@kadel we are not using structs from types.go because

yes I know. What is a benefit of using separate structs over templating new file? There are still two different places where the structure of the file is kept.

kadel avatar Dec 11 '17 13:12 kadel

@kadel templating will allow us to add blank lines, so that output will look better and more readable

surajnarwade avatar Dec 27 '17 10:12 surajnarwade