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 mssql ops apis for reconfigure tls #1341

Merged
merged 4 commits into from
Nov 19, 2024
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
1 change: 1 addition & 0 deletions apis/kubedb/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ const (

// environment variables
EnvAcceptEula = "ACCEPT_EULA"
EnvMSSQLPid = "MSSQL_PID"
EnvMSSQLEnableHADR = "MSSQL_ENABLE_HADR"
EnvMSSQLAgentEnabled = "MSSQL_AGENT_ENABLED"
EnvMSSQLSAUsername = "MSSQL_SA_USERNAME"
Expand Down
5 changes: 5 additions & 0 deletions apis/kubedb/v1alpha2/mssqlserver_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ func (m *MSSQLServer) SetTLSDefaults() {
return
}

if m.Spec.TLS.ClientTLS == nil {
defaultValue := false
m.Spec.TLS.ClientTLS = &defaultValue
}

// Server-cert
defaultServerOrg := []string{kubedb.KubeDBOrganization}
defaultServerOrgUnit := []string{string(MSSQLServerServerCert)}
Expand Down
8 changes: 5 additions & 3 deletions apis/kubedb/v1alpha2/mssqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type MSSQLServerSpec struct {
PodTemplate *ofst.PodTemplateSpec `json:"podTemplate,omitempty"`

// TLS contains tls configurations for client and server.
TLS *SQLServerTLSConfig `json:"tls,omitempty"`
TLS *MSSQLServerTLSConfig `json:"tls,omitempty"`

// ServiceTemplates is an optional configuration for services used to expose database
// +optional
Expand Down Expand Up @@ -132,9 +132,11 @@ type MSSQLServerSpec struct {
Archiver *Archiver `json:"archiver,omitempty"`
}

type SQLServerTLSConfig struct {
type MSSQLServerTLSConfig struct {
kmapi.TLSConfig `json:",inline"`
ClientTLS bool `json:"clientTLS"`

// +optional
ClientTLS *bool `json:"clientTLS"`
}

type MSSQLServerTopology struct {
Expand Down
15 changes: 12 additions & 3 deletions apis/kubedb/v1alpha2/mssqlserver_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ func (m *MSSQLServer) ValidateCreateOrUpdate() field.ErrorList {
if m.Spec.TLS == nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("tls"),
m.Name, "spec.tls is missing"))
} else if m.Spec.TLS.IssuerRef == nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("tls").Child("issuerRef"),
m.Name, "spec.tls.issuerRef' is missing"))
} else {
if m.Spec.TLS.IssuerRef == nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("tls").Child("issuerRef"),
m.Name, "spec.tls.issuerRef' is missing"))
}
}

if m.Spec.PodTemplate != nil {
Expand Down Expand Up @@ -289,11 +291,18 @@ func getMSSQLServerContainerEnvs(m *MSSQLServer) []core.EnvVar {
}

func ValidateMSSQLServerEnvVar(envs []core.EnvVar, forbiddenEnvs []string, resourceType string) error {
presentMSSQL_PID := false
for _, env := range envs {
present, _ := arrays.Contains(forbiddenEnvs, env.Name)
if present {
return fmt.Errorf("environment variable %s is forbidden to use in %s spec", env.Name, resourceType)
}
if env.Name == "MSSQL_PID" {
presentMSSQL_PID = true
}
}
if !presentMSSQL_PID {
return fmt.Errorf("environment variable %s must be provided in %s spec", kubedb.EnvMSSQLPid, resourceType)
}
return nil
}
88 changes: 43 additions & 45 deletions apis/kubedb/v1alpha2/openapi_generated.go

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

41 changes: 23 additions & 18 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.

18 changes: 17 additions & 1 deletion apis/ops/v1alpha1/mssqlserver_ops_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ limitations under the License.
package v1alpha1

import (
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -66,7 +68,7 @@ type MSSQLServerOpsRequestSpec struct {
// Specifies information necessary for custom configuration of MSSQLServer
Configuration *MSSQLServerCustomConfigurationSpec `json:"configuration,omitempty"`
// Specifies information necessary for configuring TLS
TLS *TLSSpec `json:"tls,omitempty"`
TLS *MSSQLServerTLSSpec `json:"tls,omitempty"`
// Specifies information necessary for configuring authSecret of the database
Authentication *AuthSpec `json:"authentication,omitempty"`
// Specifies information necessary for restarting database
Expand Down Expand Up @@ -119,6 +121,20 @@ type MSSQLServerCustomConfigurationSpec struct {
RemoveCustomConfig bool `json:"removeCustomConfig,omitempty"`
}

type MSSQLServerTLSSpec struct {
// SQLServerTLSSpec contains updated tls configurations for client and server.
// +optional
dbapi.MSSQLServerTLSConfig `json:",inline,omitempty"`

// RotateCertificates tells operator to initiate certificate rotation
// +optional
RotateCertificates bool `json:"rotateCertificates,omitempty"`

// Remove tells operator to remove TLS configuration
// +optional
Remove bool `json:"remove,omitempty"`
}

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

// MSSQLServerOpsRequestList is a list of MSSQLServerOpsRequests
Expand Down
59 changes: 57 additions & 2 deletions apis/ops/v1alpha1/openapi_generated.go

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

Loading
Loading