Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MS SQL Server Arbiter APIs #1363

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,12 @@ const (
MSSQLDatabasePortName = "db"
MSSQLPrimaryServicePortName = "primary"
MSSQLSecondaryServicePortName = "secondary"
MSSQLCoordinatorPortName = "coordinator"
MSSQLCoordinatorClientPortName = "coordinatclient"
MSSQLDatabasePort = 1433
MSSQLDatabaseMirroringEndpointPort = 5022
MSSQLCoordinatorPort = 2381
MSSQLCoordinatorPort = 2380
MSSQLCoordinatorClientPort = 2379
MSSQLMonitoringDefaultServicePort = 9399

// environment variables
Expand Down
12 changes: 12 additions & 0 deletions apis/kubedb/v1alpha2/mssqlserver_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
kmapi "kmodules.xyz/client-go/api/v1"
"kmodules.xyz/client-go/apiextensions"
coreutil "kmodules.xyz/client-go/core/v1"
Expand Down Expand Up @@ -380,6 +381,8 @@ func (m *MSSQLServer) SetDefaults() {
return
}

m.SetArbiterDefault()

m.setDefaultContainerSecurityContext(&mssqlVersion, m.Spec.PodTemplate)

m.SetTLSDefaults()
Expand Down Expand Up @@ -506,6 +509,15 @@ func (m *MSSQLServer) setDefaultContainerResourceLimits(podTemplate *ofst.PodTem
}
}

func (m *MSSQLServer) SetArbiterDefault() {
if m.IsAvailabilityGroup() && ptr.Deref(m.Spec.Replicas, 0)%2 == 0 && m.Spec.Arbiter == nil {
m.Spec.Arbiter = &ArbiterSpec{
Resources: core.ResourceRequirements{},
}
apis.SetDefaultResourceLimits(&m.Spec.Arbiter.Resources, kubedb.DefaultArbiter(false))
}
}

func (m *MSSQLServer) SetTLSDefaults() {
if m.Spec.TLS == nil || m.Spec.TLS.IssuerRef == nil {
return
Expand Down
4 changes: 4 additions & 0 deletions apis/kubedb/v1alpha2/mssqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ type MSSQLServerSpec struct {
// Archiver controls database backup using Archiver CR
// +optional
Archiver *Archiver `json:"archiver,omitempty"`

// Arbiter controls spec for arbiter pods
// +optional
Arbiter *ArbiterSpec `json:"arbiter,omitempty"`
}

type MSSQLServerTLSConfig struct {
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.

15 changes: 0 additions & 15 deletions apis/kubedb/v1alpha2/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,6 @@ type PostgresReplication struct {
MaxSlotWALKeepSizeInMegaBytes *int32 `json:"maxSlotWALKeepSize,omitempty"`
}

type ArbiterSpec struct {
// Compute Resources required by the sidecar container.
// +optional
Resources core.ResourceRequirements `json:"resources,omitempty"`
// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// If specified, the pod's tolerations.
// +optional
Tolerations []core.Toleration `json:"tolerations,omitempty"`
}

// PostgreLeaderElectionConfig contains essential attributes of leader election.
type PostgreLeaderElectionConfig struct {
// LeaseDuration is the duration in second that non-leader candidates will
Expand Down
15 changes: 15 additions & 0 deletions apis/kubedb/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,18 @@ type ArchiverRecovery struct {
FullDBRepository *kmapi.ObjectReference `json:"fullDBRepository,omitempty"`
ReplicationStrategy *PITRReplicationStrategy `json:"replicationStrategy,omitempty"`
}

type ArbiterSpec struct {
// Compute Resources required by the sidecar container.
// +optional
Resources core.ResourceRequirements `json:"resources,omitempty"`
// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// If specified, the pod's tolerations.
// +optional
Tolerations []core.Toleration `json:"tolerations,omitempty"`
}
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.

55 changes: 55 additions & 0 deletions crds/kubedb.com_mssqlservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,61 @@ spec:
type: object
spec:
properties:
arbiter:
properties:
nodeSelector:
additionalProperties:
type: string
type: object
x-kubernetes-map-type: atomic
resources:
properties:
claims:
items:
properties:
name:
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
tolerations:
items:
properties:
effect:
type: string
key:
type: string
operator:
type: string
tolerationSeconds:
format: int64
type: integer
value:
type: string
type: object
type: array
type: object
archiver:
properties:
pause:
Expand Down