fkorotkov / k8s-kotlin-dsl

Kotlin DSL for Kubernetes configs
MIT License
342 stars 19 forks source link

Get yaml or json representation of a kubernetes resource #26

Closed gAmUssA closed 4 years ago

gAmUssA commented 4 years ago

Hello

Say, I have a resource( deployment or stateful set). and I was wondering if there is a method that returns json or yaml representation?

Thank you

fkorotkov commented 4 years ago

fabric8 model object have Jackson annotation so if you'll just serialize them to JSON then you should be good to go. See example sub-project for reference https://github.com/fkorotkov/k8s-kotlin-dsl/blob/master/example/src/test/kotlin/BaseDeploymentTest.kt#L15

brizzbuzz commented 4 years ago

Just to take the example a bit farther, the steps to Json then to yaml aren't strictly necessary, you can achieve the same via

fun Deployment.asYaml(): String {
  return YAMLMapper().writeValueAsString(this)
}
fkorotkov commented 4 years ago

@rgbrizzlehizzle thank you!