Skip to content

Commit b0989ee

Browse files
committed
adding ut for binder resources
1 parent a35ed54 commit b0989ee

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

pkg/operator/operands/binder/binder_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"github.com/NVIDIA/KAI-scheduler/pkg/operator/operands/common/test_utils"
2020

2121
appsv1 "k8s.io/api/apps/v1"
22+
v1 "k8s.io/api/core/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224
"k8s.io/utils/ptr"
2325
"sigs.k8s.io/controller-runtime/pkg/client"
2426
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -93,6 +95,60 @@ var _ = Describe("Binder", func() {
9395
Expect(deployment.Labels).To(HaveKeyWithValue("foo", "bar"))
9496
Expect(deployment.Spec.Template.Labels).To(HaveKeyWithValue("kai", "scheduler"))
9597
})
98+
99+
It("sets CDI flag if set in cluser policy", func(ctx context.Context) {
100+
clusterPolicy := &nvidiav1.ClusterPolicy{
101+
ObjectMeta: metav1.ObjectMeta{
102+
Name: "test",
103+
},
104+
Spec: nvidiav1.ClusterPolicySpec{
105+
CDI: nvidiav1.CDIConfigSpec{
106+
Enabled: ptr.To(true),
107+
Default: ptr.To(true),
108+
},
109+
},
110+
}
111+
112+
Expect(fakeKubeClient.Create(ctx, clusterPolicy)).To(Succeed())
113+
objects, err := b.DesiredState(ctx, fakeKubeClient, kaiConfig)
114+
Expect(err).To(BeNil())
115+
116+
deploymentT := test_utils.FindTypeInObjects[*appsv1.Deployment](objects)
117+
Expect(deploymentT).NotTo(BeNil())
118+
Expect((*deploymentT).Spec.Template.Spec.Containers[0].Args).To(ContainElement("--cdi-enabled=true"))
119+
})
120+
})
121+
122+
Context("Reservation Service Account", func() {
123+
It("will not remove current image pull secrets", func(ctx context.Context) {
124+
kaiConfig.Spec.Global.ImagePullSecrets = []string{"test-secret"}
125+
126+
reservationSA := &v1.ServiceAccount{
127+
ObjectMeta: metav1.ObjectMeta{
128+
Namespace: *kaiConfig.Spec.Binder.ResourceReservation.Namespace,
129+
Name: *kaiConfig.Spec.Binder.ResourceReservation.ServiceAccountName,
130+
},
131+
ImagePullSecrets: []v1.LocalObjectReference{
132+
{Name: "existing"},
133+
},
134+
}
135+
Expect(fakeKubeClient.Create(ctx, reservationSA)).To(Succeed())
136+
objects, err := b.DesiredState(ctx, fakeKubeClient, kaiConfig)
137+
Expect(err).To(BeNil())
138+
139+
var newReservationSA *v1.ServiceAccount
140+
for _, obj := range objects {
141+
sa, ok := obj.(*v1.ServiceAccount)
142+
if ok && sa.Name == reservationSA.Name {
143+
newReservationSA = sa
144+
}
145+
}
146+
147+
Expect(newReservationSA).NotTo(BeNil())
148+
Expect(newReservationSA.ImagePullSecrets).To(HaveLen(2))
149+
Expect(newReservationSA.ImagePullSecrets).To(ContainElement(v1.LocalObjectReference{Name: "existing"}))
150+
Expect(newReservationSA.ImagePullSecrets).To(ContainElement(v1.LocalObjectReference{Name: "test-secret"}))
151+
})
96152
})
97153
})
98154
})

0 commit comments

Comments
 (0)