@@ -39,6 +39,7 @@ import (
3939 "sigs.k8s.io/controller-runtime/pkg/client"
4040
4141 "github.com/fluxcd/pkg/apis/meta"
42+ "github.com/fluxcd/pkg/runtime/dependency"
4243 "github.com/fluxcd/pkg/testserver"
4344 sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
4445
@@ -359,6 +360,74 @@ spec:
359360 Expect (k8sClient .Get (context .Background (), types.NamespacedName {Name : "test" , Namespace : namespace .Name }, deployment )).To (Succeed ())
360361 Expect (deployment .Spec .Selector .MatchLabels ["app" ]).To (Equal ("v2" ))
361362 })
363+
364+ It ("should get resource fail for dependencies not ready" , func () {
365+ manifests := []testserver.File {
366+ {
367+ Name : "deployment.yaml" ,
368+ Body : deploymentManifest (namespace .Name , "v3" ),
369+ },
370+ }
371+ artifact , err := httpServer .ArtifactFromFiles (manifests )
372+ Expect (err ).NotTo (HaveOccurred ())
373+
374+ url := fmt .Sprintf ("%s/%s" , httpServer .URL (), artifact )
375+
376+ repositoryName := types.NamespacedName {
377+ Name : fmt .Sprintf ("%s" , randStringRunes (5 )),
378+ Namespace : namespace .Name ,
379+ }
380+ repository := readyGitRepository (repositoryName , url , "v3" , "" )
381+ Expect (k8sClient .Create (context .Background (), repository )).To (Succeed ())
382+ Expect (k8sClient .Status ().Update (context .Background (), repository )).To (Succeed ())
383+ defer k8sClient .Delete (context .Background (), repository )
384+
385+ kName := types.NamespacedName {
386+ Name : fmt .Sprintf ("%s" , randStringRunes (5 )),
387+ Namespace : namespace .Name ,
388+ }
389+ k := & kustomizev1.Kustomization {
390+ ObjectMeta : metav1.ObjectMeta {
391+ Name : kName .Name ,
392+ Namespace : kName .Namespace ,
393+ },
394+ Spec : kustomizev1.KustomizationSpec {
395+ KubeConfig : kubeconfig ,
396+ Interval : metav1.Duration {Duration : reconciliationInterval },
397+ Path : "./" ,
398+ Prune : true ,
399+ DependsOn : []dependency.CrossNamespaceDependencyReference {
400+ {
401+ Name : "test-kustomization" ,
402+ },
403+ },
404+ SourceRef : kustomizev1.CrossNamespaceSourceReference {
405+ Kind : sourcev1 .GitRepositoryKind ,
406+ Name : repository .Name ,
407+ },
408+ Suspend : false ,
409+ Timeout : & metav1.Duration {Duration : 60 * time .Second },
410+ Validation : "client" ,
411+ Force : true ,
412+ },
413+ }
414+ Expect (k8sClient .Create (context .Background (), k )).To (Succeed ())
415+ defer k8sClient .Delete (context .Background (), k )
416+
417+ got := & kustomizev1.Kustomization {}
418+ Eventually (func () bool {
419+ _ = k8sClient .Get (context .Background (), kName , got )
420+ for _ , c := range got .Status .Conditions {
421+ if c .Reason == meta .DependencyNotReadyReason {
422+ return true
423+ }
424+ }
425+ return false
426+ }, timeout , interval ).Should (BeTrue ())
427+
428+ deployment := & appsv1.Deployment {}
429+ Expect (k8sClient .Get (context .Background (), types.NamespacedName {Name : "test" , Namespace : namespace .Name }, deployment )).NotTo (Succeed ())
430+ })
362431 })
363432 })
364433})
0 commit comments