douxie2029 2019-08-27 20:24
浏览 102

如何操作kubernetes PodSpec对象

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.

  • 写回答

1条回答 默认 最新

  • dongyun3897 2019-08-28 05:11
    关注

    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"})
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题