Skip to content

Commit 614f84e

Browse files
feat: add version probe job overrides (#153)
Co-authored-by: Pervakov Grigorii <pervakov.grigory@gmail.com>
1 parent d73a532 commit 614f84e

19 files changed

Lines changed: 3273 additions & 53 deletions

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ $(ACTIONLINT): $(LOCALBIN)
394394
$(call go-install-tool,$(ACTIONLINT),github.com/rhysd/actionlint/cmd/actionlint,$(ACTIONLINT_VERSION))
395395

396396
CRD_BASE_REF ?= origin/main
397+
# Violations from embedded Kubernetes core types (securityContext bools, resource maps, etc.)
398+
# that are structural to the k8s API, not operator design choices. These are automatically
399+
# suppressed by ratcheting for existing fields, but appear when adding new fields that embed core types.
400+
CRD_COMPAT_EMBEDDED_TYPE_RE := (securityContext|windowsOptions)\.|metadata\.(labels|annotations) |resources\.(limits|requests) |nodeSelector
397401
.PHONY: check-crd-compat
398402
check-crd-compat: crd-schema-checker ## Check CRD backward compatibility against $(CRD_BASE_REF).
399403
@FAILED=0; \
@@ -405,7 +409,11 @@ check-crd-compat: crd-schema-checker ## Check CRD backward compatibility against
405409
rm -f "$$BASELINE"; \
406410
continue; \
407411
fi; \
408-
if ! $(CRD_SCHEMA_CHECKER) check-manifests --existing-crd-filename="$$BASELINE" --new-crd-filename="$$crd"; then \
412+
ERRORS=$$($(CRD_SCHEMA_CHECKER) check-manifests \
413+
--existing-crd-filename="$$BASELINE" --new-crd-filename="$$crd" 2>&1 \
414+
| grep -v -E '$(CRD_COMPAT_EMBEDDED_TYPE_RE)' || true); \
415+
if [ -n "$$ERRORS" ]; then \
416+
echo "$$ERRORS"; \
409417
FAILED=1; \
410418
fi; \
411419
rm -f "$$BASELINE"; \

api/v1alpha1/clickhousecluster_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ type ClickHouseClusterSpec struct {
7676
// +optional
7777
// +kubebuilder:validation:Pattern=`^(lts|stable|\d+\.\d+)?$`
7878
UpgradeChannel string `json:"upgradeChannel,omitempty"`
79+
80+
// VersionProbeTemplate overrides for the version detection Job.
81+
// +optional
82+
VersionProbeTemplate *VersionProbeTemplate `json:"versionProbeTemplate,omitempty"`
7983
}
8084

8185
// WithDefaults sets default values for ClickHouseClusterSpec fields.

api/v1alpha1/common.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,91 @@ func formatPodHostname(stsName, serviceName, namespace, domain string) string {
426426

427427
return fmt.Sprintf("%s-0.%s.%s.svc.%s", stsName, serviceName, namespace, domain)
428428
}
429+
430+
// TemplateMeta defines supported metadata settings for template objects.
431+
type TemplateMeta struct {
432+
// Labels are labels applied to the template objects.
433+
// +optional
434+
Labels map[string]string `json:"labels,omitempty"`
435+
// Annotations are annotations applied to the template objects.
436+
// +optional
437+
Annotations map[string]string `json:"annotations,omitempty"`
438+
}
439+
440+
// VersionProbeTemplate defines overrides for the version detection Job.
441+
// The structure mirrors batchv1.JobTemplateSpec, exposing only supported fields.
442+
type VersionProbeTemplate struct {
443+
// Metadata applied to the version probe Job.
444+
// +optional
445+
Metadata TemplateMeta `json:"metadata,omitempty"`
446+
447+
// Specification of the desired behavior of the version probe Job.
448+
// +optional
449+
Spec VersionProbeJobSpec `json:"spec,omitempty"`
450+
}
451+
452+
// VersionProbeJobSpec defines Job-level overrides for the version probe.
453+
type VersionProbeJobSpec struct {
454+
// TTLSecondsAfterFinished limits the lifetime of a completed Job.
455+
// +optional
456+
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`
457+
458+
// Template describes the pod that will be created for the version probe Job.
459+
// +optional
460+
Template VersionProbePodTemplate `json:"template,omitempty"`
461+
}
462+
463+
// VersionProbePodTemplate describes overrides for the version probe Pod.
464+
type VersionProbePodTemplate struct {
465+
// Metadata applied to version probe Pods.
466+
// +optional
467+
Metadata TemplateMeta `json:"metadata,omitempty"`
468+
469+
// Specification of the desired behavior of the version probe Pod.
470+
// +optional
471+
Spec VersionProbePodSpec `json:"spec,omitempty"`
472+
}
473+
474+
// VersionProbePodSpec defines Pod-level overrides for the version probe.
475+
// Field names and JSON tags match corev1.PodSpec for strategic merge patch compatibility.
476+
type VersionProbePodSpec struct {
477+
// NodeSelector constrains the version probe Pod to nodes with matching labels.
478+
// +optional
479+
// +mapType=atomic
480+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
481+
482+
// Tolerations for the version probe Pod.
483+
// +optional
484+
// +listType=atomic
485+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
486+
487+
// SecurityContext holds pod-level security attributes for the version probe Pod.
488+
// +optional
489+
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
490+
491+
// Containers overrides for the version probe Pod.
492+
// The name field is optional — the operator fills it with default container.
493+
// Additional container with the different name may be specified.
494+
// +optional
495+
// +listType=map
496+
// +listMapKey=name
497+
Containers []VersionProbeContainer `json:"containers,omitempty"`
498+
}
499+
500+
// VersionProbeContainer defines container-level overrides for the version probe.
501+
// Field names and JSON tags match corev1.Container so that SMP merges by name.
502+
type VersionProbeContainer struct {
503+
// Name of the container. If empty, the operator sets it to the version probe container name.
504+
// +kubebuilder:default:=version-probe
505+
Name string `json:"name"`
506+
507+
// Resources are the compute resource requirements for the version probe container.
508+
// Deep-merged with operator defaults via SMP.
509+
// +optional
510+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
511+
512+
// SecurityContext defines the security options for the version probe container.
513+
// Deep-merged with operator defaults via SMP.
514+
// +optional
515+
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
516+
}

api/v1alpha1/defaults.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ const (
3333
// DefaultClusterDomain is the default Kubernetes cluster domain suffix for DNS resolution.
3434
DefaultClusterDomain = "cluster.local"
3535
DefaultAccessMode = corev1.ReadWriteOnce
36+
37+
VersionProbeContainerName = "version-probe"
3638
)

api/v1alpha1/keepercluster_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ type KeeperClusterSpec struct {
6464
// +optional
6565
// +kubebuilder:validation:Pattern=`^(lts|stable|\d+\.\d+)?$`
6666
UpgradeChannel string `json:"upgradeChannel,omitempty"`
67+
68+
// VersionProbeTemplate overrides for the version detection Job.
69+
// +optional
70+
VersionProbeTemplate *VersionProbeTemplate `json:"versionProbeTemplate,omitempty"`
6771
}
6872

6973
// WithDefaults sets default values for KeeperClusterSpec fields.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)