Skip to content

Commit

Permalink
Merge pull request #121 from vshn/feature/anode_selector_support
Browse files Browse the repository at this point in the history
Add support nodeSelector for MariaDB offering
  • Loading branch information
TheBigLee authored Jan 12, 2024
2 parents 9fc67c4 + 7d64c39 commit fabffdc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions apis/vshn/v1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions apis/vshn/v1/dbaas_vshn_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
16 changes: 16 additions & 0 deletions pkg/common/utils/plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/comp-functions/functions/vshnmariadb/mariadb_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS
}

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{}{
"existingSecret": secretName,
Expand Down Expand Up @@ -228,6 +233,7 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS
"podSecurityContext": map[string]interface{}{
"enabled": !svc.GetBoolFromCompositionConfig("isOpenshift"),
},
"nodeSelector": nodeSelector,
}

return values, nil
Expand Down

0 comments on commit fabffdc

Please sign in to comment.