Skip to content

Commit

Permalink
Update for ops requests
Browse files Browse the repository at this point in the history
Signed-off-by: Tapajit Chandra Paul <[email protected]>
  • Loading branch information
tapojit047 committed Oct 9, 2024
1 parent 9889c2e commit 57307e7
Show file tree
Hide file tree
Showing 10 changed files with 604 additions and 64 deletions.
35 changes: 17 additions & 18 deletions apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,15 +966,16 @@ const (
DruidConfigDirRouters = "/opt/druid/conf/druid/cluster/query/router"
DruidCConfigDirMySQLMetadata = "/opt/druid/extensions/mysql-metadata-storage"

DruidVolumeOperatorConfig = "operator-config-volume"
DruidVolumeMainConfig = "main-config-volume"
DruidVolumeCustomConfig = "custom-config"
DruidMetadataTLSVolume = "metadata-tls-volume"
DruidVolumeOperatorConfig = "operator-config-volume"
DruidVolumeMainConfig = "main-config-volume"
DruidVolumeCustomConfig = "custom-config"
DruidMetadataTLSVolume = "metadata-tls-volume"
DruidMetadataTLSTempVolume = "metadata-tls-volume-temp"

DruidOperatorConfigDir = "/tmp/config/operator-config"
DruidMainConfigDir = "/opt/druid/conf"
DruidCustomConfigDir = "/tmp/config/custom-config"
DruidMetadataTLSConfigDir = "/tmp/metadata-tls"
DruidOperatorConfigDir = "/tmp/config/operator-config"
DruidMainConfigDir = "/opt/druid/conf"
DruidCustomConfigDir = "/tmp/config/custom-config"
DruidMetadataTLSTempConfigDir = "/tmp/metadata-tls"

DruidVolumeCommonConfig = "common-config-volume"
DruidCommonConfigFile = "common.runtime.properties"
Expand Down Expand Up @@ -1064,26 +1065,24 @@ const (
DruidValueTrue = "true"
DruidValueFalse = "false"

DruidCertDir = "/opt/druid/ssl"
DruidCertDir = "/opt/druid/ssl"
DruidCertMetadataSubDir = "metadata"

// MySQL TLS
DruidMetadataMySQLUseSSL = "druid.metadata.mysql.ssl.useSSL"
DruidMetadataMySQLClientCertKeyStoreURL = "druid.metadata.mysql.ssl.clientCertificateKeyStoreUrl"
DruidMetadataMySQLClientCertKeyStorePath = "/opt/druid/conf/tls/metadatakeystore.jks"
DruidMetadataMySQLClientCertKeyStoreType = "druid.metadata.mysql.ssl.clientCertificateKeyStoreType"
DruidMetadataMySQLClientCertKeyStoreTypeJKS = "JKS"
DruidMetadataMySQLClientCertKeyStorePassword = "druid.metadata.mysql.ssl.clientCertificateKeyStorePassword"
DruidMetadataMySQLClientCertKeyStorePasswordValue = "password"

// Postgres TLS
DruidMetadataPostgresUseSSL = "druid.metadata.postgres.ssl.useSSL"
DruidMetadataPGUseSSLMode = "druid.metadata.postgres.ssl.sslMode"
DruidMetadataPGSSLCert = "druid.metadata.postgres.ssl.sslCert"
DruidMetadataPGSSLCertPath = "/opt/druid/conf/tls/tls.crt"
DruidMetadataPGSSLKey = "druid.metadata.postgres.ssl.sslKey"
DruidMetadataPGSSLKeyPath = "/opt/druid/conf/tls/tls.key"
DruidMetadataPGSSLRootCert = "druid.metadata.postgres.ssl.sslRootCert"
DruidMetadataPGSSLRootCertPath = "/opt/druid/conf/tls/ca.cert"
DruidMetadataPostgresUseSSL = "druid.metadata.postgres.ssl.useSSL"
DruidMetadataPGUseSSLMode = "druid.metadata.postgres.ssl.sslMode"
DruidMetadataPGUseSSLModeVerifyFull = "verify-full"
DruidMetadataPGSSLCert = "druid.metadata.postgres.ssl.sslCert"
DruidMetadataPGSSLKey = "druid.metadata.postgres.ssl.sslKey"
DruidMetadataPGSSLRootCert = "druid.metadata.postgres.ssl.sslRootCert"

// Deep Storage
DruidDeepStorageTypeKey = "druid.storage.type"
Expand Down
50 changes: 25 additions & 25 deletions apis/kubedb/v1alpha2/druid_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (d *Druid) ServiceLabels(alias ServiceAlias, extraLabels ...map[string]stri
return d.offShootLabels(meta_util.OverwriteKeys(d.OffShootSelectors(), extraLabels...), svcTemplate.Labels)
}

func (r *Druid) Finalizer() string {
return fmt.Sprintf("%s/%s", apis.Finalizer, r.ResourceSingular())
func (d *Druid) Finalizer() string {
return fmt.Sprintf("%s/%s", apis.Finalizer, d.ResourceSingular())
}

func (d *Druid) DefaultUserCredSecretName(username string) string {
Expand Down Expand Up @@ -209,21 +209,23 @@ func (d *Druid) PodControllerLabels(nodeType DruidNodeRoleType, extraLabels ...m
}

func (d *Druid) GetNodeSpec(nodeType DruidNodeRoleType) (*DruidNode, *DruidDataNode) {
if nodeType == DruidNodeRoleCoordinators {
switch nodeType {
case DruidNodeRoleCoordinators:
return d.Spec.Topology.Coordinators, nil
} else if nodeType == DruidNodeRoleOverlords {
case DruidNodeRoleOverlords:
return d.Spec.Topology.Overlords, nil
} else if nodeType == DruidNodeRoleMiddleManagers {
case DruidNodeRoleMiddleManagers:
return nil, d.Spec.Topology.MiddleManagers
} else if nodeType == DruidNodeRoleHistoricals {
case DruidNodeRoleHistoricals:
return nil, d.Spec.Topology.Historicals
} else if nodeType == DruidNodeRoleBrokers {
case DruidNodeRoleBrokers:
return d.Spec.Topology.Brokers, nil
} else if nodeType == DruidNodeRoleRouters {
case DruidNodeRoleRouters:
return d.Spec.Topology.Routers, nil
default:
klog.Errorf("unknown druid node role %s\n", nodeType)
return nil, nil
}

panic("Node role name does not match any known types")
}

func (d *Druid) ServiceAccountName() string {
Expand Down Expand Up @@ -255,7 +257,7 @@ func (d *Druid) DruidNodeContainerPort(nodeRole DruidNodeRoleType) int32 {
case DruidNodeRoleRouters:
return kubedb.DruidPlainTextPortRouters
default:
panic("Node role name does not match any known types")
klog.Errorf("unknown druid node role %s\n", nodeRole)
}
} else {
switch nodeRole {
Expand All @@ -272,9 +274,10 @@ func (d *Druid) DruidNodeContainerPort(nodeRole DruidNodeRoleType) int32 {
case DruidNodeRoleRouters:
return kubedb.DruidTLSPortRouters
default:
panic("Node role name does not match any known types")
klog.Errorf("unknown node role %s\n", nodeRole)
}
}
return -1
}

func (d *Druid) SetHealthCheckerDefaults() {
Expand Down Expand Up @@ -347,7 +350,8 @@ func (d *Druid) GetMetadataStorageType(metadataStorage string) DruidMetadataStor
metadataStorage == kubedb.DruidMetadataStorageTypePostgres || metadataStorage == strings.ToLower(string(kubedb.DruidMetadataStorageTypePostgres)) {
return DruidMetadataStoragePostgreSQL
} else {
panic(fmt.Sprintf("Unknown metadata storage type: %s", metadataStorage))
klog.Errorf("Unknown metadata storage type: %s", metadataStorage)
return ""
}
}

Expand Down Expand Up @@ -392,11 +396,11 @@ func (d *Druid) OffshootSelectors(extraSelectors ...map[string]string) map[strin
return meta_util.OverwriteKeys(selector, extraSelectors...)
}

func (d Druid) OffshootLabels() map[string]string {
func (d *Druid) OffshootLabels() map[string]string {
return d.offshootLabels(d.OffshootSelectors(), nil)
}

func (d Druid) offshootLabels(selector, override map[string]string) map[string]string {
func (d *Druid) offshootLabels(selector, override map[string]string) map[string]string {
selector[meta_util.ComponentLabelKey] = kubedb.ComponentDatabase
return meta_util.FilterKeys(kubedb.GroupName, selector, meta_util.OverwriteKeys(nil, d.Labels, override))
}
Expand All @@ -423,11 +427,7 @@ func (d *Druid) SetDefaults() {
d.Spec.DeletionPolicy = TerminationPolicyDelete
}

if d.Spec.DisableSecurity == nil {
d.Spec.DisableSecurity = pointer.BoolP(false)
}

if !*d.Spec.DisableSecurity {
if !d.Spec.DisableSecurity {
if d.Spec.AuthSecret == nil {
d.Spec.AuthSecret = &v1.LocalObjectReference{
Name: d.DefaultUserCredSecretName(kubedb.DruidUserAdmin),
Expand Down Expand Up @@ -583,12 +583,12 @@ func (d *Druid) SetDefaults() {
}
}

func (k *Druid) SetTLSDefaults() {
if k.Spec.TLS == nil || k.Spec.TLS.IssuerRef == nil {
func (d *Druid) SetTLSDefaults() {
if d.Spec.TLS == nil || d.Spec.TLS.IssuerRef == nil {
return
}
k.Spec.TLS.Certificates = kmapi.SetMissingSecretNameForCertificate(k.Spec.TLS.Certificates, string(DruidServerCert), k.CertificateName(DruidServerCert))
k.Spec.TLS.Certificates = kmapi.SetMissingSecretNameForCertificate(k.Spec.TLS.Certificates, string(DruidClientCert), k.CertificateName(DruidClientCert))
d.Spec.TLS.Certificates = kmapi.SetMissingSecretNameForCertificate(d.Spec.TLS.Certificates, string(DruidServerCert), d.CertificateName(DruidServerCert))
d.Spec.TLS.Certificates = kmapi.SetMissingSecretNameForCertificate(d.Spec.TLS.Certificates, string(DruidClientCert), d.CertificateName(DruidClientCert))
}

func (d *Druid) SetDefaultsToMetadataStorage() {
Expand Down Expand Up @@ -801,6 +801,6 @@ func (d *Druid) CertSecretVolumeName(alias DruidCertificateAlias) string {
// CertSecretVolumeMountPath returns the CertSecretVolumeMountPath
// if configDir is "/var/druid/ssl",
// mountPath will be, "/var/druid/ssl/<alias>".
func (k *Druid) CertSecretVolumeMountPath(configDir string, cert string) string {
func (d *Druid) CertSecretVolumeMountPath(configDir string, cert string) string {
return filepath.Join(configDir, cert)
}
4 changes: 2 additions & 2 deletions apis/kubedb/v1alpha2/druid_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type DruidSpec struct {
// disable security. It disables authentication security of user.
// If unset, default is false
// +optional
DisableSecurity *bool `json:"disableSecurity,omitempty"`
DisableSecurity bool `json:"disableSecurity,omitempty"`

// Database authentication secret
// +optional
Expand Down Expand Up @@ -282,7 +282,7 @@ const (
DruidDeepStorageHDFS DruidDeepStorageType = "hdfs"
)

// +kubebuilder:validation:Enum=server;client;metrics-exporter
// +kubebuilder:validation:Enum=server;client
type DruidCertificateAlias string

const (
Expand Down
5 changes: 0 additions & 5 deletions apis/kubedb/v1alpha2/zz_generated.deepcopy.go

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

14 changes: 14 additions & 0 deletions apis/ops/v1alpha1/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ const (

// Druid Constants
const (
ScaleUpCoordinators = "ScaleUpCoordinators"
ScaleUpOverlords = "ScaleUpOverlords"
ScaleUpBrokers = "ScaleUpBrokers"
ScaleUpHistoricals = "ScaleUpHistoricals"
ScaleUpMiddleManagers = "ScaleUpMiddleManagers"
ScaleUpRouters = "ScaleUpRouters"

ScaleDownCoordinators = "ScaleDownCoordinators"
ScaleDownOverlords = "ScaleDownOverlords"
ScaleDownBrokers = "ScaleDownBrokers"
ScaleDownHistoricals = "ScaleDownHistoricals"
ScaleDownMiddleManagers = "ScaleDownMiddleManagers"
ScaleDownRouters = "ScaleDownRouters"

UpdateMiddleManagersNodePVCs = "UpdateMiddleManagersNodePVCs"
UpdateHistoricalsNodePVCs = "UpdateHistoricalsNodePVCs"
)
Expand Down
67 changes: 63 additions & 4 deletions apis/ops/v1alpha1/druid_ops_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,29 @@ type DruidOpsRequestSpec struct {
DatabaseRef core.LocalObjectReference `json:"databaseRef"`
// Specifies the ops request type: UpdateVersion, HorizontalScaling, VerticalScaling etc.
Type DruidOpsRequestType `json:"type"`
// Specifies information necessary for restarting database
Restart *RestartSpec `json:"restart,omitempty"`
// Specifies information necessary for horizontal scaling
HorizontalScaling *DruidHorizontalScalingSpec `json:"horizontalScaling,omitempty"`
// Specifies information necessary for vertical scaling
VerticalScaling *DruidVerticalScalingSpec `json:"verticalScaling,omitempty"`
// Specifies information necessary for volume expansion
VolumeExpansion *DruidVolumeExpansionSpec `json:"volumeExpansion,omitempty"`
// Specifies information necessary for restarting database
Restart *RestartSpec `json:"restart,omitempty"`
// Specifies information necessary for upgrading Druid
UpdateVersion *DruidUpdateVersionSpec `json:"updateVersion,omitempty"`
// Specifies information necessary for custom configuration of Druid
Configuration *DruidCustomConfigurationSpec `json:"configuration,omitempty"`
// Specifies information necessary for configuring TLS
TLS *TLSSpec `json:"tls,omitempty"`
// Timeout for each step of the ops request in second. If a step doesn't finish within the specified timeout, the ops request will result in failure.
Timeout *metav1.Duration `json:"timeout,omitempty"`
// ApplyOption is to control the execution of OpsRequest depending on the database state.
// +kubebuilder:default="IfReady"
Apply ApplyOption `json:"apply,omitempty"`
}

// +kubebuilder:validation:Enum=VerticalScaling;VolumeExpansion;Restart
// ENUM(VerticalScaling, VolumeExpansion, Restart)
// +kubebuilder:validation:Enum=UpdateVersion;HorizontalScaling;VerticalScaling;VolumeExpansion;Restart;Reconfigure;ReconfigureTLS
// ENUM(UpdateVersion, HorizontalScaling, VerticalScaling, VolumeExpansion, Restart, Reconfigure, ReconfigureTLS)
type DruidOpsRequestType string

// DruidVerticalScalingSpec contains the vertical scaling information of a Druid cluster
Expand All @@ -82,6 +90,28 @@ type DruidVerticalScalingSpec struct {
Routers *PodResources `json:"routers,omitempty"`
}

// DruidHorizontalScalingSpec contains the horizontal scaling information of a Druid cluster
type DruidHorizontalScalingSpec struct {
// Node topology specification
Topology *DruidHorizontalScalingTopologySpec `json:"topology,omitempty"`
}

// DruidHorizontalScalingTopologySpec contains the horizontal scaling information in cluster topology mode
type DruidHorizontalScalingTopologySpec struct {
// Number of coordinator nodes
Coordinators *int32 `json:"coordinators,omitempty"`
// Number of overlords nodes
Overlords *int32 `json:"overlords,omitempty"`
// Number of middleManagers nodes
MiddleManagers *int32 `json:"middleManagers,omitempty"`
// Number of historicals nodes
Historicals *int32 `json:"historicals,omitempty"`
// Number of brokers nodes
Brokers *int32 `json:"brokers,omitempty"`
// Number of routers nodes
Routers *int32 `json:"routers,omitempty"`
}

// DruidVolumeExpansionSpec is the spec for Druid volume expansion
type DruidVolumeExpansionSpec struct {
Mode VolumeExpansionMode `json:"mode"`
Expand All @@ -91,6 +121,35 @@ type DruidVolumeExpansionSpec struct {
Historicals *resource.Quantity `json:"historicals,omitempty"`
}

// DruidUpdateVersionSpec contains the update version information of a druid cluster
type DruidUpdateVersionSpec struct {
// Specifies the target version name from catalog
TargetVersion string `json:"targetVersion,omitempty"`
}

// DruidCustomConfigurationSpec is the spec for Reconfiguring the Druid Settings
type DruidCustomConfigurationSpec struct {
// ConfigSecret is an optional field to provide custom configuration file for database.
// +optional
ConfigSecret *core.LocalObjectReference `json:"configSecret,omitempty"`
// ApplyConfig is an optional field to provide Druid configuration.
// Provided configuration will be applied to config files stored in ConfigSecret.
// If the ConfigSecret is missing, the operator will create a new k8s secret by the
// following naming convention: {db-name}-user-config .
// Expected input format:
// applyConfig:
// file-name.properties: |
// key=value
// server.properties: |
// log.retention.ms=10000
// +optional
ApplyConfig map[string]string `json:"applyConfig,omitempty"`
// If set to "true", the user provided configuration will be removed.
// The Druid cluster will start will default configuration that is generated by the operator.
// +optional
RemoveCustomConfig bool `json:"removeCustomConfig,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DruidOpsRequestList is a list of DruidOpsRequests
Expand Down
26 changes: 23 additions & 3 deletions apis/ops/v1alpha1/druid_ops_types_enum.go

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

Loading

0 comments on commit 57307e7

Please sign in to comment.