@@ -26,7 +26,7 @@ import (
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
27
corev1apply "k8s.io/client-go/applyconfigurations/core/v1"
28
28
metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
29
- "k8s.io/utils/pointer "
29
+ "k8s.io/utils/ptr "
30
30
31
31
vkv1alpha1 "github.com/liqotech/liqo/apis/virtualkubelet/v1alpha1"
32
32
liqoconst "github.com/liqotech/liqo/pkg/consts"
@@ -225,7 +225,7 @@ func RemotePodSpec(creation bool, local, remote *corev1.PodSpec, mutators ...Rem
225
225
226
226
// The information about the service account name is not reflected, since the volume is already
227
227
// present, and the remote creation would fail as the corresponding service account is not present.
228
- remote .AutomountServiceAccountToken = pointer . Bool (false )
228
+ remote .AutomountServiceAccountToken = ptr . To (false )
229
229
230
230
// This fields are currently forced to false, to prevent invasive settings on the remote cluster (which might not work).
231
231
remote .HostIPC = false
@@ -283,7 +283,7 @@ func ServiceAccountMutator(apiServerSupport APIServerSupportType, localAnnotatio
283
283
}
284
284
285
285
remote .ServiceAccountName = remoteServiceAccountName
286
- remote .AutomountServiceAccountToken = pointer . Bool (true )
286
+ remote .AutomountServiceAccountToken = ptr . To (true )
287
287
default :
288
288
// Remove the service account name.
289
289
remote .ServiceAccountName = ""
@@ -353,6 +353,64 @@ func AntiAffinityHardMutator(labels map[string]string) RemotePodSpecMutator {
353
353
}
354
354
}
355
355
356
+ // NodeSelectorMutator is a mutator which implements the support to propagate a given node selector constraint.
357
+ func NodeSelectorMutator (nodeSelector map [string ]string ) RemotePodSpecMutator {
358
+ return func (remote * corev1.PodSpec ) {
359
+ if remote .NodeSelector == nil {
360
+ remote .NodeSelector = map [string ]string {}
361
+ }
362
+
363
+ for k , v := range nodeSelector {
364
+ remote .NodeSelector [k ] = v
365
+ }
366
+ }
367
+ }
368
+
369
+ // TolerationsMutator is a mutator which implements the support to propagate tolerations.
370
+ func TolerationsMutator (tolerations []corev1.Toleration ) RemotePodSpecMutator {
371
+ return func (remote * corev1.PodSpec ) {
372
+ remote .Tolerations = append (remote .Tolerations , tolerations ... )
373
+ }
374
+ }
375
+
376
+ // AffinityMutator is a mutator which implements the support to propagate affinity constraints.
377
+ func AffinityMutator (affinity * vkv1alpha1.Affinity ) RemotePodSpecMutator {
378
+ return func (remote * corev1.PodSpec ) {
379
+ if affinity == nil || affinity .NodeAffinity == nil {
380
+ return
381
+ }
382
+
383
+ nodeAffinity := affinity .NodeAffinity .DeepCopy ()
384
+
385
+ if remote .Affinity == nil {
386
+ remote .Affinity = & corev1.Affinity {
387
+ NodeAffinity : nodeAffinity ,
388
+ }
389
+ return
390
+ }
391
+
392
+ if remote .Affinity .NodeAffinity == nil {
393
+ remote .Affinity .NodeAffinity = nodeAffinity
394
+ return
395
+ }
396
+
397
+ if nodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution != nil {
398
+ if remote .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution == nil {
399
+ remote .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution =
400
+ nodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution
401
+ } else {
402
+ remote .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms = append (
403
+ remote .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ,
404
+ nodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ... )
405
+ }
406
+ }
407
+
408
+ remote .Affinity .NodeAffinity .PreferredDuringSchedulingIgnoredDuringExecution =
409
+ append (remote .Affinity .NodeAffinity .PreferredDuringSchedulingIgnoredDuringExecution ,
410
+ nodeAffinity .PreferredDuringSchedulingIgnoredDuringExecution ... )
411
+ }
412
+ }
413
+
356
414
// FilterAntiAffinityLabels filters the label keys which are used to implement the anti-affinity constraints, based on the specified whitelist.
357
415
func FilterAntiAffinityLabels (labels map [string ]string , whitelist string ) map [string ]string {
358
416
if whitelist != "" {
0 commit comments