From 7d64c39e39847e141ba7201e9f55aee5e8dc49c7 Mon Sep 17 00:00:00 2001 From: Nicolas Bigler Date: Thu, 11 Jan 2024 11:07:17 +0100 Subject: [PATCH] Ad support nodeSelector for MariaDB offering Signed-off-by: Nicolas Bigler --- apis/vshn/v1/common_types.go | 6 ++++++ apis/vshn/v1/dbaas_vshn_postgresql.go | 6 ------ pkg/common/utils/plans.go | 16 ++++++++++++++++ .../functions/vshnmariadb/mariadb_deploy.go | 6 ++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/apis/vshn/v1/common_types.go b/apis/vshn/v1/common_types.go index e16b86c257..5b6f4f398b 100644 --- a/apis/vshn/v1/common_types.go +++ b/apis/vshn/v1/common_types.go @@ -137,6 +137,12 @@ type VSHNDBaaSNetworkSpec struct { ServiceType string `json:"serviceType,omitempty"` } +// VSHNDBaaSSchedulingSpec contains settings to control the scheduling of an instance. +type VSHNDBaaSSchedulingSpec struct { + // NodeSelector is a selector which must match a node’s labels for the pod to be scheduled on that node + NodeSelector map[string]string `json:"nodeSelector,omitempty"` +} + // VSHNMonitoring contains settings to configure monitoring aspects of databases managed by VSHN type VSHNMonitoring struct { // AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/apis/vshn/v1/dbaas_vshn_postgresql.go b/apis/vshn/v1/dbaas_vshn_postgresql.go index 4c855eb2a1..a27d2589ff 100644 --- a/apis/vshn/v1/dbaas_vshn_postgresql.go +++ b/apis/vshn/v1/dbaas_vshn_postgresql.go @@ -149,12 +149,6 @@ type VSHNDBaaSPostgresExtension struct { Name string `json:"name,omitempty"` } -// VSHNDBaaSSchedulingSpec contains settings to control the scheduling of an instance. -type VSHNDBaaSSchedulingSpec struct { - // NodeSelector is a selector which must match a node’s labels for the pod to be scheduled on that node - NodeSelector map[string]string `json:"nodeSelector,omitempty"` -} - type VSHNPostgreSQLBackup struct { // +kubebuilder:validation:Pattern=^(\*|([0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])|\*\/([0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])) (\*|([0-9]|1[0-9]|2[0-3])|\*\/([0-9]|1[0-9]|2[0-3])) (\*|([1-9]|1[0-9]|2[0-9]|3[0-1])|\*\/([1-9]|1[0-9]|2[0-9]|3[0-1])) (\*|([1-9]|1[0-2])|\*\/([1-9]|1[0-2])) (\*|([0-6])|\*\/([0-6]))$ Schedule string `json:"schedule,omitempty"` diff --git a/pkg/common/utils/plans.go b/pkg/common/utils/plans.go index 9bbea99890..7262d3cb59 100644 --- a/pkg/common/utils/plans.go +++ b/pkg/common/utils/plans.go @@ -20,6 +20,9 @@ type plan struct { Enabled bool `json:"enabled"` Memory string `json:"memory"` } `json:"Size"` + Scheduling struct { + NodeSelector map[string]string `json:"nodeSelector"` + } `json:"Scheduling"` } // FetchPlansFromCluster will fetch the plans from the current PLANS_NAMESPACE namespace and parse them into Resources. @@ -58,6 +61,19 @@ func FetchPlansFromConfig(ctx context.Context, svc *runtime.ServiceRuntime, plan return r, err } +func FetchNodeSelectorFromConfig(ctx context.Context, svc *runtime.ServiceRuntime, plan string, nodeSelector map[string]string) (map[string]string, error) { + if nodeSelector != nil { + return nodeSelector, nil + } + p := Plans{} + + err := json.Unmarshal([]byte(svc.Config.Data["plans"]), &p) + if err != nil { + return map[string]string{}, err + } + return p[plan].Scheduling.NodeSelector, nil +} + func convertPlanToResource(plan string, p Plans) (Resources, error) { r := Resources{} var err error diff --git a/pkg/comp-functions/functions/vshnmariadb/mariadb_deploy.go b/pkg/comp-functions/functions/vshnmariadb/mariadb_deploy.go index e40eedb292..c5820baa32 100644 --- a/pkg/comp-functions/functions/vshnmariadb/mariadb_deploy.go +++ b/pkg/comp-functions/functions/vshnmariadb/mariadb_deploy.go @@ -83,6 +83,11 @@ func createObjectHelmRelease(ctx context.Context, comp *vshnv1.VSHNMariaDB, svc } reqMem, reqCPU, mem, cpu, disk := common.GetResources(&comp.Spec.Parameters.Size, resources) + nodeSelector, err := utils.FetchNodeSelectorFromConfig(ctx, svc, plan, comp.Spec.Parameters.Scheduling.NodeSelector) + + if err != nil { + err = fmt.Errorf("cannot fetch nodeSelector from the composition config: %w", err) + } values := map[string]interface{}{ "fullnameOverride": comp.GetName(), @@ -127,6 +132,7 @@ func createObjectHelmRelease(ctx context.Context, comp *vshnv1.VSHNMariaDB, svc "podSecurityContext": map[string]interface{}{ "enabled": !svc.GetBoolFromCompositionConfig("isOpenshift"), }, + "nodeSelector": nodeSelector, } vb, err := json.Marshal(values)