Skip to content

Commit

Permalink
add option to change default k8s sheduler
Browse files Browse the repository at this point in the history
Signed-off-by: adrixop95 <adrixop95@me.com>
  • Loading branch information
Adrixop95 committed May 9, 2023
1 parent a64055a commit 4630df6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/v1/cluster_types.go
Expand Up @@ -135,6 +135,12 @@ type ClusterSpec struct {
// +optional
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

// Name for custom sheduler when the default one cannot be used
// If not defined, it defaults to `default-scheduler`.
// More info: https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/
// +optional
SchedulerName string `json:"schedulerName,omitempty"`

// The UID of the `postgres` user inside the image, defaults to `26`
// +kubebuilder:default:=26
PostgresUID int64 `json:"postgresUID,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/postgresql.cnpg.io_clusters.yaml
Expand Up @@ -2847,6 +2847,11 @@ spec:
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
schedulerName:
description: 'Name for custom sheduler when the default one cannot
be used If not defined, it defaults to `default-scheduler`. More
info: https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/'
type: string
seccompProfile:
description: 'The SeccompProfile applied to every Pod and Container.
Defaults to: `RuntimeDefault`'
Expand Down
1 change: 1 addition & 0 deletions docs/src/api_reference.md
Expand Up @@ -360,6 +360,7 @@ Name | Description
`inheritedMetadata ` | Metadata that will be inherited by all objects related to the Cluster | [*EmbeddedObjectMetadata](#EmbeddedObjectMetadata)
`imageName ` | Name of the container image, supporting both tags (`<image>:<tag>`) and digests for deterministic and repeatable deployments (`<image>:<tag>@sha256:<digestValue>`) | string
`imagePullPolicy ` | Image pull policy. One of `Always`, `Never` or `IfNotPresent`. If not defined, it defaults to `IfNotPresent`. Cannot be updated. More info: https://kubernetes.io/docs/concepts/containers/images#updating-images | corev1.PullPolicy
`schedulerName ` | Name for custom sheduler when the default one cannot be used if not defined, it defaults to `default-scheduler`. More info: https://kubernetes.io/docs/concepts/scheduling-eviction/kube-scheduler/ | string
`postgresUID ` | The UID of the `postgres` user inside the image, defaults to `26` | int64
`postgresGID ` | The GID of the `postgres` user inside the image, defaults to `26` | int64
`instances ` | Number of instances required in the cluster - *mandatory* | int
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/plugin/pgbench/pgbench.go
Expand Up @@ -115,6 +115,7 @@ func (cmd *pgBenchCommand) getCluster(ctx context.Context) (apiv1.Cluster, error

func (cmd *pgBenchCommand) buildJob(cluster apiv1.Cluster) *batchv1.Job {
clusterImageName := cluster.Spec.ImageName
clusterShedulerName := cluster.Spec.SchedulerName
labels := map[string]string{
"pbBenchJob": cluster.Name,
}
Expand Down Expand Up @@ -161,6 +162,7 @@ func (cmd *pgBenchCommand) buildJob(cluster apiv1.Cluster) *batchv1.Job {
},
},
},
SchedulerName: clusterShedulerName,
Containers: []corev1.Container{
{
Name: "pgbench",
Expand Down
1 change: 1 addition & 0 deletions pkg/specs/jobs.go
Expand Up @@ -271,6 +271,7 @@ func createPrimaryJob(cluster apiv1.Cluster, nodeSerial int, role jobRole, initC
InitContainers: []corev1.Container{
createBootstrapContainer(cluster),
},
SchedulerName: cluster.Spec.SchedulerName,
Containers: []corev1.Container{
{
Name: string(role),
Expand Down
5 changes: 3 additions & 2 deletions pkg/specs/pods.go
Expand Up @@ -352,8 +352,9 @@ func PodWithExistingStorage(cluster apiv1.Cluster, nodeSerial int) *corev1.Pod {
InitContainers: []corev1.Container{
createBootstrapContainer(cluster),
},
Containers: createPostgresContainers(cluster, envConfig),
Volumes: createPostgresVolumes(cluster, podName),
SchedulerName: cluster.Spec.SchedulerName,
Containers: createPostgresContainers(cluster, envConfig),
Volumes: createPostgresVolumes(cluster, podName),
SecurityContext: CreatePodSecurityContext(
cluster.GetSeccompProfile(),
cluster.GetPostgresUID(),
Expand Down

0 comments on commit 4630df6

Please sign in to comment.