Skip to content

Commit

Permalink
Migrate PostgreSQL from P&T to comp-functions
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Bigler <[email protected]>
  • Loading branch information
TheBigLee committed Jun 12, 2024
1 parent ae7aa99 commit da1fa48
Show file tree
Hide file tree
Showing 30 changed files with 3,426 additions and 84 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,27 @@ generate-stackgres-crds:
go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1 -generate=types -o apis/stackgres/v1/sgcluster.gen.go apis/stackgres/v1/sgcluster.yaml
perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1/sgcluster.gen.go

# The generator for the pool config CRD unfortunately produces a broken result. However if we ever need to regenerate it in the future, please uncomment this.
# curl ${STACKGRES_CRD_URL}/SGInstanceProfile.yaml?inline=false -o apis/stackgres/v1/sginstanceprofile_crd.yaml
# yq -i e apis/stackgres/v1/sginstanceprofile.yaml --expression ".components.schemas.SGInstanceProfileSpec=load(\"apis/stackgres/v1/sginstanceprofile_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
# go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1 -generate=types -o apis/stackgres/v1/sginstanceprofile.gen.go apis/stackgres/v1/sginstanceprofile.yaml
# perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1/sginstanceprofile.gen.go

# The generator for the pool config CRD unfortunately produces a broken result. However if we ever need to regenerate it in the future, please uncomment this.
# curl ${STACKGRES_CRD_URL}/SGPoolingConfig.yaml?inline=false -o apis/stackgres/v1/sgpoolconfigs_crd.yaml
# yq -i e apis/stackgres/v1/sgpoolconfigs.yaml --expression ".components.schemas.SGPoolingConfigSpec=load(\"apis/stackgres/v1/sgpoolconfigs_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
# yq -i e apis/stackgres/v1/sgpoolconfigs.yaml --expression ".components.schemas.SGPoolingConfigStatus=load(\"apis/stackgres/v1/sgpoolconfigs_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.status"
# go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1 -generate=types -o apis/stackgres/v1/sgpoolconfigs.gen.go apis/stackgres/v1/sgpoolconfigs.yaml
# perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1/sgpoolconfigs.gen.go

curl ${STACKGRES_CRD_URL}/SGObjectStorage.yaml?inline=false -o apis/stackgres/v1beta1/sgobjectstorage_crd.yaml
yq -i e apis/stackgres/v1beta1/sgobjectstorage.yaml --expression ".components.schemas.SGObjectStorageSpec=load(\"apis/stackgres/v1beta1/sgobjectstorage_crd.yaml\").spec.versions[0].schema.openAPIV3Schema.properties.spec"
go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=v1beta1 -generate=types -o apis/stackgres/v1beta1/sgobjectstorage.gen.go apis/stackgres/v1beta1/sgobjectstorage.yaml
perl -i -0pe 's/\*struct\s\{\n\s\sAdditionalProperties\smap\[string\]string\s`json:"-"`\n\s}/map\[string\]string/gms' apis/stackgres/v1beta1/sgobjectstorage.gen.go


go run sigs.k8s.io/controller-tools/cmd/controller-gen object paths=./apis/stackgres/v1/...
go run sigs.k8s.io/controller-tools/cmd/controller-gen object paths=./apis/stackgres/v1beta1/...
rm apis/stackgres/v1/*_crd.yaml

.PHONY: fmt
Expand Down
2 changes: 2 additions & 0 deletions apis/stackgres/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ func init() {
&SGPostgesConfigList{},
&SGPoolingConfigList{},
&SGPoolingConfig{},
&SGInstanceProfile{},
&SGPInstanceProfileList{},
)
}
6 changes: 3 additions & 3 deletions apis/stackgres/v1/sgdbops.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const SGDbOpsRestartMethodInPlace = "InPlace"

// +kubebuilder:object:root=true

// VSHNPostgreSQL is the API for creating Postgresql clusters.
// SGDbOps is the API for creating SGDbOps objects.
type SGDbOps struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the desired state of a VSHNPostgreSQL.
// Spec defines the desired state of a SGDbOps.
Spec SGDbOpsSpec `json:"spec"`

// Status reflects the observed state of a VSHNPostgreSQL.
// Status reflects the observed state of a SGDbOps.
Status SGDbOpsStatus `json:"status,omitempty"`
}

Expand Down
25 changes: 25 additions & 0 deletions apis/stackgres/v1/sginstanceprofile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:object:root=true

// SGInstanceProfile is the API for creating instance profiles for SgClusters.
type SGInstanceProfile struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec contains the custom configurations for the SgInstanceProfile.
Spec SGInstanceProfileSpec `json:"spec"`
}

// +kubebuilder:object:root=true

type SGPInstanceProfileList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []SGInstanceProfile `json:"items"`
}
205 changes: 205 additions & 0 deletions apis/stackgres/v1/sginstanceprofile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
openapi: "3.0.2"
paths:
"/spec":
get:
responses:
"200":
content:
"application/json":
schema:
"$ref": "#/components/schemas/SGInstanceProfileSpec"
components:
schemas:
SGInstanceProfileSpec:
type: object
properties:
cpu:
type: string
pattern: '^[1-9][0-9]*[m]?$'
description: |
CPU(s) (cores) used for every instance of a SGCluster. The suffix `m`
specifies millicpus (where 1000m is equals to 1).
The number of cores set is assigned to the patroni container (that runs both Patroni and PostgreSQL).
A minimum of 2 cores is recommended.
memory:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated to every instance of a SGCluster. The suffix `Mi` or `Gi`
specifies Mebibytes or Gibibytes, respectively.
The amount of RAM set is assigned to the patroni container (that runs both Patroni and PostgreSQL).
A minimum of 2-4Gi is recommended.
hugePages:
type: object
description: |
RAM allocated for huge pages
properties:
hugepages-2Mi:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated for huge pages with a size of 2Mi. The suffix `Mi` or `Gi`
specifies Mebibytes or Gibibytes, respectively.
By default the amount of RAM set is assigned to patroni container
(that runs both Patroni and PostgreSQL).
hugepages-1Gi:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated for huge pages with a size of 1Gi. The suffix `Mi` or `Gi`
specifies Mebibytes or Gibibytes, respectively.
By default the amount of RAM set is assigned to patroni container
(that runs both Patroni and PostgreSQL).
containers:
type: object
description: |
The CPU(s) (cores) and RAM assigned to containers other than patroni container.
This section, if left empty, will be filled automatically by the operator with
some defaults that can be proportional to the resources assigned to patroni
container (except for the huge pages that are always left empty).
additionalProperties:
type: object
properties:
cpu:
type: string
pattern: '^[1-9][0-9]*[m]?$'
description: |
CPU(s) (cores) used for the specified Pod container. The suffix `m`
specifies millicpus (where 1000m is equals to 1).
memory:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated to the specified Pod container. The suffix `Mi` or `Gi`
specifies Mebibytes or Gibibytes, respectively.
hugePages:
type: object
description: |
RAM allocated for huge pages
properties:
hugepages-2Mi:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated for huge pages with a size of 2Mi. The suffix `Mi`
or `Gi` specifies Mebibytes or Gibibytes, respectively.
The amount of RAM is assigned to the specified container.
hugepages-1Gi:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated for huge pages with a size of 1Gi. The suffix `Mi`
or `Gi` specifies Mebibytes or Gibibytes, respectively.
The amount of RAM is assigned to the specified container.
required: ["cpu", "memory"]
initContainers:
type: object
description: The CPU(s) (cores) and RAM assigned to init containers.
additionalProperties:
type: object
properties:
cpu:
type: string
pattern: '^[1-9][0-9]*[m]?$'
description: |
CPU(s) (cores) used for the specified Pod init container. The suffix
`m` specifies millicpus (where 1000m is equals to 1).
memory:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated to the specified Pod init container. The suffix `Mi`
or `Gi` specifies Mebibytes or Gibibytes, respectively.
hugePages:
type: object
description: |
RAM allocated for huge pages
properties:
hugepages-2Mi:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated for huge pages with a size of 2Mi. The suffix `Mi`
or `Gi` specifies Mebibytes or Gibibytes, respectively.
The amount of RAM is assigned to the specified init container.
hugepages-1Gi:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated for huge pages with a size of 1Gi. The suffix `Mi` or `Gi`
specifies Mebibytes or Gibibytes, respectively.
The amount of RAM is assigned to the specified init container.
required: ["cpu", "memory"]
requests:
type: object
description: |
On containerized environments, when running production workloads, enforcing container's resources requirements request to be equals to the limits allow to achieve the highest level of performance. Doing so, reduces the chances of leaving
the workload with less resources than it requires. It also allow to set [static CPU management policy](https://kubernetes.io/docs/tasks/administer-cluster/cpu-management-policies/#static-policy) that allows to guarantee a pod the usage exclusive CPUs on the node.
There are cases where you may need to set resource requirement request to a different value than limit. This section allow to do so but requires to enable such feature in the `SGCluster` and `SGDistributedLogs` (see `.spec.nonProductionOptions` section for each of those custom resources).
properties:
cpu:
type: string
pattern: '^[1-9][0-9]*[m]?$'
description: |
CPU(s) (cores) used for every instance of a SGCluster. The suffix `m`
specifies millicpus (where 1000m is equals to 1).
The number of cores set is assigned to the patroni container (that runs both Patroni and PostgreSQL).
memory:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated to every instance of a SGCluster. The suffix `Mi` or `Gi`
specifies Mebibytes or Gibibytes, respectively.
The amount of RAM set is assigned to the patroni container (that runs both Patroni and PostgreSQL).
containers:
type: object
description: |
The CPU(s) (cores) and RAM assigned to containers other than patroni container.
additionalProperties:
type: object
properties:
cpu:
type: string
pattern: '^[1-9][0-9]*[m]?$'
description: |
CPU(s) (cores) used for the specified Pod container. The suffix `m`
specifies millicpus (where 1000m is equals to 1).
memory:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated to the specified Pod container. The suffix `Mi` or `Gi`
specifies Mebibytes or Gibibytes, respectively.
initContainers:
type: object
description: The CPU(s) (cores) and RAM assigned to init containers.
additionalProperties:
type: object
properties:
cpu:
type: string
pattern: '^[1-9][0-9]*[m]?$'
description: |
CPU(s) (cores) used for the specified Pod init container. The suffix
`m` specifies millicpus (where 1000m is equals to 1).
memory:
type: string
pattern: '^[0-9]+(\.[0-9]+)?(Mi|Gi)$'
description: |
RAM allocated to the specified Pod init container. The suffix `Mi`
or `Gi` specifies Mebibytes or Gibibytes, respectively.
required: ["cpu", "memory"]
88 changes: 88 additions & 0 deletions apis/stackgres/v1/sginstanceprofile_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit da1fa48

Please sign in to comment.