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.
 
 
 

161 lines
5.7 KiB

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