8000 release-0.1.0beta by serhii-chechun · Pull Request #4 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11.4 as builder
FROM golang:1.11.5 as builder

WORKDIR /go/src/github.com/altinity/clickhouse-operator

Expand Down
35 changes: 35 additions & 0 deletions docs/examples/chi-example-02-default-pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"
metadata:
name: "test2"
spec:
defaults:
deployment:
volumeClaimTemplate: default
configuration:
clusters:
- name: "sharded-replicated"
layout:
type: Standard
shardsCount: 1
replicasCount: 2
- name: "sharded-non-replicated"
layout:
type: Standard
shardsCount: 2
- name: "replicated"
layout:
type: Standard
replicasCount: 2
templates:
volumeClaimTemplates:
- name: default
template:
metadata:
name: USE_DEFAULT_NAME
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 123Mi
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ kind: "ClickHouseInstallation"
metadata:
name: "clickhouse-installation-test"
spec:
deployment:
zone:
matchLabels:
clickhouse.altinity.com/zone: zone1
podTemplateName: clickhouse-installation
volumeClaimTemplate: default
# scenario: Default
defaults:
deployment:
zone:
matchLabels:
clickhouse.altinity.com/zone: zone1
podTemplateName: clickhouse-installation
volumeClaimTemplate: default
# scenario: Default
#
# default value
# default value
#
configuration:
zookeeper:
Expand Down Expand Up @@ -134,7 +135,8 @@ spec:
# values inherited from .spec.configuration.clusters[3].deployment section
#
replicas:
- deployment:
- port: 9000
deployment:
scenario: Default
# zone:
# matchLabels:
Expand Down Expand Up @@ -164,7 +166,7 @@ spec:
- name: clickhouse-installation
volumes:
- name: clickhouse-data
mountPath: /clickhouse
mountPath: /var/lib/clickhouse
containers:
- name: clickhouse
image: yandex/clickhouse-server:18.14.19-stable
Expand Down
27 changes: 21 additions & 6 deletions pkg/apis/clickhouse.altinity.com/v1/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1

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

Expand All @@ -23,17 +24,23 @@ type ChiStatus struct {

// ChiSpec defines spec section of ClickHouseInstallation resource
type ChiSpec struct {
Deployment ChiDeployment `json:"deployment,omitempty"`
Defaults ChiDefaults `json:"defaults,omitempty"`
Configuration ChiConfiguration `json:"configuration"`
Templates ChiTemplates `json:"templates,omitempty"`
}

// ChiDefaults defines defaults section of .spec
type ChiDefaults struct {
Deployment ChiDeployment `json:"deployment,omitempty"`
}

// ChiDeployment defines deployment section of .spec
type ChiDeployment struct {
PodTemplateName string `json:"podTemplateName,omitempty"`
Zone ChiDeploymentZone `json:"zone,omitempty"`
Scenario string `json:"scenario,omitempty"`
Key string // used internally by pkg/parser
PodTemplateName string `json:"podTemplateName,omitempty"`
VolumeClaimTemplate string `json:"volumeClaimTemplate,omitempty"`
Zone ChiDeploymentZone `json:"zone,omitempty"`
Scenario string `json:"scenario,omitempty"`
Key string // used internally by pkg/parser
}

// ChiDeploymentZone defines zone section of *.deployment
Expand Down Expand Up @@ -87,12 +94,20 @@ type ChiClusterLayoutShard struct {

// ChiClusterLayoutShardReplica defines item of a replicas section of .spec.configuration.clusters[n].shards[m]
type ChiClusterLayoutShardReplica struct {
Port int32 `json:"port,omitempty"`
Deployment ChiDeployment `json:"deployment,omitempty"`
}

// ChiTemplates defines templates section of .spec
type ChiTemplates struct {
PodTemplates []ChiPodTemplate `json:"podTemplates,omitempty"`
PodTemplates []ChiPodTemplate `json:"podTemplates,omitempty"`
VolumeClaimTemplates []ChiVolumeClaimTemplate `json:"volumeClaimTemplates,omitempty"`
}

// ChiVolumeClaimTemplate defines item of .spec.templates.volumeClaimTemplates
type ChiVolumeClaimTemplate struct {
Name string `json:"name"`
Template corev1.PersistentVolumeClaim `json:"template"`
}

// ChiPodTemplate defines item of a podTemplates section of .spec.templates
Expand Down
43 changes: 42 additions & 1 deletion pkg/apis/clickhouse.altinity.com/v1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ func (in *ChiConfigurationZookeeperNode) DeepCopy() *ChiConfigurationZookeeperNo
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ChiDefaults) DeepCopyInto(out *ChiDefaults) {
*out = *in
in.Deployment.DeepCopyInto(&out.Deployment)
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChiDefaults.
func (in *ChiDefaults) DeepCopy() *ChiDefaults {
if in == nil {
return nil
}
out := new(ChiDefaults)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ChiDeployment) DeepCopyInto(out *ChiDeployment) {
*out = *in
Expand Down Expand Up @@ -296,7 +313,7 @@ func (in *ChiPodTemplatesContainerTemplateResParams) DeepCopy() *ChiPodTemplates
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ChiSpec) DeepCopyInto(out *ChiSpec) {
*out = *in
in.Deployment.DeepCopyInto(&out.Deployment)
in.Defaults.DeepCopyInto(&out.Defaults)
in.Configuration.DeepCopyInto(&out.Configuration)
in.Templates.DeepCopyInto(&out.Templates)
return
Expand Down Expand Up @@ -343,6 +360,13 @@ func (in *ChiTemplates) DeepCopyInto(out *ChiTemplates) {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.VolumeClaimTemplates != nil {
in, out := &in.VolumeClaimTemplates, &out.VolumeClaimTemplates
*out = make([]ChiVolumeClaimTemplate, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}

Expand All @@ -356,6 +380,23 @@ func (in *ChiTemplates) DeepCopy() *ChiTemplates {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ChiVolumeClaimTemplate) DeepCopyInto(out *ChiVolumeClaimTemplate) {
*out = *in
in.Template.DeepCopyInto(&out.Template)
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChiVolumeClaimTemplate.
func (in *ChiVolumeClaimTemplate) DeepCopy() *ChiVolumeClaimTemplate {
if in == nil {
return nil
}
out := new(ChiVolumeClaimTemplate)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ClickHouseInstallation) DeepCopyInto(out *ClickHouseInstallation) {
*out = *in
Expand Down
24 changes: 13 additions & 11 deletions pkg/controllers/chi/chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ func (c *Controller) syncHandler(key string) error {
return err
}
if chi.Status.ObjectPrefixes == nil || len(chi.Status.ObjectPrefixes) == 0 {
chiObjects, prefixes := parser.CreateObjects(chi)
if err := c.createControlledResources(chi, chiObjects); err != nil {
prefixes, err := c.createControlledResources(chi)
if err != nil {
glog.V(2).Infof("ClickHouseInstallation (%q) unable to create controlled resources: %q", chi.Name, err)
return err
}
Expand All @@ -181,30 +181,32 @@ func (c *Controller) syncHandler(key string) error {
return nil
}

func (c *Controller) createControlledResources(chi *chiv1.ClickHouseInstallation, oMap parser.ObjectsMap) error {
for _, objList := range oMap {
func (c *Controller) createControlledResources(chi *chiv1.ClickHouseInstallation) ([]string, error) {
chiCopy := chi.DeepCopy()
chiObjects, prefixes := parser.CreateObjects(chiCopy)
for _, objList := range chiObjects {
switch v := objList.(type) {
case parser.ConfigMapList:
for _, obj := range v {
if err := c.createConfigMap(chi, obj); err != nil {
return err
if err := c.createConfigMap(chiCopy, obj); err != nil {
return nil, err
}
}
case parser.ServiceList:
for _, obj := range v {
if err := c.createService(chi, obj); err != nil {
return err
if err := c.createService(chiCopy, obj); err != nil {
return nil, err
}
}
case parser.StatefulSetList:
for _, obj := range v {
if err := c.createStatefulSet(chi, obj); err != nil {
return err
if err := c.createStatefulSet(chiCopy, obj); err != nil {
return nil, err
}
}
}
}
return nil
return prefixes, nil
}

func (c *Controller) createConfigMap(chi *chiv1.ClickHouseInstallation, newConfigMap *corev1.ConfigMap) error {
Expand Down
73 changes: 73 additions & 0 deletions pkg/parser/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package parser

const (
// ObjectsConfigMaps defines a category of the ConfigMap objects list
ObjectsConfigMaps ObjectKind = iota + 1
// ObjectsStatefulSets defines a category of the StatefulSet objects list
ObjectsStatefulSets
// ObjectsServices defines a category of the Service objects list
ObjectsServices
)

const (
clusterLayoutTypeStandard = "Standard"
clusterLayoutTypeAdvanced = "Advanced"
)

const (
shardDefinitionTypeReplicasCount = "ReplicasCount"
shardDefinitionTypeReplicas = "Replicas"
)

const (
deploymentScenarioDefault = "Default"
deploymentScenarioNodeMonopoly = "NodeMonopoly"
)

const (
shardInternalReplicationDisabled = "Disabled"
stringTrue = "true"
stringFalse = "false"
)

const (
remoteServersXML = "remote_servers.xml"
zookeeperXML = "zookeeper.xml"
usersXML = "users.xml"
)

const (
ssNamePattern = "chi-%s-%s-i%d"
svcNamePattern = "%s-service"
hostnamePattern = "%s-0.%[1]s-service.%s.svc.cluster.local"
configMapNamePattern = "chi-%s-configd"
)

const (
chDefaultDockerImage = "yandex/clickhouse-server:latest"
chDefaultVolumeMountNameData = "clickhouse-data"
)

const (
useDefaultNamePlaceholder = "USE_DEFAULT_NAME"
)

const (
chDefaultRPCPortName = "rpc"
chDefaultRPCPortNumber = 9000
chDefaultInterServerPortName = "interserver"
chDefaultInterServerPortNumber = 9009
chDefaultRestPortName = "rest"
chDefaultRestPortNumber = 8123
chDefaultAppLabel = "app"
)

const (
fullPathRemoteServersXML = "/etc/clickhouse-server/config.d/" + remoteServersXML
fullPathClickHouseData = "/var/lib/clickhouse"
)

const (
templateDefaultsServiceClusterIP = "None"
templateDefaultsVolumeClaimAccessMode = "ReadWriteOnce"
)
Loading
0