@@ -2,6 +2,7 @@ package controllers
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "time"
78
@@ -124,6 +125,7 @@ var _ = Describe("SuperGraph controller", func() {
124125 },
125126 Spec : v1beta1.SuperGraphSchemaSpec {},
126127 }
128+
127129 Expect (k8sClient .Create (ctx , schema )).Should (Succeed ())
128130 configMapName := fmt .Sprintf ("supergraph-schema-%s" , schemaName )
129131 instanceLookupKey := types.NamespacedName {Name : schemaName , Namespace : "default" }
@@ -135,6 +137,8 @@ var _ = Describe("SuperGraph controller", func() {
135137 }
136138
137139 schema .Status .ConfigMap .Name = configMapName
140+ schema .Status .ObservedSHA256Checksum = "dummy-check"
141+
138142 return k8sClient .Status ().Update (ctx , schema )
139143 }, timeout , interval ).Should (Not (HaveOccurred ()))
140144
@@ -223,11 +227,54 @@ var _ = Describe("SuperGraph controller", func() {
223227 "app.kubernetes.io/name" : "apollo-router" ,
224228 }))
225229
230+ Expect (reconciledInstance .Spec .Template .ObjectMeta .Annotations ).To (Equal (map [string ]string {
231+ "apollo-controller/schema-checksum" : schema .Status .ObservedSHA256Checksum ,
232+ }))
233+
226234 Expect (reconciledInstance .Spec .Template .Spec .Containers [0 ].Name ).To (Equal ("router" ))
227235 Expect (reconciledInstance .Spec .Template .Spec .Containers [0 ].Image ).To (Equal ("ghcr.io/apollographql/router:v2.9.0" ))
228236 Expect (reconciledInstance .OwnerReferences [0 ].Name ).Should (Equal (supergraphName ))
229237 })
230238
239+ It ("updates the deployment if the referenced schema checksum changes" , func () {
240+ ctx := context .Background ()
241+
242+ schema = & v1beta1.SuperGraphSchema {
243+ ObjectMeta : metav1.ObjectMeta {
244+ Name : schemaName ,
245+ Namespace : "default" ,
246+ },
247+ Spec : v1beta1.SuperGraphSchemaSpec {},
248+ }
249+ instanceLookupKey := types.NamespacedName {Name : schemaName , Namespace : "default" }
250+
251+ Eventually (func () error {
252+ err := k8sClient .Get (ctx , instanceLookupKey , schema )
253+ if err != nil {
254+ return err
255+ }
256+
257+ schema .Status .ObservedSHA256Checksum = "dummy-check-v2"
258+ return k8sClient .Status ().Update (ctx , schema )
259+ }, timeout , interval ).Should (Not (HaveOccurred ()))
260+
261+ instanceLookupKey = types.NamespacedName {Name : fmt .Sprintf ("apollo-router-%s" , supergraphName ), Namespace : "default" }
262+ reconciledInstance := & appsv1.Deployment {}
263+
264+ Eventually (func () error {
265+ err := k8sClient .Get (ctx , instanceLookupKey , reconciledInstance )
266+ if err != nil {
267+ return err
268+ }
269+
270+ if reconciledInstance .Spec .Template .ObjectMeta .Annotations ["apollo-controller/schema-checksum" ] != "dummy-check-v2" {
271+ return errors .New ("schema checksum not updated" )
272+ }
273+
274+ return nil
275+ }, timeout , interval ).Should (BeNil ())
276+ })
277+
231278 It ("cleans up" , func () {
232279 ctx := context .Background ()
233280 Expect (k8sClient .Delete (ctx , supergraph )).Should (Succeed ())
0 commit comments