Skip to content

Commit

Permalink
Make clientTLS optional and ensure MSSQL_PID is set
Browse files Browse the repository at this point in the history
Signed-off-by: Neaj Morshad <[email protected]>
  • Loading branch information
Neaj-Morshad-101 committed Nov 19, 2024
1 parent 623a761 commit 2e8e22a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
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
4 changes: 3 additions & 1 deletion apis/kubedb/v1alpha2/mssqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ type MSSQLServerSpec struct {

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

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

type MSSQLServerTopology struct {
Expand Down
19 changes: 16 additions & 3 deletions apis/kubedb/v1alpha2/mssqlserver_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@ 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.TLS.ClientTLS == nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("tls").Child("clientTLS"),
m.Name, "spec.tls.clientTLS' is missing"))
}
}

if m.Spec.PodTemplate != nil {
Expand Down Expand Up @@ -289,11 +295,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
}
6 changes: 2 additions & 4 deletions 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.

6 changes: 2 additions & 4 deletions apis/ops/v1alpha1/openapi_generated.go

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

2 changes: 0 additions & 2 deletions crds/kubedb.com_mssqlservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4658,8 +4658,6 @@ spec:
- name
type: object
x-kubernetes-map-type: atomic
required:
- clientTLS
type: object
topology:
properties:
Expand Down
2 changes: 0 additions & 2 deletions crds/ops.kubedb.com_mssqlserveropsrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ spec:
type: boolean
rotateCertificates:
type: boolean
required:
- clientTLS
type: object
type:
enum:
Expand Down

0 comments on commit 2e8e22a

Please sign in to comment.