@@ -3,22 +3,26 @@ package landscaper_test
33import (
44 "path"
55
6+ openmcpls "github.com/openmcp-project/service-provider-landscaper/api/v1alpha1"
7+
68 "github.com/openmcp-project/mcp-operator/internal/components"
9+ mcpocfg "github.com/openmcp-project/mcp-operator/internal/config"
710 componentutils "github.com/openmcp-project/mcp-operator/internal/utils/components"
811
912 "github.com/openmcp-project/mcp-operator/internal/controller/core/landscaper"
1013
11- lssv1alpha1 "github.com/gardener/landscaper-service/pkg/apis/core/v1alpha1"
1214 . "github.com/onsi/ginkgo/v2"
1315 . "github.com/onsi/gomega"
14- "k8s.io/apimachinery/pkg/api/errors"
16+
17+ . "github.com/openmcp-project/mcp-operator/test/matchers"
18+
19+ lssv1alpha1 "github.com/gardener/landscaper-service/pkg/apis/core/v1alpha1"
20+ apierrors "k8s.io/apimachinery/pkg/api/errors"
1521 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1622 "k8s.io/apimachinery/pkg/types"
1723 "sigs.k8s.io/controller-runtime/pkg/client"
1824 "sigs.k8s.io/controller-runtime/pkg/reconcile"
1925
20- . "github.com/openmcp-project/mcp-operator/test/matchers"
21-
2226 "github.com/openmcp-project/controller-utils/pkg/testing"
2327
2428 cconst "github.com/openmcp-project/mcp-operator/api/constants"
@@ -349,11 +353,11 @@ var _ = Describe("CO-1153 Landscaper Controller", func() {
349353 // now it should be gone
350354 err = env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (ls ), ls )
351355 Expect (err ).To (HaveOccurred ())
352- Expect (errors .IsNotFound (err )).To (BeTrue ())
356+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
353357
354358 err = env .Client (testutils .LaaSCoreCluster ).Get (env .Ctx , types.NamespacedName {Name : "test" , Namespace : "test" }, & lssv1alpha1.LandscaperDeployment {})
355359 Expect (err ).To (HaveOccurred ())
356- Expect (errors .IsNotFound (err )).To (BeTrue ())
360+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
357361
358362 as := & openmcpv1alpha1.APIServer {}
359363 Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , types.NamespacedName {Name : "test" , Namespace : "test" }, as )).To (Succeed ())
@@ -437,7 +441,7 @@ var _ = Describe("CO-1153 Landscaper Controller", func() {
437441
438442 err = env .Client (testutils .LaaSCoreCluster ).Get (env .Ctx , types.NamespacedName {Name : "test" , Namespace : "test" }, & lssv1alpha1.LandscaperDeployment {})
439443 Expect (err ).To (HaveOccurred ())
440- Expect (errors .IsNotFound (err )).To (BeTrue ())
444+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
441445 })
442446
443447 It ("should handle when landscaper is not found" , func () {
@@ -470,7 +474,7 @@ var _ = Describe("CO-1153 Landscaper Controller", func() {
470474
471475 err = env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (ls ), ls )
472476 Expect (err ).To (HaveOccurred ())
473- Expect (errors .IsNotFound (err )).To (BeTrue ())
477+ Expect (apierrors .IsNotFound (err )).To (BeTrue ())
474478
475479 as := & openmcpv1alpha1.APIServer {}
476480 Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , types.NamespacedName {Name : "test" , Namespace : "test" }, as )).To (Succeed ())
@@ -484,4 +488,50 @@ var _ = Describe("CO-1153 Landscaper Controller", func() {
484488 Expect (componentutils .HasDepedencyFinalizer (authz , lsComp .Type ())).To (BeFalse ())
485489 })
486490
491+ Context ("v2" , func () {
492+
493+ BeforeEach (func () {
494+ mcpocfg .Config .Architecture .Landscaper .Version = openmcpv1alpha1 .ArchitectureV2
495+ })
496+
497+ It ("should create a v2 Landscaper object" , func () {
498+ env := testEnvSetup (path .Join ("testdata" , "test-04" ), "" )
499+
500+ ls := & openmcpv1alpha1.Landscaper {}
501+ ls .SetName ("test" )
502+ ls .SetNamespace ("test" )
503+ err := env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (ls ), ls )
504+ Expect (err ).NotTo (HaveOccurred ())
505+
506+ env .ShouldReconcile (lsReconciler , testing .RequestFromObject (ls ))
507+
508+ lsv2 := & openmcpls.Landscaper {}
509+ lsv2 .SetName (ls .Name )
510+ lsv2 .SetNamespace (ls .Namespace )
511+ Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (lsv2 ), lsv2 )).To (Succeed ())
512+
513+ // add dummy finalizer to verify that controller waits for the lsv2 object to be deleted
514+ lsv2 .Finalizers = append (lsv2 .Finalizers , "dummy" )
515+ err = env .Client (testutils .CrateCluster ).Update (env .Ctx , lsv2 )
516+ Expect (err ).NotTo (HaveOccurred ())
517+
518+ Expect (env .Client (testutils .CrateCluster ).Delete (env .Ctx , ls )).To (Succeed ())
519+ env .ShouldReconcile (lsReconciler , testing .RequestFromObject (ls ))
520+ Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (ls ), ls )).To (Succeed ())
521+ Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (lsv2 ), lsv2 )).To (Succeed ())
522+ Expect (ls .DeletionTimestamp .IsZero ()).To (BeFalse ())
523+ Expect (lsv2 .DeletionTimestamp .IsZero ()).To (BeFalse ())
524+
525+ lsv2 .Finalizers = nil
526+ Expect (env .Client (testutils .CrateCluster ).Update (env .Ctx , lsv2 )).To (Succeed ())
527+
528+ Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (ls ), ls )).To (Succeed ())
529+ Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (lsv2 ), lsv2 )).To (MatchError (apierrors .IsNotFound , "not found" ))
530+
531+ env .ShouldReconcile (lsReconciler , testing .RequestFromObject (ls ))
532+ Expect (env .Client (testutils .CrateCluster ).Get (env .Ctx , client .ObjectKeyFromObject (ls ), ls )).To (MatchError (apierrors .IsNotFound , "not found" ))
533+ })
534+
535+ })
536+
487537})
0 commit comments