@@ -24,15 +24,15 @@ import (
24
24
. "github.com/onsi/gomega" //revive:disable:dot-imports
25
25
26
26
//revive:disable-next-line:dot-imports
27
+ topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
28
+ keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
29
+ condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
27
30
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
31
+ mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers"
28
32
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
29
33
"github.com/openstack-k8s-operators/placement-operator/pkg/placement"
30
34
corev1 "k8s.io/api/core/v1"
31
35
"k8s.io/apimachinery/pkg/types"
32
-
33
- keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
34
- condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
35
- mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers"
36
36
)
37
37
38
38
var _ = Describe ("PlacementAPI controller" , func () {
@@ -880,12 +880,6 @@ var _ = Describe("PlacementAPI controller", func() {
880
880
881
881
When ("A PlacementAPI is created with a wrong topologyref" , func () {
882
882
BeforeEach (func () {
883
- // Build the topology Spec
884
- topologySpec := GetSampleTopologySpec ()
885
- // Create Test Topologies
886
- for _ , t := range names .PlacementAPITopologies {
887
- CreateTopology (t , topologySpec )
888
- }
889
883
spec := GetDefaultPlacementAPISpec ()
890
884
spec ["topologyRef" ] = map [string ]interface {}{
891
885
"name" : "foo" ,
@@ -914,16 +908,26 @@ var _ = Describe("PlacementAPI controller", func() {
914
908
})
915
909
})
916
910
When ("A PlacementAPI is created with topologyref" , func () {
911
+ var topologyRef , topologyRefAlt * topologyv1.TopoRef
917
912
BeforeEach (func () {
918
- // Build the topology Spec
919
- topologySpec := GetSampleTopologySpec ()
913
+ // Define the two topology references used in this test
914
+ topologyRef = & topologyv1.TopoRef {
915
+ Name : names .PlacementAPITopologies [0 ].Name ,
916
+ Namespace : names .PlacementAPITopologies [0 ].Namespace ,
917
+ }
918
+ topologyRefAlt = & topologyv1.TopoRef {
919
+ Name : names .PlacementAPITopologies [1 ].Name ,
920
+ Namespace : names .PlacementAPITopologies [1 ].Namespace ,
921
+ }
920
922
// Create Test Topologies
921
923
for _ , t := range names .PlacementAPITopologies {
924
+ // Build the topology Spec
925
+ topologySpec , _ := GetSampleTopologySpec (t .Name )
922
926
CreateTopology (t , topologySpec )
923
927
}
924
928
spec := GetDefaultPlacementAPISpec ()
925
929
spec ["topologyRef" ] = map [string ]interface {}{
926
- "name" : names . PlacementAPITopologies [ 0 ] .Name ,
930
+ "name" : topologyRef .Name ,
927
931
}
928
932
placement := CreatePlacementAPI (names .PlacementAPIName , spec )
929
933
DeferCleanup (th .DeleteInstance , placement )
@@ -948,9 +952,17 @@ var _ = Describe("PlacementAPI controller", func() {
948
952
949
953
It ("sets topology in CR status" , func () {
950
954
Eventually (func (g Gomega ) {
955
+ tp := GetTopology (types.NamespacedName {
956
+ Name : topologyRef .Name ,
957
+ Namespace : topologyRef .Namespace ,
958
+ })
959
+ finalizers := tp .GetFinalizers ()
960
+ g .Expect (finalizers ).To (HaveLen (1 ))
951
961
placement := GetPlacementAPI (names .PlacementAPIName )
952
962
g .Expect (placement .Status .LastAppliedTopology ).ToNot (BeNil ())
953
- g .Expect (placement .Status .LastAppliedTopology .Name ).To (Equal (names .PlacementAPITopologies [0 ].Name ))
963
+ g .Expect (placement .Status .LastAppliedTopology ).To (Equal (topologyRef ))
964
+ g .Expect (finalizers ).To (ContainElement (
965
+ fmt .Sprintf ("openstack.org/placementapi-%s" , names .PlacementAPIName .Name )))
954
966
}, timeout , interval ).Should (Succeed ())
955
967
956
968
th .ExpectCondition (
@@ -963,23 +975,38 @@ var _ = Describe("PlacementAPI controller", func() {
963
975
964
976
It ("sets topology in resource specs" , func () {
965
977
Eventually (func (g Gomega ) {
966
- g . Expect ( th . GetDeployment ( names . DeploymentName ). Spec . Template . Spec . TopologySpreadConstraints ). ToNot ( BeNil () )
978
+ _ , topologySpecObj := GetSampleTopologySpec ( topologyRef . Name )
967
979
g .Expect (th .GetDeployment (names .DeploymentName ).Spec .Template .Spec .Affinity ).To (BeNil ())
980
+ g .Expect (th .GetDeployment (names .DeploymentName ).Spec .Template .Spec .TopologySpreadConstraints ).ToNot (BeNil ())
981
+ g .Expect (th .GetDeployment (names .DeploymentName ).Spec .Template .Spec .TopologySpreadConstraints ).To (Equal (topologySpecObj ))
968
982
}, timeout , interval ).Should (Succeed ())
969
983
})
970
984
It ("updates topology when the reference changes" , func () {
971
985
Eventually (func (g Gomega ) {
972
986
placement := GetPlacementAPI (names .PlacementAPIName )
973
- g .Expect (placement .Status .LastAppliedTopology ).ToNot (BeNil ())
974
- g .Expect (placement .Status .LastAppliedTopology .Name ).To (Equal (names .PlacementAPITopologies [0 ].Name ))
975
- placement .Spec .TopologyRef .Name = names .PlacementAPITopologies [1 ].Name
987
+ placement .Spec .TopologyRef .Name = topologyRefAlt .Name
976
988
g .Expect (k8sClient .Update (ctx , placement )).To (Succeed ())
977
989
}, timeout , interval ).Should (Succeed ())
978
990
979
991
Eventually (func (g Gomega ) {
992
+ tp := GetTopology (types.NamespacedName {
993
+ Name : topologyRefAlt .Name ,
994
+ Namespace : topologyRefAlt .Namespace ,
995
+ })
996
+ finalizers := tp .GetFinalizers ()
997
+ g .Expect (finalizers ).To (HaveLen (1 ))
980
998
placement := GetPlacementAPI (names .PlacementAPIName )
981
999
g .Expect (placement .Status .LastAppliedTopology ).ToNot (BeNil ())
982
- g .Expect (placement .Status .LastAppliedTopology .Name ).To (Equal (names .PlacementAPITopologies [1 ].Name ))
1000
+ g .Expect (placement .Status .LastAppliedTopology ).To (Equal (topologyRefAlt ))
1001
+ g .Expect (finalizers ).To (ContainElement (
1002
+ fmt .Sprintf ("openstack.org/placementapi-%s" , names .PlacementAPIName .Name )))
1003
+ // Verify the previous referenced topology has no finalizers
1004
+ tp = GetTopology (types.NamespacedName {
1005
+ Name : topologyRef .Name ,
1006
+ Namespace : topologyRef .Namespace ,
1007
+ })
1008
+ finalizers = tp .GetFinalizers ()
1009
+ g .Expect (finalizers ).To (BeEmpty ())
983
1010
}, timeout , interval ).Should (Succeed ())
984
1011
985
1012
th .ExpectCondition (
@@ -1006,6 +1033,18 @@ var _ = Describe("PlacementAPI controller", func() {
1006
1033
g .Expect (th .GetDeployment (names .DeploymentName ).Spec .Template .Spec .TopologySpreadConstraints ).To (BeNil ())
1007
1034
g .Expect (th .GetDeployment (names .DeploymentName ).Spec .Template .Spec .Affinity ).ToNot (BeNil ())
1008
1035
}, timeout , interval ).Should (Succeed ())
1036
+
1037
+ // Verify the existing topologies have no finalizer anymore
1038
+ Eventually (func (g Gomega ) {
1039
+ for _ , topology := range names .PlacementAPITopologies {
1040
+ tp := GetTopology (types.NamespacedName {
1041
+ Name : topology .Name ,
1042
+ Namespace : topology .Namespace ,
1043
+ })
1044
+ finalizers := tp .GetFinalizers ()
1045
+ g .Expect (finalizers ).To (BeEmpty ())
1046
+ }
1047
+ }, timeout , interval ).Should (Succeed ())
1009
1048
})
1010
1049
})
1011
1050
0 commit comments