SGScript.yaml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. apiVersion: apiextensions.k8s.io/v1
  2. kind: CustomResourceDefinition
  3. metadata:
  4. name: sgscripts.stackgres.io
  5. spec:
  6. group: stackgres.io
  7. scope: Namespaced
  8. names:
  9. kind: SGScript
  10. listKind: SGScriptList
  11. plural: sgscripts
  12. singular: sgscript
  13. shortNames:
  14. - sgscr
  15. versions:
  16. - name: v1
  17. served: true
  18. storage: true
  19. additionalPrinterColumns:
  20. - name: scripts
  21. type: string
  22. jsonPath: .spec.scripts.length
  23. schema:
  24. openAPIV3Schema:
  25. type: object
  26. required: ["metadata", "spec"]
  27. properties:
  28. metadata:
  29. type: object
  30. properties:
  31. name:
  32. type: string
  33. maxLength: 52
  34. pattern: "^[a-z]([-a-z0-9]*[a-z0-9])?$"
  35. description: |
  36. Name of the StackGres script. Following [Kubernetes naming conventions](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md), it must be an rfc1035/rfc1123 subdomain, that is, up to 253 characters consisting of one or more lowercase labels separated by `.`. Where each label is an alphanumeric (a-z, and 0-9) string, with the `-` character allowed anywhere except the first or last character.
  37. The name must be unique across all StackGres scripts in the same namespace. The full script name includes the namespace in which the script is created.
  38. spec:
  39. type: object
  40. properties:
  41. managedVersions:
  42. type: boolean
  43. description: |
  44. If `true` the versions will be managed by the operator automatically. The user will still be able to update them if needed. `true` by default.
  45. continueOnError:
  46. type: boolean
  47. description: |
  48. If `true`, when any script entry fail will not prevent subsequent script entries from being executed. `false` by default.
  49. scripts:
  50. type: array
  51. description: |
  52. A list of SQL scripts.
  53. items:
  54. type: object
  55. description: |
  56. Scripts are executed in auto-commit mode with the user `postgres` in the specified database (or in database `postgres` if not specified).
  57. Fields `script` and `scriptFrom` are mutually exclusive and only one of them is required.
  58. properties:
  59. name:
  60. type: string
  61. description: |
  62. Name of the script. Must be unique across this SGScript.
  63. id:
  64. type: integer
  65. description: |
  66. The id is immutable and must be unique across all the script entries. It is replaced by the operator and is used to identify the script for the whole life of the `SGScript` object.
  67. version:
  68. type: integer
  69. description: |
  70. Version of the script. It will allow to identify if this script entry has been changed.
  71. database:
  72. type: string
  73. description: |
  74. Database where the script is executed. Defaults to the `postgres` database, if not specified.
  75. user:
  76. type: string
  77. description: |
  78. User that will execute the script. Defaults to the `postgres` user.
  79. wrapInTransaction:
  80. type: string
  81. description: |
  82. Wrap the script in a transaction using the specified transaction mode:
  83. * `read-committed`: The script will be wrapped in a transaction using [READ COMMITTED](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-READ-COMMITTED) isolation level.
  84. * `repeatable-read`: The script will be wrapped in a transaction using [REPEATABLE READ](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-REPEATABLE-READ) isolation level.
  85. * `serializable`: The script will be wrapped in a transaction using [SERIALIZABLE](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-SERIALIZABLE) isolation level.
  86. If not set the script entry will not be wrapped in a transaction
  87. storeStatusInDatabase:
  88. type: boolean
  89. description: |
  90. When set to `true` the script entry execution will include storing the status of the execution of this
  91. script entry in the table `managed_sql.status` that will be created in the specified `database`. This
  92. will avoid an operation that fails partially to be unrecoverable requiring the intervention from the user
  93. if user in conjunction with `retryOnError`.
  94. If set to `true` then `wrapInTransaction` field must be set.
  95. This is `false` by default.
  96. retryOnError:
  97. type: boolean
  98. description: |
  99. If not set or set to `false` the script entry will not be retried if it fails.
  100. When set to `true` the script execution will be retried with an exponential backoff of 5 minutes,
  101. starting from 10 seconds and a standard deviation of 10 seconds.
  102. This is `false` by default.
  103. script:
  104. type: string
  105. description: |
  106. Raw SQL script to execute. This field is mutually exclusive with `scriptFrom` field.
  107. scriptFrom:
  108. type: object
  109. description: |
  110. Reference to either a Kubernetes [Secret](https://kubernetes.io/docs/concepts/configuration/secret/) or a [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/) that contains the SQL script to execute. This field is mutually exclusive with `script` field.
  111. Fields `secretKeyRef` and `configMapKeyRef` are mutually exclusive, and one of them is required.
  112. properties:
  113. secretKeyRef:
  114. type: object
  115. description: |
  116. A Kubernetes [SecretKeySelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#secretkeyselector-v1-core) that contains the SQL script to execute. This field is mutually exclusive with `configMapKeyRef` field.
  117. properties:
  118. name:
  119. type: string
  120. description: Name of the referent. [More information](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names).
  121. key:
  122. type: string
  123. description: The key of the secret to select from. Must be a valid secret key.
  124. configMapKeyRef:
  125. type: object
  126. description: |
  127. A [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/) reference that contains the SQL script to execute. This field is mutually exclusive with `secretKeyRef` field.
  128. properties:
  129. name:
  130. type: string
  131. description: |
  132. The name of the ConfigMap that contains the SQL script to execute.
  133. key:
  134. type: string
  135. description: |
  136. The key name within the ConfigMap that contains the SQL script to execute.
  137. status:
  138. type: object
  139. properties:
  140. scripts:
  141. type: array
  142. description: |
  143. A list of script entry statuses where a script entry under `.spec.scripts` is identified by the `id` field.
  144. items:
  145. type: object
  146. properties:
  147. id:
  148. type: integer
  149. description: |
  150. The id that identifies a script entry.
  151. hash:
  152. type: string
  153. description: |
  154. The hash of a ConfigMap or Secret referenced with the associated script entry.