-2

I am looking for some help with the golang code to modify the podspec based on user input.

This is my flow.

User provides an incomplete yaml file to create deployment. Assume they are missing/update environment variables information. User also gives a variable foo [{name: "abc", value: "xyz"}, {name: "ab", value: "12"}] which has the environment variable information. I need to read the yaml file and merge the variable before i create the deployment.

This is what I have figured out so far, Read yaml file.

decode := scheme.Codecs.UniversalDeserializer().Decode
data, _ := readyamlfile(file)
obj, _, _ := decode(data, nil, nil)
dep := obj.(*appsv1.Deployment)

From dep I can find the podspec. Now I need to update the object based on user input foo. Not sure if i can use XXX_Merge function or not. Please recommend and if possible provide a working example pointer of XXX_Merge function. https://godoc.org/k8s.io/apiserver/pkg/apis/example/v1#PodSpec.XXX_Merge

Please let me know if there is any other way.

  • Your overall workflow sounds pretty similar to what [Helm](https://helm.sh) does; could you use that in place of a custom tool? – David Maze Aug 28 '19 at 01:02

1 Answers1

0

You should not use XXX_Merge. Just fill the dep object with user inputs. For instance:

dep.Spec.Template.Env = append(dep.Spec.Template.Env, EnvVar{Name: "abc", Value: "xyz"})
dep.Spec.Template.Env = append(dep.Spec.Template.Env, EnvVar{Name: "ab", Value: "12"})
hoozecn
  • 497
  • 4
  • 14
  • Any specific reason not to XXX_Merge? Currently I am only supporting Env variables, so this will work just fine. But the moment I start almost complete PodSpec this will become tricky. Curious why XXX_Merge function not to be used or any scenario where it should be used. – Nitin Mathur Aug 29 '19 at 18:35