Skip to content

Commit

Permalink
Add PodTemplate to cluster specificaton
Browse files Browse the repository at this point in the history
This patch adds a new parameter to the CRD named `podTemplate`, containing a
template that is used to create Pods for PostgreSQL instances. This feature is
useful to fine-grain configure things that don't have a direct field in
CRD, like NodeAffinity.

The patch also updates the version of `controllen-gen` we are using the latest version
because the previous one had a bug preventing the generation of CRDs where PodTemplate
is used. More information can be found here:

operator-framework/operator-sdk#3235

Co-authored-by: Leonardo Cecchi <leonardo.cecchi@2ndquadrant.it>
Co-authored-by: Jonathan Gonzalez V <jonathan.gonzalez@2ndquadrant.com>
Co-authored-by: Marco Nenciarini <marco.nenciarini@2ndquadrant.it>
Co-authored-by: Gabriele Bartolini <gabriele.bartolini@2ndquadrant.it>
  • Loading branch information
5 people committed Dec 22, 2020
1 parent 8652a85 commit ec0e5ba
Show file tree
Hide file tree
Showing 24 changed files with 7,175 additions and 834 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -126,13 +126,13 @@ apidoc: po-docgen
.PHONY: controller-gen
controller-gen:
# download controller-gen if necessary
ifneq ($(shell controller-gen --version), Version: v0.3.0)
ifneq ($(shell controller-gen --version), Version: v0.4.1)
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
Expand Down
37 changes: 37 additions & 0 deletions api/v1alpha1/cluster_types.go
Expand Up @@ -61,6 +61,38 @@ const (
defaultPostgresGID = 26
)

// MetaSubset contains a subset of the standard object's metadata.
// TODO: Dissmiss this type if we can in the future
type MetaSubset struct {
// Annotations is an unstructured key value map stored with a resource that may be
// set by external tools to store and retrieve arbitrary metadata. They are not
// queryable and should be preserved when modifying objects.
// More info: http://kubernetes.io/docs/user-guide/annotations
// +optional
Annotations map[string]string `json:"annotations,omitempty"`

// Map of string keys and values that can be used to organize and categorize
// (scope and select) objects. May match selectors of replication controllers
// and services.
// More info: http://kubernetes.io/docs/user-guide/labels
// +optional
Labels map[string]string `json:"labels,omitempty"`
}

// PodTemplateSpec describes the data a pod should have when created from a template.
// TODO: Dissmiss this type if we can in the future
type PodTemplateSpec struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
Meta MetaSubset `json:"metadata,omitempty"`

// Specification of the desired behavior of the pod.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// +optional
Spec corev1.PodSpec `json:"spec,omitempty"`
}

// ClusterSpec defines the desired state of Cluster
type ClusterSpec struct {
// Description of this PostgreSQL cluster
Expand Down Expand Up @@ -122,6 +154,11 @@ type ClusterSpec struct {
// +optional
Affinity AffinityConfiguration `json:"affinity,omitempty"`

// This contains a Pod template which is applied when creating
// the actual instances
// +optional
PodTemplate *PodTemplateSpec `json:"podTemplate,omitempty"`

// Resources requirements of every generated Pod. Please refer to
// https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// for more information.
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/cluster_webhook.go
Expand Up @@ -35,7 +35,7 @@ func (r *Cluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
Complete()
}

// +kubebuilder:webhook:path=/mutate-postgresql-k8s-enterprisedb-io-v1alpha1-cluster,mutating=true,failurePolicy=fail,groups=postgresql.k8s.enterprisedb.io,resources=clusters,verbs=create;update,versions=v1alpha1,name=mcluster.kb.io
// +kubebuilder:webhook:webhookVersions={v1beta1},admissionReviewVersions={v1beta1},path=/mutate-postgresql-k8s-enterprisedb-io-v1alpha1-cluster,mutating=true,failurePolicy=fail,groups=postgresql.k8s.enterprisedb.io,resources=clusters,verbs=create;update,versions=v1alpha1,name=mcluster.kb.io

var _ webhook.Defaulter = &Cluster{}

Expand Down Expand Up @@ -81,7 +81,7 @@ func (r *Cluster) Default() {
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
// +kubebuilder:webhook:verbs=create;update,path=/validate-postgresql-k8s-enterprisedb-io-v1alpha1-cluster,mutating=false,failurePolicy=fail,groups=postgresql.k8s.enterprisedb.io,resources=clusters,versions=v1alpha1,name=vcluster.kb.io
// +kubebuilder:webhook:webhookVersions={v1beta1},admissionReviewVersions={v1beta1},verbs=create;update,path=/validate-postgresql-k8s-enterprisedb-io-v1alpha1-cluster,mutating=false,failurePolicy=fail,groups=postgresql.k8s.enterprisedb.io,resources=clusters,versions=v1alpha1,name=vcluster.kb.io

var _ webhook.Validator = &Cluster{}

Expand Down
51 changes: 51 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit ec0e5ba

Please sign in to comment.