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.
 
 
 

168 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. RabbitmqStorageClass *string `json:"rabbitmq_storage_class,omitempty"`
  74. // set rabbitmq policies
  75. RabbitmqPolicies []RabbitmqPolicy `json:"policies"`
  76. // load additional plugins
  77. RabbitmqPlugins []string `json:"plugins"`
  78. // k8s specific
  79. // serviceaccount
  80. RabbitmqK8SServiceAccount string `json:"k8s_serviceaccount"`
  81. RabbitmqK8SServiceDiscovery string `json:"k8s_service_discovery"`
  82. // set your own ENV variables in k8s style
  83. K8SENV []corev1.EnvVar `json:"env,omitempty"`
  84. // you can set your own image instead of official
  85. K8SImage RabbitmqImage `json:"image"`
  86. // TODO: additional labels
  87. K8SLabels []metav1.LabelSelector `json:"k8s_labels"`
  88. // purge all PVC after CR deletion, default false
  89. RabbitmqPurgePVC bool `json:"purgePVC,omitempty"`
  90. // PersistentVolumeClaim in k8s style
  91. RabbitmqVolumeSize resource.Quantity `json:"volume_size"`
  92. // TODO: set rabbitmq limits to pod limits, remove RabbitmqMemoryHighWatermark Spec after it
  93. RabbitmqPodRequests corev1.ResourceList `json:"pod_requests,omitempty"`
  94. RabbitmqPodLimits corev1.ResourceList `json:"pod_limits,omitempty"`
  95. RabbitmqK8SHost string `json:"k8s_host"`
  96. RabbitmqK8SAddrType string `json:"k8s_addrtype"`
  97. RabbitmqK8SPeerDiscoveryBackend string `json:"k8s_peer_discovery_backend"`
  98. RabbitmqClusterFormationNodeCleanup int64 `json:"cluster_node_cleanup_interval"`
  99. RabbitmqClusterPartitionHandling string `json:"cluster_partition_handling"`
  100. RabbitmqPrometheusExporterPort int32 `json:"prometheus_exporter_port,omitempty"`
  101. RabbitmqPrometheusImage string `json:"prometheus_image,omitempty"`
  102. RabbitmqAffinity *corev1.Affinity `json:"affinity,omitempty"`
  103. NodeSelector map[string]string `json:"nodeSelector"`
  104. Tolerations []corev1.Toleration `json:"tolerations"`
  105. RabbitmqUseServiceMonitor bool `json:"use_service_monitor,omitempty"`
  106. }
  107. // RabbitmqStatus defines the observed state of Rabbitmq
  108. // +k8s:openapi-gen=true
  109. type RabbitmqStatus struct {
  110. // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
  111. // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
  112. // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
  113. }
  114. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
  115. // Rabbitmq is the Schema for the rabbitmqs API
  116. // +k8s:openapi-gen=true
  117. type Rabbitmq struct {
  118. metav1.TypeMeta `json:",inline"`
  119. metav1.ObjectMeta `json:"metadata,omitempty"`
  120. Spec RabbitmqSpec `json:"spec,omitempty"`
  121. Status RabbitmqStatus `json:"status,omitempty"`
  122. }
  123. // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
  124. // RabbitmqList contains a list of Rabbitmq
  125. type RabbitmqList struct {
  126. metav1.TypeMeta `json:",inline"`
  127. metav1.ListMeta `json:"metadata,omitempty"`
  128. Items []Rabbitmq `json:"items"`
  129. }
  130. func init() {
  131. SchemeBuilder.Register(&Rabbitmq{}, &RabbitmqList{})
  132. }