GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spec.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package resource
  2. import (
  3. "fmt"
  4. "github.com/fluxcd/flux/image"
  5. "github.com/fluxcd/flux/resource"
  6. )
  7. // Types that daemonsets, deployments, and other things have in
  8. // common.
  9. type ObjectMeta struct {
  10. Labels map[string]string
  11. Annotations map[string]string
  12. }
  13. type PodTemplate struct {
  14. Metadata ObjectMeta
  15. Spec PodSpec
  16. }
  17. func (t PodTemplate) Containers() []resource.Container {
  18. var result []resource.Container
  19. // FIXME(https://github.com/weaveworks/flux/issues/1269): account for possible errors (x2)
  20. for _, c := range t.Spec.Containers {
  21. im, _ := image.ParseRef(c.Image)
  22. result = append(result, resource.Container{Name: c.Name, Image: im})
  23. }
  24. for _, c := range t.Spec.InitContainers {
  25. im, _ := image.ParseRef(c.Image)
  26. result = append(result, resource.Container{Name: c.Name, Image: im})
  27. }
  28. return result
  29. }
  30. func (t PodTemplate) SetContainerImage(container string, ref image.Ref) error {
  31. for i, c := range t.Spec.Containers {
  32. if c.Name == container {
  33. t.Spec.Containers[i].Image = ref.String()
  34. return nil
  35. }
  36. }
  37. for i, c := range t.Spec.InitContainers {
  38. if c.Name == container {
  39. t.Spec.InitContainers[i].Image = ref.String()
  40. return nil
  41. }
  42. }
  43. return fmt.Errorf("container %q not found in workload", container)
  44. }
  45. type PodSpec struct {
  46. ImagePullSecrets []struct{ Name string }
  47. Volumes []Volume
  48. Containers []ContainerSpec
  49. InitContainers []ContainerSpec `yaml:"initContainers"`
  50. }
  51. type Volume struct {
  52. Name string
  53. Secret struct {
  54. SecretName string
  55. }
  56. }
  57. type ContainerSpec struct {
  58. Name string
  59. Image string
  60. Args Args
  61. Ports []ContainerPort
  62. Env Env
  63. }
  64. type Args []string
  65. type ContainerPort struct {
  66. ContainerPort int
  67. Name string
  68. }
  69. type VolumeMount struct {
  70. Name string
  71. MountPath string
  72. ReadOnly bool
  73. }
  74. // Env is a bag of Name, Value pairs that are treated somewhat like a
  75. // map.
  76. type Env []EnvEntry
  77. type EnvEntry struct {
  78. Name, Value string
  79. }