Skip to content

Commit f0d0dac

Browse files
author
lamai93
committed
Added nodeSelector field that is forwarded to the created pods of the specific group.
1 parent 06d4af4 commit f0d0dac

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

pkg/apis/deployment/v1alpha/server_group_spec.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,20 @@ type ServerGroupSpec struct {
4949
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
5050
// ServiceAccountName specifies the name of the service account used for Pods in this group.
5151
ServiceAccountName *string `json:"serviceAccountName,omitempty"`
52+
// NodeSelector speficies a set of selectors for nodes
53+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
5254
}
5355

5456
// GetCount returns the value of count.
5557
func (s ServerGroupSpec) GetCount() int {
5658
return util.IntOrDefault(s.Count)
5759
}
5860

61+
// GetNodeSelector returns the selectors for nodes of this group
62+
func (s ServerGroupSpec) GetNodeSelector() map[string]string {
63+
return s.NodeSelector
64+
}
65+
5966
// GetArgs returns the value of args.
6067
func (s ServerGroupSpec) GetArgs() []string {
6168
return s.Args
@@ -194,6 +201,9 @@ func (s *ServerGroupSpec) SetDefaultsFrom(source ServerGroupSpec) {
194201
if s.ServiceAccountName == nil {
195202
s.ServiceAccountName = util.NewStringOrNil(source.ServiceAccountName)
196203
}
204+
if s.NodeSelector == nil {
205+
s.NodeSelector = source.NodeSelector
206+
}
197207
setDefaultsFromResourceList(&s.Resources.Limits, source.Resources.Limits)
198208
setDefaultsFromResourceList(&s.Resources.Requests, source.Resources.Requests)
199209
}

pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
179179
serviceAccountName := ""
180180

181181
if err := k8sutil.CreateArangodPod(ib.KubeCli, true, ib.APIObject, role, id, podName, "", image, "", "", ib.Spec.GetImagePullPolicy(), "", false, terminationGracePeriod, args, nil, nil, nil, nil,
182-
tolerations, serviceAccountName, "", ""); err != nil {
182+
tolerations, serviceAccountName, "", "", nil); err != nil {
183183
log.Debug().Err(err).Msg("Failed to create image ID pod")
184184
return true, maskAny(err)
185185
}

pkg/deployment/resources/pod_creator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
529529
requireUUID := group == api.ServerGroupDBServers && m.IsInitialized
530530
finalizers := r.createPodFinalizers(group)
531531
if err := k8sutil.CreateArangodPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, m.PersistentVolumeClaimName, imageInfo.ImageID, lifecycleImage, alpineImage, spec.GetImagePullPolicy(),
532-
engine, requireUUID, terminationGracePeriod, args, env, finalizers, livenessProbe, readinessProbe, tolerations, serviceAccountName, tlsKeyfileSecretName, rocksdbEncryptionSecretName); err != nil {
532+
engine, requireUUID, terminationGracePeriod, args, env, finalizers, livenessProbe, readinessProbe, tolerations, serviceAccountName, tlsKeyfileSecretName, rocksdbEncryptionSecretName,
533+
groupSpec.GetNodeSelector()); err != nil {
533534
return maskAny(err)
534535
}
535536
log.Debug().Str("pod-name", m.PodName).Msg("Created pod")
@@ -600,7 +601,7 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, memberID string,
600601
affinityWithRole = api.ServerGroupDBServers.AsRole()
601602
}
602603
if err := k8sutil.CreateArangoSyncPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, imageInfo.ImageID, lifecycleImage, spec.GetImagePullPolicy(), terminationGracePeriod, args, env,
603-
livenessProbe, tolerations, serviceAccountName, tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName, affinityWithRole); err != nil {
604+
livenessProbe, tolerations, serviceAccountName, tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName, affinityWithRole, groupSpec.GetNodeSelector()); err != nil {
604605
return maskAny(err)
605606
}
606607
log.Debug().Str("pod-name", m.PodName).Msg("Created pod")

pkg/util/k8sutil/pods.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func initLifecycleContainer(image string) (v1.Container, error) {
389389
}
390390

391391
// newPod creates a basic Pod for given settings.
392-
func newPod(deploymentName, ns, role, id, podName string, finalizers []string, tolerations []v1.Toleration, serviceAccountName string) v1.Pod {
392+
func newPod(deploymentName, ns, role, id, podName string, finalizers []string, tolerations []v1.Toleration, serviceAccountName string, nodeSelector map[string]string) v1.Pod {
393393
hostname := CreatePodHostName(deploymentName, role, id)
394394
p := v1.Pod{
395395
ObjectMeta: metav1.ObjectMeta{
@@ -403,6 +403,7 @@ func newPod(deploymentName, ns, role, id, podName string, finalizers []string, t
403403
RestartPolicy: v1.RestartPolicyNever,
404404
Tolerations: tolerations,
405405
ServiceAccountName: serviceAccountName,
406+
NodeSelector: nodeSelector,
406407
},
407408
}
408409
return p
@@ -416,9 +417,9 @@ func CreateArangodPod(kubecli kubernetes.Interface, developmentMode bool, deploy
416417
engine string, requireUUID bool, terminationGracePeriod time.Duration,
417418
args []string, env map[string]EnvValue, finalizers []string,
418419
livenessProbe *HTTPProbeConfig, readinessProbe *HTTPProbeConfig, tolerations []v1.Toleration, serviceAccountName string,
419-
tlsKeyfileSecretName, rocksdbEncryptionSecretName string) error {
420+
tlsKeyfileSecretName, rocksdbEncryptionSecretName string, nodeSelector map[string]string) error {
420421
// Prepare basic pod
421-
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, finalizers, tolerations, serviceAccountName)
422+
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, finalizers, tolerations, serviceAccountName, nodeSelector)
422423
terminationGracePeriodSeconds := int64(math.Ceil(terminationGracePeriod.Seconds()))
423424
p.Spec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
424425

@@ -519,9 +520,9 @@ func CreateArangodPod(kubecli kubernetes.Interface, developmentMode bool, deploy
519520
// If another error occurs, that error is returned.
520521
func CreateArangoSyncPod(kubecli kubernetes.Interface, developmentMode bool, deployment APIObject, role, id, podName, image, lifecycleImage string, imagePullPolicy v1.PullPolicy,
521522
terminationGracePeriod time.Duration, args []string, env map[string]EnvValue, livenessProbe *HTTPProbeConfig, tolerations []v1.Toleration, serviceAccountName string,
522-
tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName, affinityWithRole string) error {
523+
tlsKeyfileSecretName, clientAuthCASecretName, masterJWTSecretName, clusterJWTSecretName, affinityWithRole string, nodeSelector map[string]string) error {
523524
// Prepare basic pod
524-
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, nil, tolerations, serviceAccountName)
525+
p := newPod(deployment.GetName(), deployment.GetNamespace(), role, id, podName, nil, tolerations, serviceAccountName, nodeSelector)
525526
terminationGracePeriodSeconds := int64(math.Ceil(terminationGracePeriod.Seconds()))
526527
p.Spec.TerminationGracePeriodSeconds = &terminationGracePeriodSeconds
527528

0 commit comments

Comments
 (0)