postgresql_types.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. Copyright 2023.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package v1
  14. import (
  15. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  16. )
  17. // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
  18. // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
  19. // PostgreSQLSpec defines the desired state of PostgreSQL
  20. type PostgreSQLSpec struct {
  21. // Version of Postgres to deploy. [16.0]
  22. Version string `json:"version"`
  23. // Username for authentication
  24. User string `json:"user"`
  25. // Password for authentication
  26. Password string `json:"password"`
  27. // Autogenerated name for default Database
  28. Database string `json:"database"`
  29. }
  30. // PostgreSQLStatus defines the observed state of PostgreSQL
  31. type PostgreSQLStatus struct {
  32. Conditions Conditions `json:"conditions,omitempty"`
  33. Status Status `json:"status,omitempty"`
  34. ListenOn Listen `json:"listenOn,omitempty"`
  35. }
  36. type Listen struct {
  37. Node string `json:"node,omitempty"`
  38. Host string `json:"host,omitempty"`
  39. Port int32 `json:"port,omitempty"`
  40. }
  41. type Conditions struct {
  42. Pod Status `json:"pod,omitempty"`
  43. Service Status `json:"service,omitempty"`
  44. }
  45. type Status string
  46. const (
  47. Status_Error Status = "error"
  48. Status_Pending Status = "pending"
  49. Status_Initializing Status = "initializing"
  50. Status_NotReady Status = "notReady"
  51. Status_Ready Status = "ready"
  52. )
  53. func (a Status) IsLowerThan(b Status) bool {
  54. var m = map[Status]int{
  55. Status_Error: 0,
  56. Status_Pending: 1,
  57. Status_Initializing: 2,
  58. Status_NotReady: 3,
  59. Status_Ready: 4,
  60. }
  61. return m[a] < m[b]
  62. }
  63. //+kubebuilder:object:root=true
  64. //+kubebuilder:subresource:status
  65. //+kubebuilder:printcolumn:JSONPath=".status.listenOn.node",name=Node,type=string
  66. //+kubebuilder:printcolumn:JSONPath=".status.listenOn.host",name=Host,type=string
  67. //+kubebuilder:printcolumn:JSONPath=".status.listenOn.port",name=Port,type=number
  68. //+kubebuilder:printcolumn:JSONPath=".status.status",name=Status,type=string
  69. // PostgreSQL is the Schema for the postgresqls API
  70. type PostgreSQL struct {
  71. metav1.TypeMeta `json:",inline"`
  72. metav1.ObjectMeta `json:"metadata,omitempty"`
  73. Spec PostgreSQLSpec `json:"spec,omitempty"`
  74. Status PostgreSQLStatus `json:"status,omitempty"`
  75. }
  76. //+kubebuilder:object:root=true
  77. // PostgreSQLList contains a list of PostgreSQL
  78. type PostgreSQLList struct {
  79. metav1.TypeMeta `json:",inline"`
  80. metav1.ListMeta `json:"metadata,omitempty"`
  81. Items []PostgreSQL `json:"items"`
  82. }
  83. func init() {
  84. SchemeBuilder.Register(&PostgreSQL{}, &PostgreSQLList{})
  85. }