Skip to content

Commit

Permalink
Add DisableSecurity Support for ClickHouse
Browse files Browse the repository at this point in the history
Signed-off-by: SK Ali Arman <[email protected]>
  • Loading branch information
sheikh-arman committed Sep 25, 2024
1 parent f15802f commit c78368b
Show file tree
Hide file tree
Showing 12 changed files with 3,969 additions and 101 deletions.
10 changes: 6 additions & 4 deletions clickhouse/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"database/sql"
"fmt"

olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

_ "github.com/ClickHouse/clickhouse-go/v2"
core "k8s.io/api/core/v1"
"k8s.io/klog/v2"
"kubedb.dev/apimachinery/apis/kubedb"
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -95,15 +95,17 @@ func (o *KubeDBClientBuilder) getURL() string {
}

func (o *KubeDBClientBuilder) getPort() *int {
chPort := 9000
chPort := kubedb.ClickHouseNativeTCP
return &chPort
}

func (o *KubeDBClientBuilder) getClickHouseRootCredentials() (string, string, error) {
db := o.db
var secretName string
if db.Spec.AuthSecret != nil {
if !db.Spec.DisableSecurity {
secretName = db.GetAuthSecretName()
} else {
return kubedb.ClickHouseDefaultUser, "", nil
}
var secret core.Secret
err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: db.Namespace, Name: secretName}, &secret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type ClickHouseVersionSpec struct {
// Database Image
InitContainer ClickHouseInitContainer `json:"initContainer"`

// ClickHouse Keeper Image
ClickHouseKeeper ClickHouseKeeperContainer `json:"clickHouseKeeper"`

// SecurityContext is for the additional config for the DB container
// +optional
SecurityContext SecurityContext `json:"securityContext"`
Expand All @@ -81,6 +84,11 @@ type ClickHouseInitContainer struct {
Image string `json:"image"`
}

// ClickHouseKeeperContainer is the ClickHouse keeper Container image
type ClickHouseKeeperContainer struct {
Image string `json:"image"`
}

// ClickHouseVersionStatus defines the observed state of ClickHouseVersion
type ClickHouseVersionStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down

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

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

72 changes: 58 additions & 14 deletions vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,36 +1313,71 @@ const (
ClickHouseNativeTCP = 9000
ClickHouseNativeTLS = 9440
ClickhousePromethues = 9363
ClickHouseRaftPort = 9234

ClickHousePromethusEndpoint = "/metrics"
ClickHouseDataDir = "/var/lib/clickhouse"
ClickHouseKeeperDataDir = "/var/lib/clickhouse_keeper"
ClickHouseConfigDir = "/etc/clickhouse-server/config.d"
ClickHouseKeeperConfigDir = "/etc/clickhouse-keeper"
ClickHouseCommonConfigDir = "/etc/clickhouse-server/conf.d"
ClickHouseTempConfigDir = "/ch-tmp"
ClickHouseInternalKeeperTempConfigDir = "/keeper"
ClickHouseTempDir = "/ch-tmp"
ClickHouseKeeperTempDir = "/ch-tmp"
ClickHouseKeeperConfigPath = "/etc/clickhouse-keeper"
ClickHouseUserConfigDir = "/etc/clickhouse-server/user.d"
ClickHouseLogPath = "/var/log/clickhouse-server/clickhouse-server.log"
ClickHouseErrorLogPath = "/var/log/clickhouse-server/clickhouse-server.err.log"

// keeper
ClickHouseKeeperDataPath = "/var/lib/clickhouse_keeper"
ClickHouseKeeperLogPath = "/var/lib/clickhouse_keeper/coordination/logs"
ClickHouseKeeperSnapshotPath = "/var/lib/clickhouse_keeper/coordination/snapshots"

ClickHouseInternalKeeperDataPath = "/var/lib/clickhouse/coordination/log"
ClickHouseInternalKeeperSnapshotPath = "/var/lib/clickhouse/coordination/snapshots"

ComponentCoOrdinator = "co-ordinator"
ClickHouseVolumeData = "data"
ClickHouseDefaultUser = "default"

ClickHouseConfigVolumeName = "clickhouse-config"
ClickHouseKeeperConfigVolumeName = "clickhouse-keeper-config"
ClickHouseInternalKeeperConfigVolumeName = "clickhouse-internal-keeper-config"

ClickHouseVolumeData = "data"
ClickHouseDataDir = "/var/lib/clickhouse"
ClickHouseConfigVolName = "clickhouse-config"
ClickHouseConfigDir = "/etc/clickhouse-server/config.d"
ClickHouseDefaultStorageSize = "2Gi"

ClickHouseClusterConfigVolName = "cluster-config"
ClickHouseClusterConfigDir = "/etc/clickhouse-server/conf.d"

ClickHouseTempClusterConfigVolName = "temp-cluster-config"
ClickHouseClusterTempConfigVolName = "temp-cluster-config"

ClickHouseContainerName = "clickhouse"
ClickHouseInitContainerName = "clickhouse-init"

ClickHouseClusterConfigFile = "cluster-config.yaml"
ClickHouseTempConfigDir = "/ch-tmp/config"
ClickHouseTempDir = "/ch-tmp"

ClickHouseUserConfigDir = "/etc/clickhouse-server/user.d"
ClickHouseMacrosFileName = "macros.yaml"

ClickHouseStandalone = "standalone"
ClickHouseCluster = "cluster"

ClickHouseHealthCheckerDatabase = "kubedb_system_db"
ClickHouseHealthCheckerTable = "kubedb_system_table"

ClickHouseServerConfigFile = "server-config.yaml"
ClickHouseKeeperFileConfig = "keeper-config.yaml"
ClickHouseHealthCheckerDatabase = "kubedb_system"
ClickHouseHealthCheckerTable = "kubedb_write_check"

ClickHouseServerConfigFile = "server-config.yaml"
ClickHouseKeeperFileConfig = "keeper_config.yaml"
ClickHouseVolumeCustomConfig = "custom-config"

// keeper
ClickHouseKeeperContainerName = "clickhouse-keeper"
ClickHouseKeeeprConfigFileName = "keeper_config.xml"
ClickHOuseKeeeprConfigFileVolumeName = "keeper-config"
ClickHouseKeeperInitContainerName = "clickhouse-keeper-init"
ClickHouseKeeperConfig = "etc-clickhouse-keeper"
ClickHouseInternalServerListFile = "server_list.yaml"
ClickHouseKeeperServerIdNo = "serverid"
ClickHouseKeeperServerID = "KEEPERID"
)

// =========================== Cassandra Constants ============================
Expand Down Expand Up @@ -1439,6 +1474,15 @@ var (
core.ResourceMemory: resource.MustParse("1024Mi"),
},
}
ClickHouseDefaultResources = core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse("1"),
core.ResourceMemory: resource.MustParse("3Gi"),
},
Limits: core.ResourceList{
core.ResourceMemory: resource.MustParse("6Gi"),
},
}
// CoordinatorDefaultResources must be used for raft backed coordinators to avoid unintended leader switches
CoordinatorDefaultResources = core.ResourceRequirements{
Requests: core.ResourceList{
Expand Down
Loading

0 comments on commit c78368b

Please sign in to comment.