77 "context"
88 "errors"
99 "fmt"
10+ "maps"
1011 "os"
1112 "slices"
1213 "strings"
@@ -595,6 +596,7 @@ func TestNewJob(t *testing.T) {
595596 strictHostKeyChecks bool
596597 clientObjects []runtime.Object
597598 deploymentTolerations []corev1.Toleration
599+ deploymentNodeSelector map [string ]string
598600 expectedInitContainers []corev1.Container
599601 expectedContainers []corev1.Container
600602 expectedVolumes []corev1.Volume
@@ -1741,6 +1743,9 @@ func TestNewJob(t *testing.T) {
17411743 Operator : "Exists" ,
17421744 },
17431745 },
1746+ deploymentNodeSelector : map [string ]string {
1747+ "node-role.kubernetes.io/fleet" : "true" ,
1748+ },
17441749 clientObjects : []runtime.Object {
17451750 & corev1.ConfigMap {
17461751 ObjectMeta : metav1.ObjectMeta {
@@ -1760,7 +1765,7 @@ func TestNewJob(t *testing.T) {
17601765 for name , test := range tests {
17611766 t .Run (name , func (t * testing.T ) {
17621767 r := GitJobReconciler {
1763- Client : getFakeClient (test .deploymentTolerations , test .clientObjects ... ),
1768+ Client : getFakeClient (test .deploymentTolerations , test .deploymentNodeSelector , test . clientObjects ... ),
17641769 Scheme : scheme ,
17651770 Image : "test" ,
17661771 Clock : RealClock {},
@@ -1867,6 +1872,12 @@ func TestNewJob(t *testing.T) {
18671872 if ! cmp .Equal (expectedTolerations , job .Spec .Template .Spec .Tolerations ) {
18681873 t .Fatalf ("job tolerations differ. Expecting: %v and found: %v" , test .deploymentTolerations , job .Spec .Template .Spec .Tolerations )
18691874 }
1875+
1876+ expectedNodeSelector := map [string ]string {"kubernetes.io/os" : "linux" }
1877+ maps .Copy (expectedNodeSelector , test .deploymentNodeSelector )
1878+ if ! cmp .Equal (expectedNodeSelector , job .Spec .Template .Spec .NodeSelector ) {
1879+ t .Fatalf ("job node selector differs. Expecting: %v and found: %v" , expectedNodeSelector , job .Spec .Template .Spec .NodeSelector )
1880+ }
18701881 })
18711882 }
18721883}
@@ -2380,7 +2391,7 @@ func TestGenerateJob_EnvVars(t *testing.T) {
23802391 }
23812392
23822393 r := GitJobReconciler {
2383- Client : getFakeClient ([]corev1.Toleration {}),
2394+ Client : getFakeClient ([]corev1.Toleration {}, nil ),
23842395 Image : "test" ,
23852396 Clock : RealClock {},
23862397 SystemNamespace : config .DefaultNamespace ,
@@ -2747,18 +2758,18 @@ ignore this line as well`,
27472758 }
27482759}
27492760
2750- func getFakeClient (tolerations []corev1.Toleration , objs ... runtime.Object ) client.Client {
2761+ func getFakeClient (tolerations []corev1.Toleration , nodeSelector map [ string ] string , objs ... runtime.Object ) client.Client {
27512762 scheme := runtime .NewScheme ()
27522763 utilruntime .Must (corev1 .AddToScheme (scheme ))
27532764 utilruntime .Must (appsv1 .AddToScheme (scheme ))
27542765
27552766 return fake .NewClientBuilder ().
27562767 WithScheme (scheme ).
27572768 WithRuntimeObjects (objs ... ).
2758- WithRuntimeObjects (getFleetControllerDeployment (tolerations )).Build ()
2769+ WithRuntimeObjects (getFleetControllerDeployment (tolerations , nodeSelector )).Build ()
27592770}
27602771
2761- func getFleetControllerDeployment (tolerations []corev1.Toleration ) * appsv1.Deployment {
2772+ func getFleetControllerDeployment (tolerations []corev1.Toleration , nodeSelector map [ string ] string ) * appsv1.Deployment {
27622773 return & appsv1.Deployment {
27632774 ObjectMeta : metav1.ObjectMeta {
27642775 Name : config .ManagerConfigName ,
@@ -2767,7 +2778,8 @@ func getFleetControllerDeployment(tolerations []corev1.Toleration) *appsv1.Deplo
27672778 Spec : appsv1.DeploymentSpec {
27682779 Template : corev1.PodTemplateSpec {
27692780 Spec : corev1.PodSpec {
2770- Tolerations : tolerations ,
2781+ Tolerations : tolerations ,
2782+ NodeSelector : nodeSelector ,
27712783 },
27722784 },
27732785 },
0 commit comments