Azure / draft-classic

A tool for developers to create cloud-native applications on Kubernetes.
https://draft.sh
MIT License
3.92k stars 396 forks source link

allow draft packs to customize draft.toml #820

Open omnilinguist opened 6 years ago

omnilinguist commented 6 years ago

This could be useful if an organization / team has custom draft.toml settings it would like to standardize as default.

Here's what actually happened when I tried putting a draft.toml inside a draft pack and then draft createing it:

contents of draft.toml in pack:

[environments]
  [environments.staging]
    name = "service-template"
    registry = "CUSTOM_DOCKER_REGISTRY"
    namespace = "staging"
    wait = true
    watch = false
    watch-delay = 2
    auto-connect = false
    dockerfile = ""
    chart = ""
    set = ["environment=staging"]
  [environments.prod]
    name = "service-template"
    registry = "CUSTOM_DOCKER_REGISTRY"
    namespace = "prod"
    wait = true
    watch = false
    watch-delay = 2
    auto-connect = false
    dockerfile = ""
    chart = ""
    set = ["environment=prod"]

what came out from draft create (this is verbatim):

[environments]
  [environments.development]
    name = "my-service"
    namespace = "default"
    wait = true
    watch = false
    watch-delay = 2
    auto-connect = false
    dockerfile = ""
    chart = ""
uto-connect = false
    dockerfile = ""
    chart = ""
    set = ["environment=staging"]
  [environments.prod]
    name = "service-template"
    registry = "CUSTOM_DOCKER_REGISTRY"
    namespace = "prod"
    wait = true
    watch = false
    watch-delay = 2
    auto-connect = false
    dockerfile = ""
    chart = ""
    set = ["environment=prod"]

It looks like the order of operations is to first copy the files, and then overwrite the initial segment of draft.toml with the default contents. I think a better behaviour might be to respect the existing contents, and only overwrite all name values in draft create if the pack already has a draft.toml (since it looks like that's the main thing within draft.toml that needs to be templatized/customized to the appName). This would require introspecting the TOML file contents though...

michelleN commented 6 years ago

Thanks for bringing this up @omnilinguist. We should probably not override a draft.toml file if it is included in the draft pack.

omnilinguist commented 6 years ago

that could be a good first iteration. I think you do want to introspect the toml though (or have a more generic templating method similar to https://github.com/audreyr/cookiecutter); there is already some automagic functionality elsewhere that is doing replacements and injections of the appName - eg. the name value in Chart.yaml, as well as the injection of an intermediate directory charts/appName/... to work around https://github.com/kubernetes/helm/issues/1979