Skip to content

Commit

Permalink
Use common memcached.GetMemcachedServerListWithInetString()
Browse files Browse the repository at this point in the history
Use common func to retrieve the memcached server list for a
memcached instance.
  • Loading branch information
stuggi committed Mar 11, 2024
1 parent 0ac0e42 commit cb12734
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 32 deletions.
26 changes: 2 additions & 24 deletions controllers/manila_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"strings"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -49,7 +48,6 @@ import (
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -473,7 +471,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
//
// Check for required memcached used for caching
//
memcached, err := r.getManilaMemcached(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(
Expand Down Expand Up @@ -866,7 +864,7 @@ func (r *ManilaReconciler) generateServiceConfig(
string(databaseSecret.Data[mariadbv1.DatabasePasswordSelector]),
instance.Status.DatabaseHostname,
manila.DatabaseCRName),
"MemcachedServersWithInet": strings.Join(memcached.Status.ServerListWithInet, ","),
"MemcachedServersWithInet": memcached.GetMemcachedServerListWithInetString(),
}

// create httpd vhost template parameters
Expand Down Expand Up @@ -1059,26 +1057,6 @@ func (r *ManilaReconciler) transportURLCreateOrUpdate(ctx context.Context, insta
return transportURL, op, err
}

// getManilaMemcached - gets the Memcached instance used for Manila cache backend
func (r *ManilaReconciler) getManilaMemcached(
ctx context.Context,
h *helper.Helper,
instance *manilav1beta1.Manila,
) (*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
}

func (r *ManilaReconciler) ensureDB(
ctx context.Context,
h *helper.Helper,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/go-logr/logr v1.4.1
github.com/onsi/ginkgo/v2 v2.16.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.20240308113717-eaf5876d69c3
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240220135139-2dc967b0f6de
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240224182407-3b6c02b195f6
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240224182407-3b6c02b195f6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,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.20240308113717-eaf5876d69c3 h1:GJgS/TApDzvNj6lyEr1du6twi539QT2LOu5pqU0dZdA=
github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240308113717-eaf5876d69c3/go.mod h1:yPqJ+WU8jApuDXNUjpTxMafihuZpX3Yik9ZXqGaxYBQ=
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240220135139-2dc967b0f6de h1:2OxiGrl3iT/KYBNKddfQUCF6FAaGrNqrHGisEHtU3ZQ=
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240220135139-2dc967b0f6de/go.mod h1:YyoDWNxCFstwhVRAcEh2X6bXBG0ML5iEhOYQhltgqi4=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240224182407-3b6c02b195f6 h1:mWYmNGOWZY/d24sqGq3uNw0vdUJon4n/rYkhdVqiGgc=
Expand Down
8 changes: 6 additions & 2 deletions test/functional/manila_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ var _ = Describe("Manila controller", func() {

BeforeEach(func() {
memcachedSpec = memcachedv1.MemcachedSpec{
Replicas: ptr.To(int32(3)),
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
Replicas: ptr.To[int32](3),
},
}
})

Expand Down Expand Up @@ -640,7 +642,9 @@ var _ = Describe("Manila controller", func() {
// are removed from unused accounts since that's part of what we are testing
SetupCR: func(accountName types.NamespacedName) {
memcachedSpec = memcachedv1.MemcachedSpec{
Replicas: ptr.To(int32(3)),
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
Replicas: ptr.To[int32](3),
},
}

spec := GetDefaultManilaSpec()
Expand Down
4 changes: 3 additions & 1 deletion test/functional/manilaapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ var _ = Describe("ManilaAPI controller", func() {

BeforeEach(func() {
memcachedSpec = memcachedv1.MemcachedSpec{
Replicas: ptr.To(int32(3)),
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
Replicas: ptr.To[int32](3),
},
}
apiSpec := GetDefaultManilaAPISpec()
apiSpec["customServiceConfig"] = "foo=bar"
Expand Down
4 changes: 3 additions & 1 deletion test/functional/manilascheduler_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ var _ = Describe("ManilaScheduler controller", func() {

BeforeEach(func() {
memcachedSpec = memcachedv1.MemcachedSpec{
Replicas: ptr.To(int32(3)),
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
Replicas: ptr.To[int32](3),
},
}
schedSpec := GetDefaultManilaSchedulerSpec()
schedSpec["customServiceConfig"] = "foo=bar"
Expand Down
4 changes: 3 additions & 1 deletion test/functional/manilashare_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ var _ = Describe("ManilaShare controller", func() {

BeforeEach(func() {
memcachedSpec = memcachedv1.MemcachedSpec{
Replicas: ptr.To(int32(3)),
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
Replicas: ptr.To[int32](3),
},
}
shareSpec := GetDefaultManilaShareSpec()
shareSpec["customServiceConfig"] = "foo=bar"
Expand Down

0 comments on commit cb12734

Please sign in to comment.