Skip to content

Commit

Permalink
DEVOPS-28230 remove version validation (#306)
Browse files Browse the repository at this point in the history
* update how default engineversion is treated

* update

* comment

* Updating dbclaim to valid db version

* fix tests

* rename properties to be like what enduser sees

* update

* fix tests

* add comments

* change namespace where secret is created

* implement PR review suggestions

* refacvtor

* install XRD like a CRD is installed (#305)

* put xrd in the templates folder and turn off pruning (#308)

---------

Co-authored-by: Drew Wells <dwells@infoblox.com>
  • Loading branch information
EvertonCalgarotto and drewwells authored Sep 30, 2024
1 parent 55aba37 commit 8124ea5
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 257 deletions.
1 change: 1 addition & 0 deletions cmd/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ project: gcp-eng-ddiaas-dev
network: "ddiaas-dev-use1-vpc"
subnetwork: private-service-connect
numbackupstoretain: 3
defaultMajorVersion: 15

passwordConfig:
passwordComplexity: enabled
Expand Down
1 change: 1 addition & 0 deletions helm/db-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ controllerConfig:
passwordRotationPeriod: 60m
pgTemp: "/pg-temp/"
storageType: gp3
defaultMajorVersion: 15
supportSuperUserElevation: true
# system funtions are created as functions in the database. The prefix is used as the schema name.
# only "ib_" prefixed functions are supported at this time.
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/databaseclaim_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ var _ = Describe("DatabaseClaim Controller", func() {

})

It("Should fail to reconcile DB Claim missing dbVersion", func() {
It("Should succeed to reconcile DB Claim missing dbVersion", func() {
By("Reconciling the created resource")

_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typeNamespacedName})
Expect(err).To(MatchError(".spec.dbVersion is a mandatory field and cannot be empty"))
Expect(err).NotTo(HaveOccurred())
Expect(claim.Status.Error).To(Equal(""))
})

Expand Down
4 changes: 4 additions & 0 deletions pkg/basefunctions/basefunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ func GetSystemFunctions(viperConfig *viper.Viper) map[string]string {
return viperConfig.GetStringMapString("systemFunctions")
}

func GetDefaultMajorVersion(viperConfig *viper.Viper) string {
return viperConfig.GetString("defaultMajorVersion")
}

func GetDynamicHostWaitTime(viperConfig *viper.Viper) time.Duration {
t := time.Duration(viperConfig.GetInt("dynamicHostWaitTimeMin")) * time.Minute

Expand Down
62 changes: 25 additions & 37 deletions pkg/databaseclaim/awsprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"github.com/go-logr/logr"
v1 "github.com/infobloxopen/db-controller/api/v1"
basefun "github.com/infobloxopen/db-controller/pkg/basefunctions"
"github.com/infobloxopen/db-controller/pkg/hostparams"
_ "github.com/lib/pq"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -109,11 +111,6 @@ func (r *DatabaseClaimReconciler) manageDBClusterAWS(ctx context.Context, dbHost
}

logr.Info("creating_crossplane_dbcluster", "name", dbHostName)
validationError := params.CheckEngineVersion()
if validationError != nil {
logr.Error(validationError, "invalid_db_version")
return false, validationError
}
dbCluster = &crossplaneaws.DBCluster{
ObjectMeta: metav1.ObjectMeta{
Name: dbHostName,
Expand All @@ -137,9 +134,9 @@ func (r *DatabaseClaimReconciler) manageDBClusterAWS(ctx context.Context, dbHost
DBClusterParameterGroupNameRef: &xpv1.Reference{
Name: pgName,
},
EngineVersion: &params.EngineVersion,
EngineVersion: ptr.To(getEngineVersion(params, r)),
},
Engine: &params.Engine,
Engine: &params.Type,
Tags: DBClaimTags(dbClaim.Spec.Tags).DBTags(),
// Items from Config
MasterUsername: &params.MasterUsername,
Expand Down Expand Up @@ -249,10 +246,6 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstanceAWS(ctx context.Contex
}, dbInstance)
if err != nil {
if errors.IsNotFound(err) {
validationError := params.CheckEngineVersion()
if validationError != nil {
return false, validationError
}
dbInstance = &crossplaneaws.DBInstance{
ObjectMeta: metav1.ObjectMeta{
Name: dbHostName,
Expand All @@ -277,9 +270,9 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstanceAWS(ctx context.Contex
},
AutogeneratePassword: true,
MasterUserPasswordSecretRef: &dbMasterSecretInstance,
EngineVersion: &params.EngineVersion,
EngineVersion: ptr.To(getEngineVersion(params, r)),
},
Engine: &params.Engine,
Engine: &params.Type,
MultiAZ: &multiAZ,
DBInstanceClass: &params.InstanceClass,
AllocatedStorage: &ms64,
Expand Down Expand Up @@ -407,10 +400,6 @@ func (r *DatabaseClaimReconciler) manageAuroraDBInstance(ctx context.Context, re
if err != nil {
if errors.IsNotFound(err) {
logr.Info("aurora db instance not found. creating now")
validationError := params.CheckEngineVersion()
if validationError != nil {
return false, validationError
}
dbInstance = &crossplaneaws.DBInstance{
ObjectMeta: metav1.ObjectMeta{
Name: dbHostName,
Expand All @@ -424,10 +413,10 @@ func (r *DatabaseClaimReconciler) manageAuroraDBInstance(ctx context.Context, re
CustomDBInstanceParameters: crossplaneaws.CustomDBInstanceParameters{
ApplyImmediately: &trueVal,
SkipFinalSnapshot: params.SkipFinalSnapshotBeforeDeletion,
EngineVersion: &params.EngineVersion,
EngineVersion: ptr.To(getEngineVersion(params, r)),
},
DBParameterGroupName: &pgName,
Engine: &params.Engine,
Engine: &params.Type,
DBInstanceClass: &params.InstanceClass,
Tags: ReplaceOrAddTag(DBClaimTags(dbClaim.Spec.Tags).DBTags(), OperationalStatusTagKey, OperationalStatusActiveValue),
// Items from Config
Expand Down Expand Up @@ -502,10 +491,6 @@ func (r *DatabaseClaimReconciler) managePostgresParamGroup(ctx context.Context,
}, dbParamGroup)
if err != nil {
if errors.IsNotFound(err) {
validationError := params.CheckEngineVersion()
if validationError != nil {
return pgName, validationError
}
dbParamGroup = &crossplaneaws.DBParameterGroup{
ObjectMeta: metav1.ObjectMeta{
Name: pgName,
Expand All @@ -516,8 +501,8 @@ func (r *DatabaseClaimReconciler) managePostgresParamGroup(ctx context.Context,
Description: &desc,
CustomDBParameterGroupParameters: crossplaneaws.CustomDBParameterGroupParameters{
DBParameterGroupFamilySelector: &crossplaneaws.DBParameterGroupFamilyNameSelector{
Engine: params.Engine,
EngineVersion: &params.EngineVersion,
Engine: params.Type,
EngineVersion: ptr.To(getEngineVersion(params, r)),
},
Parameters: []crossplaneaws.CustomParameter{
{ParameterName: &logical,
Expand Down Expand Up @@ -563,6 +548,7 @@ func (r *DatabaseClaimReconciler) managePostgresParamGroup(ctx context.Context,
}
return pgName, nil
}

func (r *DatabaseClaimReconciler) manageAuroraPostgresParamGroup(ctx context.Context, reqInfo *requestInfo, dbClaim *v1.DatabaseClaim) (string, error) {

logr := log.FromContext(ctx)
Expand Down Expand Up @@ -590,10 +576,6 @@ func (r *DatabaseClaimReconciler) manageAuroraPostgresParamGroup(ctx context.Con
}, dbParamGroup)
if err != nil {
if errors.IsNotFound(err) {
validationError := params.CheckEngineVersion()
if validationError != nil {
return pgName, validationError
}
dbParamGroup = &crossplaneaws.DBParameterGroup{
ObjectMeta: metav1.ObjectMeta{
Name: pgName,
Expand All @@ -604,8 +586,8 @@ func (r *DatabaseClaimReconciler) manageAuroraPostgresParamGroup(ctx context.Con
Description: &desc,
CustomDBParameterGroupParameters: crossplaneaws.CustomDBParameterGroupParameters{
DBParameterGroupFamilySelector: &crossplaneaws.DBParameterGroupFamilyNameSelector{
Engine: params.Engine,
EngineVersion: &params.EngineVersion,
Engine: params.Type,
EngineVersion: ptr.To(getEngineVersion(params, r)),
},
Parameters: []crossplaneaws.CustomParameter{
{ParameterName: &transactionTimeout,
Expand Down Expand Up @@ -674,10 +656,6 @@ func (r *DatabaseClaimReconciler) manageClusterParamGroup(ctx context.Context, r
}, dbParamGroup)
if err != nil {
if errors.IsNotFound(err) {
validationError := params.CheckEngineVersion()
if validationError != nil {
return pgName, validationError
}
dbParamGroup = &crossplaneaws.DBClusterParameterGroup{
ObjectMeta: metav1.ObjectMeta{
Name: pgName,
Expand All @@ -688,8 +666,8 @@ func (r *DatabaseClaimReconciler) manageClusterParamGroup(ctx context.Context, r
Description: &desc,
CustomDBClusterParameterGroupParameters: crossplaneaws.CustomDBClusterParameterGroupParameters{
DBParameterGroupFamilySelector: &crossplaneaws.DBParameterGroupFamilyNameSelector{
Engine: params.Engine,
EngineVersion: &params.EngineVersion,
Engine: params.Type,
EngineVersion: ptr.To(getEngineVersion(params, r)),
},
Parameters: []crossplaneaws.CustomParameter{
{ParameterName: &logical,
Expand Down Expand Up @@ -1095,3 +1073,13 @@ func HasOperationalTag(tags []*crossplaneaws.Tag) bool {
}
return false
}

func getEngineVersion(params *hostparams.HostParams, r *DatabaseClaimReconciler) string {
defaultMajorVersion := ""
if params.IsDefaultVersion {
defaultMajorVersion = basefun.GetDefaultMajorVersion(r.Config.Viper)
} else {
defaultMajorVersion = params.DBVersion
}
return defaultMajorVersion
}
14 changes: 7 additions & 7 deletions pkg/databaseclaim/databaseclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func (r *DatabaseClaimReconciler) reconcileNewDB(ctx context.Context, reqInfo *r
if dbClaim.Status.NewDB.MinStorageGB != reqInfo.HostParams.MinStorageGB {
dbClaim.Status.NewDB.MinStorageGB = reqInfo.HostParams.MinStorageGB
}
if reqInfo.HostParams.Engine == string(v1.Postgres) && int(dbClaim.Status.NewDB.MaxStorageGB) != int(reqInfo.HostParams.MaxStorageGB) {
if reqInfo.HostParams.Type == string(v1.Postgres) && int(dbClaim.Status.NewDB.MaxStorageGB) != int(reqInfo.HostParams.MaxStorageGB) {
dbClaim.Status.NewDB.MaxStorageGB = reqInfo.HostParams.MaxStorageGB
}
} else {
Expand Down Expand Up @@ -1116,11 +1116,11 @@ func (r *DatabaseClaimReconciler) getParameterGroupName(hostParams *hostparams.H

switch dbType {
case v1.Postgres:
return hostName + "-" + (strings.Split(hostParams.EngineVersion, "."))[0]
return hostName + "-" + (strings.Split(hostParams.DBVersion, "."))[0]
case v1.AuroraPostgres:
return hostName + "-a-" + (strings.Split(hostParams.EngineVersion, "."))[0]
return hostName + "-a-" + (strings.Split(hostParams.DBVersion, "."))[0]
default:
return hostName + "-" + (strings.Split(hostParams.EngineVersion, "."))[0]
return hostName + "-" + (strings.Split(hostParams.DBVersion, "."))[0]
}
}

Expand Down Expand Up @@ -1340,11 +1340,11 @@ func updateHostPortStatus(status *v1.Status, host, port, sslMode string) {
}

func updateClusterStatus(status *v1.Status, hostParams *hostparams.HostParams) {
status.DBVersion = hostParams.EngineVersion
status.Type = v1.DatabaseType(hostParams.Engine)
status.DBVersion = hostParams.DBVersion
status.Type = v1.DatabaseType(hostParams.Type)
status.Shape = hostParams.Shape
status.MinStorageGB = hostParams.MinStorageGB
if hostParams.Engine == string(v1.Postgres) {
if hostParams.Type == string(v1.Postgres) {
status.MaxStorageGB = hostParams.MaxStorageGB
}
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/databaseclaim/gcpprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ func (r *DatabaseClaimReconciler) manageDBClusterGCP(ctx context.Context, reqInf
}

logr.Info("creating_crossplane_dbcluster", "name", dbHostName)
validationError := params.CheckEngineVersion()
if validationError != nil {
logr.Error(validationError, "invalid_db_version")
return false, validationError
}
dbCluster = &crossplanegcp.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: dbHostName,
Expand All @@ -202,7 +197,7 @@ func (r *DatabaseClaimReconciler) manageDBClusterGCP(ctx context.Context, reqInf
Enabled: ptr.To(true),
},

DatabaseVersion: getAlloyDBVersion(&params.EngineVersion),
DatabaseVersion: getAlloyDBVersion(&params.DBVersion),

DeletionPolicy: ptr.To(string(params.DeletionPolicy)),

Expand Down Expand Up @@ -312,10 +307,6 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstanceGCP(ctx context.Contex
}, dbInstance)
if err != nil {
if errors.IsNotFound(err) {
validationError := params.CheckEngineVersion()
if validationError != nil {
return false, validationError
}
dbInstance = &crossplanegcp.Instance{
ObjectMeta: metav1.ObjectMeta{
Name: dbHostName,
Expand Down
Loading

0 comments on commit 8124ea5

Please sign in to comment.