From bf9e1e9b2ffeabfb54d7f7e9ed85374a4bdc68fe Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 11 Mar 2024 17:31:29 +0100 Subject: [PATCH] Use common memcached.GetMemcachedServerListWithInetString() Use common func to retrieve the memcached server list for a memcached instance. --- api/go.mod | 4 +-- api/go.sum | 8 ++--- controllers/neutronapi_controller.go | 29 +++---------------- go.mod | 6 ++-- go.sum | 12 ++++---- test/functional/neutronapi_controller_test.go | 18 +++++++----- 6 files changed, 30 insertions(+), 47 deletions(-) diff --git a/api/go.mod b/api/go.mod index 58bd75a9..118452d8 100644 --- a/api/go.mod +++ b/api/go.mod @@ -46,8 +46,8 @@ require ( golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/term v0.17.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect diff --git a/api/go.sum b/api/go.sum index 4e7c9715..7f22e1ce 100644 --- a/api/go.sum +++ b/api/go.sum @@ -123,12 +123,12 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= diff --git a/controllers/neutronapi_controller.go b/controllers/neutronapi_controller.go index 51ae084b..61530d58 100644 --- a/controllers/neutronapi_controller.go +++ b/controllers/neutronapi_controller.go @@ -19,7 +19,6 @@ package controllers import ( "context" "fmt" - "strings" "time" "github.com/go-logr/logr" @@ -845,7 +844,7 @@ func (r *NeutronAPIReconciler) reconcileNormal(ctx context.Context, instance *ne instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage) // run check OpenStack secret - end - memcached, err := r.getNeutronMemcached(ctx, helper, instance) + memcached, err := memcachedv1.GetMemcachedByName(ctx, helper, instance.Spec.MemcachedInstance, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { instance.Status.Conditions.Set(condition.FalseCondition( @@ -1436,7 +1435,7 @@ func (r *NeutronAPIReconciler) generateServiceSecrets( return err } - mc, err := r.getNeutronMemcached(ctx, h, instance) + mc, err := memcachedv1.GetMemcachedByName(ctx, h, instance.Spec.MemcachedInstance, instance.Namespace) if err != nil { return err } @@ -1446,8 +1445,8 @@ func (r *NeutronAPIReconciler) generateServiceSecrets( templateParameters["KeystoneInternalURL"] = keystoneInternalURL templateParameters["KeystonePublicURL"] = keystonePublicURL templateParameters["TransportURL"] = transportURL - templateParameters["MemcachedServers"] = strings.Join(mc.Status.ServerList, ",") - templateParameters["MemcachedServersWithInet"] = strings.Join(mc.Status.ServerListWithInet, ",") + templateParameters["MemcachedServers"] = mc.GetMemcachedServerListString() + templateParameters["MemcachedServersWithInet"] = mc.GetMemcachedServerListWithInetString() // Other OpenStack services servicePassword := string(ospSecret.Data[instance.Spec.PasswordSelectors.Service]) @@ -1568,26 +1567,6 @@ func (r *NeutronAPIReconciler) memcachedNamespaceMapFunc(ctx context.Context, cl } } -// getNeutronMemcached - gets the Memcached instance used for neutron cache backend -func (r *NeutronAPIReconciler) getNeutronMemcached( - ctx context.Context, - h *helper.Helper, - instance *neutronv1beta1.NeutronAPI, -) (*memcachedv1.Memcached, error) { - memcached := &memcachedv1.Memcached{} - err := h.GetClient().Get( - ctx, - types.NamespacedName{ - Name: instance.Spec.MemcachedInstance, - Namespace: instance.Namespace, - }, - memcached) - if err != nil { - return nil, err - } - return memcached, err -} - // ensureDB - create neutron DB instance func (r *NeutronAPIReconciler) ensureDB( ctx context.Context, diff --git a/go.mod b/go.mod index a7b8294a..19733aad 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0 github.com/onsi/ginkgo/v2 v2.15.0 github.com/onsi/gomega v1.31.1 - github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240221083751-49edc0df8a12 + github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240312175130-455be042c07f github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240226160457-b1b853eb4600 github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240229121803-169ced56d56e github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240229121803-169ced56d56e @@ -64,8 +64,8 @@ require ( golang.org/x/mod v0.15.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/term v0.17.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.18.0 // indirect diff --git a/go.sum b/go.sum index 7832b1a8..703f9850 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,8 @@ github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 h1:rncLxJBpFGqBztyxCMwNRnMjhhIDOWHJowi6q8G6koI= github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4= -github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240221083751-49edc0df8a12 h1:n+A0L+6w3Yt9iOVWdu0aU8Ig0fICv4luruVjH5kU7KM= -github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240221083751-49edc0df8a12/go.mod h1:2//rIZ8ucDbK+gLxvwmU6uPCm6o/C6GxXJHDo4ye7I8= +github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240312175130-455be042c07f h1:2HYgZbbHngmqWad1Dyz7whg/fEmXtKny2O5HcreoBEc= +github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240312175130-455be042c07f/go.mod h1:qKuzDDDMlAmJn4JWPoUeBEzpAia7J17++hhzR0oPv88= github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240226160457-b1b853eb4600 h1:Lqlkv5CWGlarcjsc1SW2YzhxAVQtQZp0BWEwFUl+OyM= github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240226160457-b1b853eb4600/go.mod h1:YyoDWNxCFstwhVRAcEh2X6bXBG0ML5iEhOYQhltgqi4= github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240229121803-169ced56d56e h1:zpxxz/iI8C09XHBcDYW9prMoODndBBsSmoonRXRXu1Q= @@ -157,12 +157,12 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/test/functional/neutronapi_controller_test.go b/test/functional/neutronapi_controller_test.go index 9350f951..e8a7b3c8 100644 --- a/test/functional/neutronapi_controller_test.go +++ b/test/functional/neutronapi_controller_test.go @@ -32,7 +32,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" @@ -70,7 +70,9 @@ var _ = Describe("NeutronAPI controller", func() { Name: name, } memcachedSpec = memcachedv1.MemcachedSpec{ - Replicas: pointer.Int32(3), + MemcachedSpecCore: memcachedv1.MemcachedSpecCore{ + Replicas: ptr.To(int32(3)), + }, } memcachedName = types.NamespacedName{ Name: "memcached", @@ -621,11 +623,13 @@ var _ = Describe("NeutronAPI controller", func() { Eventually(func() corev1.Secret { return th.GetSecret(secret) }, timeout, interval).ShouldNot(BeNil()) - Expect(th.GetSecret(secret).Data["01-neutron.conf"]).Should( - ContainSubstring("memcache_servers=memcached-0.memcached:11211,memcached-1.memcached:11211,memcached-2.memcached:11211")) - Expect(th.GetSecret(secret).Data["01-neutron.conf"]).Should( - ContainSubstring("memcached_servers=inet:[memcached-0.memcached]:11211,inet:[memcached-1.memcached]:11211,inet:[memcached-2.memcached]:11211")) - + neutronCfg := string(th.GetSecret(secret).Data["01-neutron.conf"]) + Expect(neutronCfg).Should( + ContainSubstring(fmt.Sprintf("memcache_servers=memcached-0.memcached.%s.svc:11211,memcached-1.memcached.%s.svc:11211,memcached-2.memcached.%s.svc:11211", + neutronAPIName.Namespace, neutronAPIName.Namespace, neutronAPIName.Namespace))) + Expect(neutronCfg).Should( + ContainSubstring(fmt.Sprintf("memcached_servers=inet:[memcached-0.memcached.%s.svc]:11211,inet:[memcached-1.memcached.%s.svc]:11211,inet:[memcached-2.memcached.%s.svc]:11211", + neutronAPIName.Namespace, neutronAPIName.Namespace, neutronAPIName.Namespace))) }) It("should create an external Ovn Agent Secret with expected ovn nb and sb connection set", func() {