Kubernetes RabbitMQ operator https://github.com/tekliner/rabbitmq-operator
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.
 
 
 

166 lines
6.0 KiB

  1. package v1
  2. import (
  3. corev1 "k8s.io/api/core/v1"
  4. "k8s.io/api/policy/v1beta1"
  5. "k8s.io/apimachinery/pkg/api/resource"
  6. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  7. )
  8. // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
  9. // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
  10. // RabbitmqImage Sets image url and tag
  11. type RabbitmqImage struct {
  12. Name string `json:"name"`
  13. Tag string `json:"tag"`
  14. }
  15. // RabbitmqSSL sets SSL parameters
  16. type RabbitmqSSL struct {
  17. Enabled bool `json:"enabled"`
  18. ExitingSecret string `json:"exitingSecret,omitempty"`
  19. Cacertfile string `json:"cacertfile,omitempty"`
  20. Certfile string `json:"certfile,omitempty"`
  21. Keyfile string `json:"keyfile,omitempty"`
  22. }
  23. // RabbitmqAuth auth config
  24. type RabbitmqAuth struct {
  25. Enabled bool `json:"enabled"`
  26. // +kubebuilder:validation:UniqueItems=true
  27. Config []string `json:"mechanisms,omitempty"`
  28. }
  29. // RabbitmqPolicy type
  30. type RabbitmqPolicy struct {
  31. Vhost string `json:"vhost,omitempty"`
  32. Name string `json:"name"`
  33. Pattern string `json:"pattern"`
  34. Definition RabbitmqPolicyDefinition `json:"definition"`
  35. Priority int64 `json:"priority"`
  36. ApplyTo string `json:"apply-to"`
  37. }
  38. // RabbitmqPolicyDefinition type
  39. type RabbitmqPolicyDefinition struct {
  40. FederationUpstreamSet string `json:"federation-upstream-set,omitempty"`
  41. HaMode string `json:"ha-mode,omitempty"`
  42. HaParams int `json:"ha-params,omitempty"`
  43. HaSyncMode string `json:"ha-sync-mode,omitempty"`
  44. Expires int `json:"expires,omitempty"`
  45. MessageTTL int `json:"message-ttl,omitempty"`
  46. MaxLen int `json:"max-length,omitempty"`
  47. MaxLenBytes int `json:"max-length-bytes,omitempty"`
  48. }
  49. // RabbitmqSpec defines the desired state of Rabbitmq
  50. // +k8s:openapi-gen=true
  51. type RabbitmqSpec struct {
  52. // +kubebuilder:validation:Minimum=1
  53. // +kubebuilder:validation:Maximum=10
  54. RabbitmqReplicas int32 `json:"replicas"`
  55. // set PodDisruptionBudget. Default values: if replicas >= 2, minA = 1
  56. // else if replicas = 1, maxU = 1
  57. RabbitmqPdb v1beta1.PodDisruptionBudget `json:"pdb,omitempty"`
  58. // set default_vhost, if empty falling to "%2f" (/)
  59. RabbitmqVhost string `json:"default_vhost,omitempty"`
  60. // all secrets generated once with CRDs name, but you can set it by hands
  61. // usualy not needed
  62. RabbitmqSecretCredentials string `json:"secret_credentials,omitempty"`
  63. RabbitmqSecretServiceAccount string `json:"secret_service_account,omitempty"`
  64. // working now, but will be ignored in future versions
  65. RabbitmqMemoryHighWatermark string `json:"memory_high_watermark,omitempty"`
  66. // Hipe
  67. RabbitmqHipeCompile bool `json:"hipe_compile,omitempty"`
  68. // set SSL settings
  69. // TODO: add to template, issue certs with Vault
  70. RabbitmqSSL RabbitmqSSL `json:"cert,omitempty"`
  71. // TODO: auth mechanisms
  72. RabbitmqAuth RabbitmqAuth `json:"auth,omitempty"`
  73. // set rabbitmq policies
  74. RabbitmqPolicies []RabbitmqPolicy `json:"policies"`
  75. // load additional plugins
  76. RabbitmqPlugins []string `json:"plugins"`
  77. // k8s specific
  78. // serviceaccount
  79. RabbitmqK8SServiceAccount string `json:"k8s_serviceaccount"`
  80. RabbitmqK8SServiceDiscovery string `json:"k8s_service_discovery"`
  81. // set your own ENV variables in k8s style
  82. K8SENV []corev1.EnvVar `json:"env,omitempty"`
  83. // you can set your own image instead of official
  84. K8SImage RabbitmqImage `json:"image"`
  85. // TODO: additional labels
  86. K8SLabels []metav1.LabelSelector `json:"k8s_labels"`
  87. // purge all PVC after CR deletion, default false
  88. RabbitmqPurgePVC bool `json:"purgePVC,omitempty"`
  89. // PersistentVolumeClaim in k8s style
  90. RabbitmqVolumeSize resource.Quantity `json:"volume_size"`
  91. // TODO: set rabbitmq limits to pod limits, remove RabbitmqMemoryHighWatermark Spec after it
  92. RabbitmqPodRequests corev1.ResourceList `json:"pod_requests,omitempty"`
  93. RabbitmqPodLimits corev1.ResourceList `json:"pod_limits,omitempty"`
  94. RabbitmqK8SHost string `json:"k8s_host"`
  95. RabbitmqK8SAddrType string `json:"k8s_addrtype"`
  96. RabbitmqK8SPeerDiscoveryBackend string `json:"k8s_peer_discovery_backend"`
  97. RabbitmqClusterFormationNodeCleanup int64 `json:"cluster_node_cleanup_interval"`
  98. RabbitmqClusterPartitionHandling string `json:"cluster_partition_handling"`
  99. RabbitmqPrometheusExporterPort int32 `json:"prometheus_exporter_port,omitempty"`
  100. RabbitmqPrometheusImage string `json:"prometheus_image,omitempty"`
  101. RabbitmqAffinity *corev1.Affinity `json:"affinity,omitempty"`
  102. NodeSelector map[string]string `json:"nodeSelector"`
  103. Tolerations []corev1.Toleration `json:"tolerations"`
  104. RabbitmqUseServiceMonitor bool `json:"use_service_monitor,omitempty"`
  105. }
  106. // RabbitmqStatus defines the observed state of Rabbitmq
  107. // +k8s:openapi-gen=true
  108. type RabbitmqStatus struct {
  109. // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
  110. // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
  111. // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
  112. }
  113. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
  114. // Rabbitmq is the Schema for the rabbitmqs API
  115. // +k8s:openapi-gen=true
  116. type Rabbitmq struct {
  117. metav1.TypeMeta `json:",inline"`
  118. metav1.ObjectMeta `json:"metadata,omitempty"`
  119. Spec RabbitmqSpec `json:"spec,omitempty"`
  120. Status RabbitmqStatus `json:"status,omitempty"`
  121. }
  122. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
  123. // RabbitmqList contains a list of Rabbitmq
  124. type RabbitmqList struct {
  125. metav1.TypeMeta `json:",inline"`
  126. metav1.ListMeta `json:"metadata,omitempty"`
  127. Items []Rabbitmq `json:"items"`
  128. }
  129. func init() {
  130. SchemeBuilder.Register(&Rabbitmq{}, &RabbitmqList{})
  131. }