Skip to content

Commit

Permalink
feat: introduce containers and volumes in podTemplate (#120)
Browse files Browse the repository at this point in the history
There's obvious constraint: user cannot add PVC's with `ReadWriteOnce`
or `ReadWriteOncePod` to pods as they should be included in
statefulset's volumeClaimTemplates or should have extra option in case
of custom pod controller

fixes #113
  • Loading branch information
sircthulhu authored Apr 4, 2024
1 parent 81c12c3 commit e3cdb40
Show file tree
Hide file tree
Showing 9 changed files with 6,624 additions and 1,779 deletions.
33 changes: 7 additions & 26 deletions api/v1alpha1/etcdcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,17 @@ type PodSpec struct {
// Image is the etcd container image name
// +optional
Image string `json:"image,omitempty"`
// ImagePullPolicy describes a policy for if/when to pull a container image
// +kubebuilder:default:=IfNotPresent

// Containers allows the user to add containers to the pod and change "etcd" container if such options are not
// available in the EtcdCluster custom resource.
// +optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Containers []corev1.Container `json:"containers" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=containers"`

// ImagePullSecrets An optional list of references to secrets in the same namespace
// to use for pulling images from registries
// see https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod
// +optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// Resources describes the compute resource requirements.
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
// Affinity sets the scheduling constraints for the pod.
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Expand Down Expand Up @@ -180,27 +179,9 @@ type PodSpec struct {
// RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod.
// +optional
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
// ExtraEnv are the extra environment variables to pass to the etcd container.
// +optional
ExtraEnv []corev1.EnvVar `json:"extraEnv,omitempty"`

// LivenessProbe defines liveness probe check for the pod.
// If not specified, default probe will be used with HTTP probe handler and path /livez on the port 2379,
// with periodSeconds 5.
// +optional
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"`

// ReadinessProbe defines readiness probe check for the pod.
// If not specified, default probe will be used with HTTP probe handler and path /readyz on the port 2379,
// with periodSeconds 5.
// +optional
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`

// StartupProbe defines startup probe check for the pod.
// If not specified, default probe will be used with HTTP probe handler and path /readyz?serializable=false on the port 2379,
// with periodSeconds 5.
// Volumes are volumes for being used by the pods. Cannot collide with "data" volume used by etcd.
// +optional
StartupProbe *corev1.Probe `json:"startupProbe,omitempty"`
Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,1,rep,name=volumes"`
}

// StorageSpec defines the configured storage for a etcd members.
Expand Down
15 changes: 15 additions & 0 deletions api/v1alpha1/etcdcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1
import (
"fmt"
"math"
"slices"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -66,6 +67,20 @@ func (r *EtcdCluster) Default() {
}
}
}
etcdContainerIdx := slices.IndexFunc(r.Spec.PodTemplate.Spec.Containers, func(c corev1.Container) bool {
return c.Name == "etcd"
})
if etcdContainerIdx == -1 {
r.Spec.PodTemplate.Spec.Containers = append(r.Spec.PodTemplate.Spec.Containers, corev1.Container{
Name: "etcd",
Image: defaultEtcdImage,
})
} else {
c := &r.Spec.PodTemplate.Spec.Containers[etcdContainerIdx]
if c.Image == "" {
c.Image = defaultEtcdImage
}
}
}

// +kubebuilder:webhook:path=/validate-etcd-aenix-io-v1alpha1-etcdcluster,mutating=false,failurePolicy=fail,sideEffects=None,groups=etcd.aenix.io,resources=etcdclusters,verbs=create;update,versions=v1alpha1,name=vetcdcluster.kb.io,admissionReviewVersions=v1
Expand Down
29 changes: 10 additions & 19 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit e3cdb40

Please sign in to comment.