Skip to content

Commit

Permalink
Add MS SQL Ops Requests APIs (#1198)
Browse files Browse the repository at this point in the history
Signed-off-by: Neaj Morshad <neaj@appscode.com>
  • Loading branch information
Neaj-Morshad-101 authored Sep 24, 2024
1 parent adf7fe7 commit 1d90d68
Show file tree
Hide file tree
Showing 16 changed files with 774 additions and 12 deletions.
3 changes: 3 additions & 0 deletions apis/autoscaling/v1alpha1/mssqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type MSSQLServerStorageAutoscalerSpec struct {
}

type MSSQLServerOpsRequestOptions struct {
// Specifies the Readiness Criteria
ReadinessCriteria *opsapi.MSSQLServerReplicaReadinessCriteria `json:"readinessCriteria,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"`

Expand Down
8 changes: 7 additions & 1 deletion apis/autoscaling/v1alpha1/openapi_generated.go

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

5 changes: 5 additions & 0 deletions apis/autoscaling/v1alpha1/zz_generated.deepcopy.go

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

24 changes: 19 additions & 5 deletions apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,19 @@ const (
SinglestoreTLSConfigPreferred = "preferred"

// =========================== MSSQLServer Constants ============================
MSSQLSAUser = "sa"
MSSQLSAUser = "sa"
MSSQLConfigKey = "mssql.conf"

AGPrimaryReplicaReadyCondition = "AGPrimaryReplicaReady"

MSSQLDatabasePodPrimary = "primary"
MSSQLDatabasePodSecondary = "secondary"
MSSQLSecondaryServiceAlias = "secondary"
MSSQLSecondaryServicePortName = "secondary"
MSSQLDatabasePodPrimary = "primary"
MSSQLDatabasePodSecondary = "secondary"
MSSQLSecondaryServiceAlias = "secondary"

// port related
MSSQLDatabasePortName = "db"
MSSQLPrimaryServicePortName = "primary"
MSSQLSecondaryServicePortName = "secondary"
MSSQLDatabasePort = 1433
MSSQLDatabaseMirroringEndpointPort = 5022
MSSQLCoordinatorPort = 2381
Expand All @@ -404,6 +405,8 @@ const (
// volume related
MSSQLVolumeNameData = "data"
MSSQLVolumeMountPathData = "/var/opt/mssql"
MSSQLVolumeNameConfig = "config"
MSSQLVolumeMountPathConfig = "/var/opt/mssql/mssql.conf"
MSSQLVolumeNameInitScript = "init-scripts"
MSSQLVolumeMountPathInitScript = "/scripts"
MSSQLVolumeNameEndpointCert = "endpoint-cert"
Expand Down Expand Up @@ -1494,6 +1497,17 @@ var (
},
}

// DefaultResourcesMemoryIntensiveMSSQLServer must be used for Microsoft SQL Server
DefaultResourcesMemoryIntensiveMSSQLServer = core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(".500"),
core.ResourceMemory: resource.MustParse("1.5Gi"),
},
Limits: core.ResourceList{
core.ResourceMemory: resource.MustParse("4Gi"),
},
}

// DefaultResourcesCoreAndMemoryIntensive must be used for Solr
DefaultResourcesCoreAndMemoryIntensiveSolr = core.ResourceRequirements{
Requests: core.ResourceList{
Expand Down
2 changes: 1 addition & 1 deletion apis/kubedb/v1alpha2/mssqlserver_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func (m *MSSQLServer) assignDefaultContainerSecurityContext(mssqlVersion *catalo
func (m *MSSQLServer) setDefaultContainerResourceLimits(podTemplate *ofst.PodTemplateSpec) {
dbContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, kubedb.MSSQLContainerName)
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResourcesMemoryIntensive)
apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResourcesMemoryIntensiveMSSQLServer)
}

initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, kubedb.MSSQLInitContainerName)
Expand Down
5 changes: 5 additions & 0 deletions apis/kubedb/v1alpha2/mssqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ type MSSQLServerSpec struct {
// +optional
AuthSecret *SecretReference `json:"authSecret,omitempty"`

// ConfigSecret is an optional field to provide custom configuration file for database (i.e mssql.conf).
// If specified, this file will be used as configuration file otherwise default configuration file will be used.
// +optional
ConfigSecret *core.LocalObjectReference `json:"configSecret,omitempty"`

// InternalAuth is used to authenticate endpoint
// +optional
// +nullable
Expand Down
2 changes: 2 additions & 0 deletions apis/kubedb/v1alpha2/mssqlserver_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (m *MSSQLServer) ValidateCreateOrUpdate() field.ErrorList {
// reserved volume and volumes mounts for mssql
var mssqlReservedVolumes = []string{
kubedb.MSSQLVolumeNameData,
kubedb.MSSQLVolumeNameConfig,
kubedb.MSSQLVolumeNameInitScript,
kubedb.MSSQLVolumeNameEndpointCert,
kubedb.MSSQLVolumeNameCerts,
Expand All @@ -202,6 +203,7 @@ var mssqlReservedVolumes = []string{

var mssqlReservedVolumesMountPaths = []string{
kubedb.MSSQLVolumeMountPathData,
kubedb.MSSQLVolumeMountPathConfig,
kubedb.MSSQLVolumeMountPathInitScript,
kubedb.MSSQLVolumeMountPathEndpointCert,
kubedb.MSSQLVolumeMountPathCerts,
Expand Down
8 changes: 7 additions & 1 deletion apis/kubedb/v1alpha2/openapi_generated.go

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

5 changes: 5 additions & 0 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.

54 changes: 52 additions & 2 deletions apis/ops/v1alpha1/mssqlserver_ops_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1

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

Expand Down Expand Up @@ -54,6 +55,18 @@ type MSSQLServerOpsRequestSpec struct {
DatabaseRef core.LocalObjectReference `json:"databaseRef"`
// Specifies the ops request type: UpdateVersion, HorizontalScaling, VerticalScaling etc.
Type MSSQLServerOpsRequestType `json:"type"`
// Specifies information necessary for upgrading MSSQL
UpdateVersion *MSSQLServerUpdateVersionSpec `json:"updateVersion,omitempty"`
// Specifies information necessary for horizontal scaling
HorizontalScaling *MSSQLServerHorizontalScalingSpec `json:"horizontalScaling,omitempty"`
// Specifies information necessary for vertical scaling
VerticalScaling *MSSQLServerVerticalScalingSpec `json:"verticalScaling,omitempty"`
// Specifies information necessary for volume expansion
VolumeExpansion *MSSQLServerVolumeExpansionSpec `json:"volumeExpansion,omitempty"`
// Specifies information necessary for custom configuration of MSSQLServer
Configuration *MSSQLServerCustomConfigurationSpec `json:"configuration,omitempty"`
// Specifies information necessary for configuring TLS
TLS *TLSSpec `json:"tls,omitempty"`
// Specifies information necessary for restarting database
Restart *RestartSpec `json:"restart,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.
Expand All @@ -63,10 +76,47 @@ type MSSQLServerOpsRequestSpec struct {
Apply ApplyOption `json:"apply,omitempty"`
}

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

// MSSQLServerReplicaReadinessCriteria is the criteria for checking readiness of a MSSQLServer pod
// after updating, horizontal scaling etc.
type MSSQLServerReplicaReadinessCriteria struct{}

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

// MSSQLServerHorizontalScalingSpec contains the horizontal scaling information of a MSSQLServer cluster
type MSSQLServerHorizontalScalingSpec struct {
// Number of Replicas of MSSQLServer Availability Group
Replicas *int32 `json:"replicas,omitempty"`
}

// MSSQLServerVerticalScalingSpec contains the vertical scaling information of a MSSQLServer cluster
type MSSQLServerVerticalScalingSpec struct {
MSSQLServer *PodResources `json:"mssqlserver,omitempty"`
Exporter *ContainerResources `json:"exporter,omitempty"`
Coordinator *ContainerResources `json:"coordinator,omitempty"`
}

// MSSQLServerVolumeExpansionSpec is the spec for MSSQLServer volume expansion
type MSSQLServerVolumeExpansionSpec struct {
// volume specification for Postgres
MSSQLServer *resource.Quantity `json:"mssqlserver,omitempty"`
Mode VolumeExpansionMode `json:"mode"`
}

// MSSQLServerCustomConfigurationSpec is the spec for Reconfiguring the MSSQLServer
type MSSQLServerCustomConfigurationSpec struct {
ConfigSecret *core.LocalObjectReference `json:"configSecret,omitempty"`
ApplyConfig map[string]string `json:"applyConfig,omitempty"`
RemoveCustomConfig bool `json:"removeCustomConfig,omitempty"`
}

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

// MSSQLServerOpsRequestList is a list of MSSQLServerOpsRequests
Expand Down
32 changes: 31 additions & 1 deletion apis/ops/v1alpha1/mssqlserver_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 1d90d68

Please sign in to comment.