Skip to content

Commit 3043f8a

Browse files
author
qzuo
committed
make namespaceNamePattern and statefulsetName configurable
Signed-off-by: qzuo <[email protected]>
1 parent ab5ed0b commit 3043f8a

13 files changed

+308
-10
lines changed

Diff for: deploy/dev/clickhouse-operator-install-dev.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
- "disabled"
9898
- "Enabled"
9999
- "enabled"
100+
namespaceDomainPattern:
101+
type: string
100102
defaults:
101103
type: object
102104
properties:
@@ -509,6 +511,8 @@ spec:
509511
properies:
510512
name:
511513
type: string
514+
generateName:
515+
type: string
512516
zone:
513517
type: object
514518
required:
@@ -726,6 +730,8 @@ spec:
726730
- "disabled"
727731
- "Enabled"
728732
- "enabled"
733+
namespaceDomainPattern:
734+
type: string
729735
defaults:
730736
type: object
731737
properties:
@@ -1138,6 +1144,8 @@ spec:
11381144
properies:
11391145
name:
11401146
type: string
1147+
generateName:
1148+
type: string
11411149
zone:
11421150
type: object
11431151
required:

Diff for: deploy/dev/clickhouse-operator-install-yaml-template-01-section-crd-01-chi.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
- "disabled"
9898
- "Enabled"
9999
- "enabled"
100+
namespaceDomainPattern:
101+
type: string
100102
defaults:
101103
type: object
102104
properties:
@@ -509,6 +511,8 @@ spec:
509511
properies:
510512
name:
511513
type: string
514+
generateName:
515+
type: string
512516
zone:
513517
type: object
514518
required:

Diff for: deploy/dev/clickhouse-operator-install-yaml-template-01-section-crd-02-chit.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
- "disabled"
9898
- "Enabled"
9999
- "enabled"
100+
namespaceDomainPattern:
101+
type: string
100102
defaults:
101103
type: object
102104
properties:
@@ -509,6 +511,8 @@ spec:
509511
properies:
510512
name:
511513
type: string
514+
generateName:
515+
type: string
512516
zone:
513517
type: object
514518
required:

Diff for: deploy/operator/clickhouse-operator-install-crd.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
- "disabled"
9898
- "Enabled"
9999
- "enabled"
100+
namespaceDomainPattern:
101+
type: string
100102
defaults:
101103
type: object
102104
properties:
@@ -509,6 +511,8 @@ spec:
509511
properies:
510512
name:
511513
type: string
514+
generateName:
515+
type: string
512516
zone:
513517
type: object
514518
required:
@@ -726,6 +730,8 @@ spec:
726730
- "disabled"
727731
- "Enabled"
728732
- "enabled"
733+
namespaceDomainPattern:
734+
type: string
729735
defaults:
730736
type: object
731737
properties:
@@ -1138,6 +1144,8 @@ spec:
11381144
properies:
11391145
name:
11401146
type: string
1147+
generateName:
1148+
type: string
11411149
zone:
11421150
type: object
11431151
required:

Diff for: deploy/operator/clickhouse-operator-install-template-crd.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
- "disabled"
9898
- "Enabled"
9999
- "enabled"
100+
namespaceDomainPattern:
101+
type: string
100102
defaults:
101103
type: object
102104
properties:
@@ -509,6 +511,8 @@ spec:
509511
properies:
510512
name:
511513
type: string
514+
generateName:
515+
type: string
512516
zone:
513517
type: object
514518
required:
@@ -726,6 +730,8 @@ spec:
726730
- "disabled"
727731
- "Enabled"
728732
- "enabled"
733+
namespaceDomainPattern:
734+
type: string
729735
defaults:
730736
type: object
731737
properties:
@@ -1138,6 +1144,8 @@ spec:
11381144
properies:
11391145
name:
11401146
type: string
1147+
generateName:
1148+
type: string
11411149
zone:
11421150
type: object
11431151
required:

Diff for: deploy/operator/clickhouse-operator-install-template.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
- "disabled"
9898
- "Enabled"
9999
- "enabled"
100+
namespaceDomainPattern:
101+
type: string
100102
defaults:
101103
type: object
102104
properties:
@@ -509,6 +511,8 @@ spec:
509511
properies:
510512
name:
511513
type: string
514+
generateName:
515+
type: string
512516
zone:
513517
type: object
514518
required:
@@ -726,6 +730,8 @@ spec:
726730
- "disabled"
727731
- "Enabled"
728732
- "enabled"
733+
namespaceDomainPattern:
734+
type: string
729735
defaults:
730736
type: object
731737
properties:
@@ -1138,6 +1144,8 @@ spec:
11381144
properies:
11391145
name:
11401146
type: string
1147+
generateName:
1148+
type: string
11411149
zone:
11421150
type: object
11431151
required:

Diff for: deploy/operator/clickhouse-operator-install.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
- "disabled"
9898
- "Enabled"
9999
- "enabled"
100+
namespaceDomainPattern:
101+
type: string
100102
defaults:
101103
type: object
102104
properties:
@@ -509,6 +511,8 @@ spec:
509511
properies:
510512
name:
511513
type: string
514+
generateName:
515+
type: string
512516
zone:
513517
type: object
514518
required:
@@ -726,6 +730,8 @@ spec:
726730
- "disabled"
727731
- "Enabled"
728732
- "enabled"
733+
namespaceDomainPattern:
734+
type: string
729735
defaults:
730736
type: object
731737
properties:
@@ -1138,6 +1144,8 @@ spec:
11381144
properies:
11391145
name:
11401146
type: string
1147+
generateName:
1148+
type: string
11411149
zone:
11421150
type: object
11431151
required:

Diff for: docs/chi-examples/18-namespace-domain-pattern.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: "clickhouse.altinity.com/v1"
2+
kind: "ClickHouseInstallation"
3+
metadata:
4+
name: "namespace-domain-pattern"
5+
spec:
6+
namespaceDomainPattern: "%s.svc"
7+
configuration:
8+
clusters:
9+
- name: "shard1-repl2"
10+
layout:
11+
shardsCount: 1
12+
replicasCount: 2

Diff for: docs/chi-examples/19-pod-generate-name.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: "clickhouse.altinity.com/v1"
2+
kind: "ClickHouseInstallation"
3+
metadata:
4+
name: "pod-generate-name"
5+
spec:
6+
configuration:
7+
clusters:
8+
- name: shard1-repl1
9+
templates:
10+
podTemplate: clickhouse-pod-template
11+
layout:
12+
shardsCount: 1
13+
replicasCount: 1
14+
templates:
15+
podTemplates:
16+
- name: clickhouse-pod-template
17+
generateName: "chi-{chi}-{cluster}-{host}"
18+
spec:
19+
containers:
20+
- name: clickhouse-pod
21+
image: yandex/clickhouse-server:19.16.10.44
22+
volumeMounts:
23+
- name: clickhouse-storage-template
24+
mountPath: /var/lib/clickhouse

Diff for: pkg/apis/clickhouse.altinity.com/v1/type_chi.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
package v1
1616

1717
import (
18-
"github.com/altinity/clickhouse-operator/pkg/version"
1918
"math"
19+
20+
"github.com/altinity/clickhouse-operator/pkg/version"
2021
)
2122

2223
// fillStatus fills .Status
@@ -448,11 +449,17 @@ func (spec *ChiSpec) MergeFrom(from *ChiSpec, _type MergeType) {
448449
if spec.Stop == "" {
449450
spec.Stop = from.Stop
450451
}
452+
if spec.NamespaceDomainPattern == "" {
453+
spec.NamespaceDomainPattern = from.NamespaceDomainPattern
454+
}
451455
case MergeTypeOverrideByNonEmptyValues:
452456
if from.Stop != "" {
453457
// Override by non-empty values only
454458
spec.Stop = from.Stop
455459
}
460+
if from.NamespaceDomainPattern != "" {
461+
spec.NamespaceDomainPattern = from.NamespaceDomainPattern
462+
}
456463
}
457464

458465
(&spec.Defaults).MergeFrom(&from.Defaults, _type)

Diff for: pkg/apis/clickhouse.altinity.com/v1/types.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ type ClickHouseOperatorConfiguration struct {
5757

5858
// ChiSpec defines spec section of ClickHouseInstallation resource
5959
type ChiSpec struct {
60-
Stop string `json:"stop,omitempty" yaml:"stop"`
61-
Defaults ChiDefaults `json:"defaults,omitempty" yaml:"defaults"`
62-
Configuration ChiConfiguration `json:"configuration" yaml:"configuration"`
63-
Templates ChiTemplates `json:"templates,omitempty" yaml:"templates"`
64-
UseTemplates []ChiUseTemplate `json:"useTemplates,omitempty" yaml:"useTemplates"`
60+
Stop string `json:"stop,omitempty" yaml:"stop"`
61+
NamespaceDomainPattern string `json:"namespaceDomainPattern,omitempty" yaml:"namespaceDomainPattern"`
62+
Defaults ChiDefaults `json:"defaults,omitempty" yaml:"defaults"`
63+
Configuration ChiConfiguration `json:"configuration" yaml:"configuration"`
64+
Templates ChiTemplates `json:"templates,omitempty" yaml:"templates"`
65+
UseTemplates []ChiUseTemplate `json:"useTemplates,omitempty" yaml:"useTemplates"`
6566
}
6667

6768
// ChiUseTemplates defines UseTemplates section of ClickHouseInstallation resource
@@ -281,8 +282,9 @@ type ChiTemplates struct {
281282

282283
// ChiPodTemplate defines full Pod Template, directly used by StatefulSet
283284
type ChiPodTemplate struct {
284-
Name string `json:"name" yaml:"name"`
285-
Zone ChiPodTemplateZone `json:"zone" yaml:"zone""`
285+
Name string `json:"name" yaml:"name"`
286+
GenerateName string `json:"generateName,omitempty" yaml:"generateName"`
287+
Zone ChiPodTemplateZone `json:"zone" yaml:"zone""`
286288
// DEPRECATED - to be removed soon
287289
Distribution string `json:"distribution" yaml:"distribution"`
288290
PodDistribution []ChiPodDistribution `json:"podDistribution" yaml:"podDistribution"`

Diff for: pkg/model/namer.go

+29-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ package model
1616

1717
import (
1818
"fmt"
19+
"strconv"
20+
"strings"
21+
1922
chop "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
2023
"github.com/altinity/clickhouse-operator/pkg/util"
2124
apps "k8s.io/api/apps/v1"
22-
"strconv"
23-
"strings"
2425
)
2526

2627
const (
@@ -503,6 +504,15 @@ func CreateCHIServiceName(chi *chop.ClickHouseInstallation) string {
503504

504505
// CreateCHIServiceName creates a name of a Installation Service resource
505506
func CreateChiServiceFQDN(chi *chop.ClickHouseInstallation) string {
507+
if chi.Spec.NamespaceDomainPattern != "" {
508+
// NamespaceDomainPattern has been explicitly specified
509+
return fmt.Sprintf(
510+
"%s."+chi.Spec.NamespaceDomainPattern,
511+
CreateCHIServiceName(chi),
512+
chi.Namespace,
513+
)
514+
}
515+
506516
return fmt.Sprintf(
507517
serviceFQDNPattern,
508518
CreateCHIServiceName(chi),
@@ -594,6 +604,15 @@ func IsAutoGeneratedHostName(
594604

595605
// CreateStatefulSetName creates a name of a StatefulSet for ClickHouse instance
596606
func CreateStatefulSetName(host *chop.ChiHost) string {
607+
if template, ok := host.GetPodTemplate(); ok {
608+
// Pod template available
609+
if template.GenerateName != "" {
610+
// Pod template has explicitly specified pod name template
611+
return newNameMacroReplacerHost(host).Replace(template.GenerateName)
612+
}
613+
}
614+
615+
// Create Statefulset name based on default Statefulset Name template
597616
return newNameMacroReplacerHost(host).Replace(statefulSetNamePattern)
598617
}
599618

@@ -620,6 +639,14 @@ func CreatePodHostname(host *chop.ChiHost) string {
620639
// CreatePodFQDN creates a fully qualified domain name of a pod
621640
// ss-1eb454-2-0.my-dev-domain.svc.cluster.local
622641
func CreatePodFQDN(host *chop.ChiHost) string {
642+
if host.CHI.Spec.NamespaceDomainPattern != "" {
643+
return fmt.Sprintf(
644+
"%s."+host.CHI.Spec.NamespaceDomainPattern,
645+
CreatePodHostname(host),
646+
host.Address.Namespace,
647+
)
648+
}
649+
623650
return fmt.Sprintf(
624651
podFQDNPattern,
625652
CreatePodHostname(host),

0 commit comments

Comments
 (0)