Skip to content

Commit d0004bb

Browse files
Merge pull request #565 from fmount/topology_optimize
Optmize handling topology logic
2 parents 909226b + 754bd77 commit d0004bb

File tree

8 files changed

+12
-58
lines changed

8 files changed

+12
-58
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/google/uuid v1.6.0
88
github.com/gophercloud/gophercloud v1.14.1
99
github.com/onsi/gomega v1.34.1
10-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250411133346-82683c873656
10+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462
1111
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b
1212
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250408123225-0d9e9b82c41b
1313
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250408123225-0d9e9b82c41b

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
8080
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
8181
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E=
8282
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
83-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250411133346-82683c873656 h1:T/hODJCaWH13MV+7+snYAA1d/uuDYW0K20QDCfSSXj4=
84-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250411133346-82683c873656/go.mod h1:+l+sclC6YCRcLcvS3UEGKBf8xya8aExMrmHeA9tMg+k=
83+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462 h1:hWdJM9hB/GSFjXc7E7b9L+2H4ZfCOxygceMiYXR4kKc=
84+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462/go.mod h1:+l+sclC6YCRcLcvS3UEGKBf8xya8aExMrmHeA9tMg+k=
8585
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=
8686
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
8787
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250408123225-0d9e9b82c41b h1:WvlbQ1nXX3MuVKVXdd2o5EK0RDMy5x/VtV845ReUlM4=

api/v1beta1/keystoneapi_types.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,6 @@ func (c *KeystoneExtraMounts) Propagate(svc []storage.PropagationType) []storage
360360
return vl
361361
}
362362

363-
// GetLastTopologyRef - Returns a TopoRef object that can be passed to the
364-
// Handle topology logic
365-
func (instance KeystoneAPI) GetLastAppliedTopologyRef() *topologyv1.TopoRef {
366-
lastAppliedTopologyName := ""
367-
if instance.Status.LastAppliedTopology != nil {
368-
lastAppliedTopologyName = instance.Status.LastAppliedTopology.Name
369-
}
370-
return &topologyv1.TopoRef{
371-
Name: lastAppliedTopologyName,
372-
Namespace: instance.Namespace,
373-
}
374-
}
375-
376363
// ValidateTopology -
377364
func (instance *KeystoneAPISpecCore) ValidateTopology(
378365
basePath *field.Path,

controllers/keystoneapi_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ func (r *KeystoneAPIReconciler) reconcileNormal(
10641064
ctx,
10651065
helper,
10661066
instance.Spec.TopologyRef,
1067-
instance.GetLastAppliedTopologyRef(),
1067+
instance.Status.LastAppliedTopology,
10681068
instance.Name,
10691069
labels.GetLabelSelector(serviceLabels),
10701070
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.6
99
github.com/onsi/ginkgo/v2 v2.20.1
1010
github.com/onsi/gomega v1.34.1
11-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250411133346-82683c873656
11+
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250414173555-d17cbc245462
1212
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240213125925-e40975f3db7e
1313
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b
1414
github.com/openstack-k8s-operators/lib-common/modules/openstack 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.20250411133346-82683c873656 h1:T/hODJCaWH13MV+7+snYAA1d/uuDYW0K20QDCfSSXj4=
82-
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250411133346-82683c873656/go.mod h1:+l+sclC6YCRcLcvS3UEGKBf8xya8aExMrmHeA9tMg+k=
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/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b h1:T+N6xOT2NP+hVp2K1xl/NV3uheVHu38CcBuW+8uOBYw=
8484
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250408123225-0d9e9b82c41b/go.mod h1:A9Ohw5Q90YOGhcDF4ZHkMr5RArz3phoBu9+ibbYDKG4=
8585
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250408123225-0d9e9b82c41b h1:WvlbQ1nXX3MuVKVXdd2o5EK0RDMy5x/VtV845ReUlM4=

tests/functional/base_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"k8s.io/apimachinery/pkg/types"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828

29-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
3029
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
3130
keystone_base "github.com/openstack-k8s-operators/keystone-operator/pkg/keystone"
3231
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
@@ -164,38 +163,6 @@ func GetSampleTopologySpec(label string) (map[string]interface{}, []corev1.Topol
164163
return topologySpec, topologySpecObj
165164
}
166165

167-
// CreateTopology - Creates a Topology CR based on the spec passed as input
168-
func CreateTopology(
169-
topology types.NamespacedName,
170-
spec map[string]interface{},
171-
) (client.Object, topologyv1.TopoRef) {
172-
raw := map[string]interface{}{
173-
"apiVersion": "topology.openstack.org/v1beta1",
174-
"kind": "Topology",
175-
"metadata": map[string]interface{}{
176-
"name": topology.Name,
177-
"namespace": topology.Namespace,
178-
},
179-
"spec": spec,
180-
}
181-
// other than creating the topology based on the raw spec, we return the
182-
// TopoRef that can be referenced
183-
topologyRef := topologyv1.TopoRef{
184-
Name: topology.Name,
185-
Namespace: topology.Namespace,
186-
}
187-
return th.CreateUnstructured(raw), topologyRef
188-
}
189-
190-
// GetTopology - Returns the referenced Topology
191-
func GetTopology(name types.NamespacedName) *topologyv1.Topology {
192-
instance := &topologyv1.Topology{}
193-
Eventually(func(g Gomega) {
194-
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed())
195-
}, timeout, interval).Should(Succeed())
196-
return instance
197-
}
198-
199166
// GetExtraMounts - Utility function that simulates extraMounts pointing
200167
// to a secret
201168
func GetExtraMounts(kemName string, kemPath string) []map[string]interface{} {

tests/functional/keystoneapi_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ var _ = Describe("Keystone controller", func() {
15731573
for _, t := range keystoneAPITopologies {
15741574
// Build the topology Spec
15751575
topologySpec, _ := GetSampleTopologySpec(t.Name)
1576-
CreateTopology(t, topologySpec)
1576+
infra.CreateTopology(t, topologySpec)
15771577
}
15781578
spec := GetDefaultKeystoneAPISpec()
15791579
spec["topologyRef"] = map[string]interface{}{
@@ -1613,7 +1613,7 @@ var _ = Describe("Keystone controller", func() {
16131613

16141614
It("check topology has been applied", func() {
16151615
Eventually(func(g Gomega) {
1616-
tp := GetTopology(types.NamespacedName{
1616+
tp := infra.GetTopology(types.NamespacedName{
16171617
Name: topologyRef.Name,
16181618
Namespace: topologyRef.Namespace,
16191619
})
@@ -1642,7 +1642,7 @@ var _ = Describe("Keystone controller", func() {
16421642
}, timeout, interval).Should(Succeed())
16431643

16441644
Eventually(func(g Gomega) {
1645-
tp := GetTopology(types.NamespacedName{
1645+
tp := infra.GetTopology(types.NamespacedName{
16461646
Name: topologyRefAlt.Name,
16471647
Namespace: topologyRefAlt.Namespace,
16481648
})
@@ -1656,7 +1656,7 @@ var _ = Describe("Keystone controller", func() {
16561656
fmt.Sprintf("openstack.org/keystoneapi-%s", keystoneAPIName.Name)))
16571657

16581658
// Verify the previous referenced topology has no finalizers
1659-
tp = GetTopology(types.NamespacedName{
1659+
tp = infra.GetTopology(types.NamespacedName{
16601660
Name: topologyRef.Name,
16611661
Namespace: topologyRef.Namespace,
16621662
})
@@ -1685,7 +1685,7 @@ var _ = Describe("Keystone controller", func() {
16851685
// Verify the existing topologies have no finalizer anymore
16861686
Eventually(func(g Gomega) {
16871687
for _, topology := range keystoneAPITopologies {
1688-
tp := GetTopology(types.NamespacedName{
1688+
tp := infra.GetTopology(types.NamespacedName{
16891689
Name: topology.Name,
16901690
Namespace: topology.Namespace,
16911691
})

0 commit comments

Comments
 (0)