Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
6a493f3
Added additional property to yaml
mazin-s Sep 21, 2023
3feeac3
Added allowed fields
mazin-s Sep 21, 2023
8019fab
Changing naming
mazin-s Sep 22, 2023
e544ef4
Added webhook validation
mazin-s Sep 22, 2023
e392bf2
Ran make generate manifests
mazin-s Sep 22, 2023
9c157c5
Added webhook validation and tests for db engine logic
mazin-s Sep 25, 2023
0e4e9a6
Changed NDB Validation test format
mazin-s Sep 25, 2023
6ae02d5
Did not need util file anymore
mazin-s Sep 25, 2023
5e0d4be
Changed error messaging slightly
mazin-s Sep 25, 2023
f420b58
Refactored UT's and added UT's for db_engine specific logic
mazin-s Sep 25, 2023
080305a
Added GetDBInstanceTypeDetails() method and test
mazin-s Sep 25, 2023
2b58a64
Changed from map to ActionArgument
mazin-s Sep 25, 2023
c69d941
Created a function that sorts actionArgs by Name property
mazin-s Sep 26, 2023
cfe21d7
Added an appendActionArguments helper function, changed MSSQL appendi…
mazin-s Sep 26, 2023
15f0131
Added GetDBInstanceTypeDetails interface
mazin-s Sep 26, 2023
01dda22
Edited TestMSSQLProvisionRequestAppenderNoTypeDetails
mazin-s Sep 26, 2023
168f719
Had a duplicate actionArgument, renamed to reflect correct value
mazin-s Sep 26, 2023
e433520
Added mssqlReplacableActionArgs and mssqlDefaultActionArgs
mazin-s Sep 26, 2023
d0e4590
Am using functions from common_types
mazin-s Sep 26, 2023
f7a1e56
Added MSSQL tests
mazin-s Sep 26, 2023
d73d47c
Added a small comment
mazin-s Sep 26, 2023
36f1c40
Added mongoDbReplacableActionArgs and mongoDbDefaultActionArgs
mazin-s Sep 26, 2023
496fbeb
Replaced MongoDB appender logic
mazin-s Sep 26, 2023
3d79610
Added mongodb test
mazin-s Sep 26, 2023
3eb75ef
Added postgresReplacableActionArgs and postgresDefaultActionArgs
mazin-s Sep 26, 2023
635d877
(a *PostgresProvisionRequestAppender) appendRequest
mazin-s Sep 26, 2023
21d4631
PostGres test complete
mazin-s Sep 26, 2023
afa8736
MYSQL test done
mazin-s Sep 26, 2023
1170d8f
Renamed sortActionArgsByName
mazin-s Sep 26, 2023
de72bc3
Changed function names and documentation
mazin-s Sep 26, 2023
97feaab
small changes
mazin-s Sep 26, 2023
79ca07e
Removed ndb_api dependency and changed to AdditionalArguments map[str…
mazin-s Sep 27, 2023
3cc6798
Changed DB type
mazin-s Sep 27, 2023
79d8903
Changed GetDBInstanceTypeDetails() to GetDBInstanceAdditionalArguments()
mazin-s Sep 27, 2023
8fed399
Changed GetDBInstanceTypeDetails() []ActionArgument mock to GetDBInst…
mazin-s Sep 27, 2023
18f782f
Created a default action argument and allowed additional argument for…
mazin-s Sep 27, 2023
faccb7c
Changed naming from typeDetails to actionArguments and using constant…
mazin-s Sep 27, 2023
316e6b8
CRD changed
mazin-s Sep 27, 2023
998b228
Removed not needed maps. Am referencing from elsewhere instead
mazin-s Sep 27, 2023
e30865e
Changed database implementation to GetDBInstanceAdditionalArguments(…
mazin-s Sep 27, 2023
03f0ca2
Slight changed to use AdditionalArguments instead of TypeDetails
mazin-s Sep 27, 2023
a60b0ca
Refactored to use new logic
mazin-s Sep 27, 2023
c43cde9
Slightly changed function signature
mazin-s Sep 27, 2023
2a8bb46
temp change to tests. is failing right now
mazin-s Sep 27, 2023
9fcd281
Changed bug so all test passing
mazin-s Sep 27, 2023
8a71398
Using common.DATABASE_ENGINE_TYPE_POSTGRES and renamed/recommented db…
mazin-s Sep 27, 2023
3c4edbf
Using common.DATABASE_TYPE_POSTGRES, deleted NDB validation, refactor…
mazin-s Sep 27, 2023
c27b5ee
deleted helper file and am creating database objects in test file
mazin-s Sep 27, 2023
947e12d
Remove unrelated changes
mazin-s Sep 28, 2023
0680438
Undid error message changes
mazin-s Sep 28, 2023
ec39a1c
Changed error messaging and delete not needed tests
mazin-s Sep 28, 2023
51d6707
changed documentation
mazin-s Sep 28, 2023
5e40506
Merge conflict complete
mazin-s Sep 28, 2023
9789736
Created GetAllowedAdditionalArgumentsForType function
mazin-s Sep 29, 2023
c3ec31f
Removed ndb_api dependency and am using util.GetAllowedAdditionalArgu…
mazin-s Sep 29, 2023
7e433e9
Moved logic to common/util
mazin-s Sep 29, 2023
02f6159
Changed appender logic
mazin-s Sep 29, 2023
a1f8d40
small referencing chanfe
mazin-s Sep 29, 2023
a14c53b
Addressed Manav's comments
mazin-s Oct 4, 2023
4d25f64
Fixed log message and renamed typ to dbType
mazin-s Oct 5, 2023
b7f76bb
Added DATABASE_TYPES string
mazin-s Oct 9, 2023
332ad51
More descriptive error message and renamed typ to dbType
mazin-s Oct 9, 2023
1a6e4a3
Edited additionalArgumentsValidationCheck in webhooks and correspondi…
mazin-s Oct 9, 2023
b5ecdd7
Changed formatting of DATABASE_TYPES constant
mazin-s Oct 9, 2023
ff2ead0
Changed flow to allow for returned error
mazin-s Oct 9, 2023
819120f
additional error handling
mazin-s Oct 10, 2023
8554b7e
Got rid of testify/assert
mazin-s Oct 10, 2023
461836f
Added tests for when requestAppender fails because additionalArgument…
mazin-s Oct 10, 2023
9d1f350
Changed error message formatting
mazin-s Oct 10, 2023
035ee5a
removed errors dependency
mazin-s Oct 10, 2023
0dc80bd
Added a comment for GetAllowedAdditionalArgumentsForType
mazin-s Oct 12, 2023
1ba84c8
spelled arguments right
mazin-s Oct 13, 2023
3f817c9
spelled mongodb correctly
mazin-s Oct 16, 2023
ca4bd28
E2E formatting complete
mazin-s Oct 16, 2023
cb93a9f
reading CLUSTER_ID env instead of NDB_CLUSTER_ID
mazin-s Oct 16, 2023
dbbe46e
changed db yaml
mazin-s Oct 16, 2023
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
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ spec:
weeklySnapshotDay: "WEDNESDAY" # Day of the week for weekly snapshot
monthlySnapshotDay: 24 # Day of the month for monthly snapshot
quarterlySnapshotMonth: "Jan" # Start month of the quarterly snapshot
additionalArguments: # Optional black, can specify additional arguments that are unique to database engines.
listener_port: 8080

```

Expand All @@ -176,6 +178,37 @@ kubectl delete -f config/samples/ndb_v1alpha1_database.yaml
```sh
kubectl delete -f config/samples/ndb_v1alpha1_ndbserver.yaml
```
Below are the various optional addtionalArguments you can specify along with examples of their corresponding values. Arguments that have defaults will be indicated.

```yaml
# PostGres
additionalArguments:
listener_port: "1111" # Default: "5432"

# MySQL
additionalArguments:
listener_port: "1111" # Default: "3306"

# MongoDB
additionalArguments:
listener_port: "1111" # Default: "27017"
log_size: "150" # Default: "100"
journal_size: "150" # Default: "100"

# MSSQL
additionalArguments:
sql_user_name: "mazin" # Defualt: "sa".
authentication_mode: "mixed" # Default: "windows". Options are "windows" or "mixed". Must specify sql_user.
server_collation: "<server-collation>" # Default: "SQL_Latin1_General_CP1_CI_AS".
database_collation: "<server-collation>" # Default: "SQL_Latin1_General_CP1_CI_AS".
dbParameterProfileIdInstance: "<id-instance>" # Default: Fetched from profile.
vm_dbserver_admin_password: "<admin-password>" # Default: Fetched from database secret.
sql_user_password: "<sq-user-password>" # NO Default. Must specify authentication_mode as "mixed".
windows_domain_profile_id: <domain-profile-id> # NO Default. Must specify vm_db_server_user.
vm_db_server_user: <vm-db-server-use> # NO Default. Must specify windows_domain_profile_id.
vm_win_license_key: <licenseKey> # NO Default.
```

## Developement

### Installation and Running the controller locally
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ type Instance struct {
// +optional
// Information related to time machine that is to be associated with this database
TMInfo *DBTimeMachineInfo `json:"timeMachine"`
// +optional
// Additional database engine specific arguments
AdditionalArguments map[string]string `json:"additionalArguments"`
}

// Time Machine details
Expand Down
43 changes: 43 additions & 0 deletions api/v1alpha1/database_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"reflect"
"regexp"
"strings"

"github.com/nutanix-cloud-native/ndb-operator/api"
"github.com/nutanix-cloud-native/ndb-operator/common"
Expand Down Expand Up @@ -106,6 +107,11 @@ func instanceSpecDefaulterForCreate(instance *Instance) {
instance.TMInfo.QuarterlySnapshotMonth = "Jan"
}

// additional arguments defaulting logic
if instance.AdditionalArguments == nil {
databaselog.Info("Initializing empty additional db arguments...")
instance.AdditionalArguments = map[string]string{}
}
}

// Default implements webhook.Defaulter so a webhook will be registered for the type
Expand Down Expand Up @@ -188,10 +194,47 @@ func instanceSpecValidatorForCreate(instance *Instance, allErrs field.ErrorList,
))
}

if err := additionalArgumentsValidationCheck(instance.Type, instance.AdditionalArguments); err != nil {
allErrs = append(allErrs, field.Invalid(instancePath.Child("additionalArguments"), instance.AdditionalArguments, err.Error()))
}

databaselog.Info("Exiting instanceSpecValidatorForCreate...")
return allErrs
}

/* Checks if configured additional arguments are valid or not and returns the corresponding additional arguments. If error is nil valid, else invalid */
func additionalArgumentsValidationCheck(dbType string, specifiedAdditionalArguments map[string]string) error {
// Empty additionalArguments is always valid
if specifiedAdditionalArguments == nil {
return nil
}

allowedAdditionalArguments, err := util.GetAllowedAdditionalArgumentsForType(dbType)

// Invalid type returns error
if err != nil {
return err
}

// Checking if arguments are valid
invalidArgs := []string{}
for name, _ := range specifiedAdditionalArguments {
if _, isPresent := allowedAdditionalArguments[name]; !isPresent {
invalidArgs = append(invalidArgs, name)
}
}

if len(invalidArgs) == 0 {
return nil
} else {
return fmt.Errorf(
"Additional Arguments validation for database type: %s failed! The following args are invalid: %s. These are the allowed args: %s",
dbType,
strings.Join(invalidArgs, ", "),
reflect.ValueOf(allowedAdditionalArguments).MapKeys())
}
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *Database) ValidateCreate() (admission.Warnings, error) {
databaselog.Info("Entering ValidateCreate...")
Expand Down
Loading