Skip to content

Commit 4b9ccf8

Browse files
Merge pull request #543 from fmount/topology_optimize
Optmize handling topology logic
2 parents 7144328 + ffee0fd commit 4b9ccf8

File tree

7 files changed

+15
-52
lines changed

7 files changed

+15
-52
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
require (
66
github.com/onsi/ginkgo/v2 v2.20.1
77
github.com/onsi/gomega v1.34.1
8-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d
8+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462
99
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b
1010
k8s.io/api v0.29.15
1111
k8s.io/apimachinery v0.29.15

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7474
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
7575
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E=
7676
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
77-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d h1:/C+ysubV00VYrqGFhQlDeQ5tUtnhIWPwQUc8MOfCEBA=
78-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d/go.mod h1:IY5zp1GRhacGMvjZMUZQ0LlxWDaogIRb/4H3by1Pivk=
77+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462 h1:hWdJM9hB/GSFjXc7E7b9L+2H4ZfCOxygceMiYXR4kKc=
78+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462/go.mod h1:+l+sclC6YCRcLcvS3UEGKBf8xya8aExMrmHeA9tMg+k=
7979
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=
8080
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
8181
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

controllers/funcs.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ type topologyHandler interface {
8888
SetLastAppliedTopology(t *topologyv1.TopoRef)
8989
}
9090

91-
// GetLastAppliedTopologyRef - Returns a TopoRef object that can be passed to the
92-
// Handle topology logic
93-
func GetLastAppliedTopologyRef(t topologyHandler, ns string) *topologyv1.TopoRef {
94-
lastAppliedTopologyName := ""
95-
if l := t.GetLastAppliedTopology(); l != nil {
96-
lastAppliedTopologyName = l.Name
97-
}
98-
return &topologyv1.TopoRef{
99-
Name: lastAppliedTopologyName,
100-
Namespace: ns,
101-
}
102-
}
103-
10491
func ensureTopology(
10592
ctx context.Context,
10693
helper *helper.Helper,
@@ -114,7 +101,7 @@ func ensureTopology(
114101
ctx,
115102
helper,
116103
instance.GetSpecTopologyRef(),
117-
GetLastAppliedTopologyRef(instance, helper.GetBefore().GetNamespace()),
104+
instance.GetLastAppliedTopology(),
118105
finalizer,
119106
defaultLabelSelector,
120107
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/onsi/ginkgo/v2 v2.20.1
99
github.com/onsi/gomega v1.34.1
1010
github.com/openshift/api v3.9.0+incompatible
11-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d
11+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462
1212
github.com/openstack-k8s-operators/ironic-operator/api v0.0.0-00010101000000-000000000000
1313
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250406092234-10f5f7e5b5a9
1414
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7878
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
7979
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E=
8080
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
81-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d h1:/C+ysubV00VYrqGFhQlDeQ5tUtnhIWPwQUc8MOfCEBA=
82-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250403063905-eb287d52f38d/go.mod h1:IY5zp1GRhacGMvjZMUZQ0LlxWDaogIRb/4H3by1Pivk=
81+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462 h1:hWdJM9hB/GSFjXc7E7b9L+2H4ZfCOxygceMiYXR4kKc=
82+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462/go.mod h1:+l+sclC6YCRcLcvS3UEGKBf8xya8aExMrmHeA9tMg+k=
8383
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250406092234-10f5f7e5b5a9 h1:Q1yMkuwIOCtGQJDsKYAbspJU5b6emRvoKw5VyPXfiak=
8484
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250406092234-10f5f7e5b5a9/go.mod h1:klMsoleakNm0dfNR9ePkL5pNZQsIyx4WMLaHDKIkTt4=
8585
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=

tests/functional/base_test.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
. "github.com/onsi/gomega" //revive:disable:dot-imports
2424

25-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2625
ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1"
2726
ironic_pkg "github.com/openstack-k8s-operators/ironic-operator/pkg/ironic"
2827
ironic_inspector_pkg "github.com/openstack-k8s-operators/ironic-operator/pkg/ironicinspector"
@@ -691,26 +690,3 @@ func GetSampleTopologySpec(label string) (map[string]interface{}, []corev1.Topol
691690
}
692691
return topologySpec, topologySpecObj
693692
}
694-
695-
// CreateTopology - Creates a Topology CR based on the spec passed as input
696-
func CreateTopology(topology types.NamespacedName, spec map[string]interface{}) client.Object {
697-
raw := map[string]interface{}{
698-
"apiVersion": "topology.openstack.org/v1beta1",
699-
"kind": "Topology",
700-
"metadata": map[string]interface{}{
701-
"name": topology.Name,
702-
"namespace": topology.Namespace,
703-
},
704-
"spec": spec,
705-
}
706-
return th.CreateUnstructured(raw)
707-
}
708-
709-
// GetTopology - Returns the referenced Topology
710-
func GetTopology(name types.NamespacedName) *topologyv1.Topology {
711-
instance := &topologyv1.Topology{}
712-
Eventually(func(g Gomega) {
713-
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
714-
}, timeout, interval).Should(Succeed())
715-
return instance
716-
}

tests/functional/ironic_controller_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ var _ = Describe("Ironic controller", func() {
702702
for _, t := range ironicNames.IronicTopologies {
703703
// Build the topology Spec
704704
topologySpec, _ := GetSampleTopologySpec(t.Name)
705-
CreateTopology(t, topologySpec)
705+
infra.CreateTopology(t, topologySpec)
706706
}
707707
DeferCleanup(
708708
k8sClient.Delete,
@@ -756,7 +756,7 @@ var _ = Describe("Ironic controller", func() {
756756

757757
It("sets topology in CR status", func() {
758758
Eventually(func(g Gomega) {
759-
tp := GetTopology(types.NamespacedName{
759+
tp := infra.GetTopology(types.NamespacedName{
760760
Name: topologyRef.Name,
761761
Namespace: topologyRef.Namespace,
762762
})
@@ -814,7 +814,7 @@ var _ = Describe("Ironic controller", func() {
814814
}, timeout, interval).Should(Succeed())
815815

816816
Eventually(func(g Gomega) {
817-
tp := GetTopology(types.NamespacedName{
817+
tp := infra.GetTopology(types.NamespacedName{
818818
Name: expectedTopology.Name,
819819
Namespace: expectedTopology.Namespace,
820820
})
@@ -841,7 +841,7 @@ var _ = Describe("Ironic controller", func() {
841841

842842
// Get the previous topology and verify there are no finalizers
843843
// anymore
844-
tp = GetTopology(types.NamespacedName{
844+
tp = infra.GetTopology(types.NamespacedName{
845845
Name: topologyRef.Name,
846846
Namespace: topologyRef.Namespace,
847847
})
@@ -871,7 +871,7 @@ var _ = Describe("Ironic controller", func() {
871871
Name: ironicNames.IronicTopologies[1].Name,
872872
Namespace: ironicNames.IronicTopologies[1].Namespace,
873873
}
874-
tp := GetTopology(types.NamespacedName{
874+
tp := infra.GetTopology(types.NamespacedName{
875875
Name: expectedTopology.Name,
876876
Namespace: expectedTopology.Namespace,
877877
})
@@ -889,7 +889,7 @@ var _ = Describe("Ironic controller", func() {
889889
Name: ironicNames.IronicTopologies[2].Name,
890890
Namespace: ironicNames.IronicTopologies[2].Namespace,
891891
}
892-
tp := GetTopology(types.NamespacedName{
892+
tp := infra.GetTopology(types.NamespacedName{
893893
Name: expectedTopology.Name,
894894
Namespace: expectedTopology.Namespace,
895895
})
@@ -907,7 +907,7 @@ var _ = Describe("Ironic controller", func() {
907907
Name: ironicNames.IronicTopologies[3].Name,
908908
Namespace: ironicNames.IronicTopologies[3].Namespace,
909909
}
910-
tp := GetTopology(types.NamespacedName{
910+
tp := infra.GetTopology(types.NamespacedName{
911911
Name: expectedTopology.Name,
912912
Namespace: expectedTopology.Namespace,
913913
})
@@ -951,7 +951,7 @@ var _ = Describe("Ironic controller", func() {
951951
Eventually(func(g Gomega) {
952952
for _, topology := range ironicNames.IronicTopologies {
953953
// Get the current topology and verify there are no finalizers
954-
tp := GetTopology(types.NamespacedName{
954+
tp := infra.GetTopology(types.NamespacedName{
955955
Name: topology.Name,
956956
Namespace: topology.Namespace,
957957
})

0 commit comments

Comments
 (0)