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 authored and openshift-merge-bot[bot] committed Mar 12, 2024
1 parent 2fc1351 commit d9341ba
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 42 deletions.
20 changes: 1 addition & 19 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,24 +546,6 @@ func getMemcachedInstance(instance *novav1.Nova, cellTemplate novav1.NovaCellTem
return instance.Spec.MemcachedInstance
}

// getMemcached - gets the Memcached instance cell specific used for nova services cache backend
func getMemcached(
ctx context.Context,
h *helper.Helper,
namespaceName string,
mamcachedName string,
) (*memcachedv1.Memcached, error) {
memcached := &memcachedv1.Memcached{}
err := h.GetClient().Get(
ctx,
types.NamespacedName{
Name: mamcachedName,
Namespace: namespaceName,
},
memcached)
return memcached, err
}

// ensureMemcached - gets the Memcached instance cell specific used for nova services cache backend
func ensureMemcached(
ctx context.Context,
Expand All @@ -572,7 +554,7 @@ func ensureMemcached(
mamcachedName string,
conditionUpdater conditionUpdater,
) (*memcachedv1.Memcached, error) {
memcached, err := getMemcached(ctx, h, namespaceName, mamcachedName)
memcached, err := memcachedv1.GetMemcachedByName(ctx, h, mamcachedName, namespaceName)
if err != nil {
if k8s_errors.IsNotFound(err) {
conditionUpdater.Set(condition.FalseCondition(
Expand Down
7 changes: 3 additions & 4 deletions controllers/novaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"strings"

v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -461,8 +460,8 @@ func (r *NovaAPIReconciler) generateConfigs(
"transport_url": string(secret.Data[TransportURLSelector]),
"log_file": "/var/log/nova/nova-api.log",
"tls": false,
"MemcachedServers": strings.Join(memcachedInstance.Status.ServerList, ","),
"MemcachedServersWithInet": strings.Join(memcachedInstance.Status.ServerListWithInet, ","),
"MemcachedServers": memcachedInstance.GetMemcachedServerListString(),
"MemcachedServersWithInet": memcachedInstance.GetMemcachedServerListWithInetString(),
}
// create httpd vhost template parameters
httpdVhostConfig := map[string]interface{}{}
Expand Down Expand Up @@ -793,7 +792,7 @@ func (r *NovaAPIReconciler) reconcileDelete(
}

// Remove our finalizer from Memcached
memcached, err := getMemcached(ctx, h, instance.Namespace, instance.Spec.MemcachedInstance)
memcached, err := memcachedv1.GetMemcachedByName(ctx, h, instance.Spec.MemcachedInstance, instance.Namespace)
if memcached != nil {
if controllerutil.RemoveFinalizer(memcached, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, memcached)
Expand Down
7 changes: 3 additions & 4 deletions controllers/novaconductor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"strings"

v1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -414,8 +413,8 @@ func (r *NovaConductorReconciler) generateConfigs(
"default_project_domain": "Default", // fixme
"default_user_domain": "Default", // fixme
"transport_url": string(secret.Data[TransportURLSelector]),
"MemcachedServers": strings.Join(memcachedInstance.Status.ServerList, ","),
"MemcachedServersWithInet": strings.Join(memcachedInstance.Status.ServerListWithInet, ","),
"MemcachedServers": memcachedInstance.GetMemcachedServerListString(),
"MemcachedServersWithInet": memcachedInstance.GetMemcachedServerListWithInetString(),
}
if len(instance.Spec.APIDatabaseHostname) > 0 {
apiDatabaseAccount, apiDbSecret, err := mariadbv1.GetAccountAndSecret(ctx, h, instance.Spec.APIDatabaseAccount, instance.Namespace)
Expand Down Expand Up @@ -694,7 +693,7 @@ func (r *NovaConductorReconciler) reconcileDelete(

// Remove our finalizer from Memcached

memcached, _ := getMemcached(ctx, h, instance.Namespace, instance.Spec.MemcachedInstance)
memcached, _ := memcachedv1.GetMemcachedByName(ctx, h, instance.Spec.MemcachedInstance, instance.Namespace)
if memcached != nil {
if controllerutil.RemoveFinalizer(memcached, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, memcached)
Expand Down
7 changes: 3 additions & 4 deletions controllers/novametadata_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"net/url"
"strings"

v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -457,8 +456,8 @@ func (r *NovaMetadataReconciler) generateConfigs(
"transport_url": string(secret.Data[TransportURLSelector]),
"tls": false,
"ServerName": fmt.Sprintf("%s.%s.svc", novametadata.ServiceName, instance.Namespace),
"MemcachedServers": strings.Join(memcachedInstance.Status.ServerList, ","),
"MemcachedServersWithInet": strings.Join(memcachedInstance.Status.ServerListWithInet, ","),
"MemcachedServers": memcachedInstance.GetMemcachedServerListString(),
"MemcachedServersWithInet": memcachedInstance.GetMemcachedServerListWithInetString(),
}

var db *mariadbv1.Database
Expand Down Expand Up @@ -710,7 +709,7 @@ func (r *NovaMetadataReconciler) reconcileDelete(
// when the service is scaled in or deleted

// Remove our finalizer from Memcached
memcached, _ := getMemcached(ctx, h, instance.Namespace, instance.Spec.MemcachedInstance)
memcached, _ := memcachedv1.GetMemcachedByName(ctx, h, instance.Spec.MemcachedInstance, instance.Namespace)
if memcached != nil {
if controllerutil.RemoveFinalizer(memcached, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, memcached)
Expand Down
7 changes: 3 additions & 4 deletions controllers/novanovncproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"strings"

v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -406,8 +405,8 @@ func (r *NovaNoVNCProxyReconciler) generateConfigs(
"openstack_region_name": "regionOne", // fixme
"default_project_domain": "Default", // fixme
"default_user_domain": "Default", // fixme
"MemcachedServers": strings.Join(memcachedInstance.Status.ServerList, ","),
"MemcachedServersWithInet": strings.Join(memcachedInstance.Status.ServerListWithInet, ","),
"MemcachedServers": memcachedInstance.GetMemcachedServerListString(),
"MemcachedServersWithInet": memcachedInstance.GetMemcachedServerListWithInetString(),
}
if instance.Spec.TLS.GenericService.Enabled() {
templateParameters["SSLCertificateFile"] = fmt.Sprintf("/etc/pki/tls/certs/%s.crt", novncproxy.ServiceName)
Expand Down Expand Up @@ -625,7 +624,7 @@ func (r *NovaNoVNCProxyReconciler) reconcileDelete(
Log := r.GetLogger(ctx)
Log.Info("Reconciling delete")
// Remove our finalizer from Memcached
memcached, _ := getMemcached(ctx, h, instance.Namespace, instance.Spec.MemcachedInstance)
memcached, _ := memcachedv1.GetMemcachedByName(ctx, h, instance.Spec.MemcachedInstance, instance.Namespace)

if memcached != nil {
if controllerutil.RemoveFinalizer(memcached, h.GetFinalizer()) {
Expand Down
7 changes: 3 additions & 4 deletions controllers/novascheduler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"strings"

v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -487,8 +486,8 @@ func (r *NovaSchedulerReconciler) generateConfigs(
"default_project_domain": "Default", // fixme
"default_user_domain": "Default", // fixme
"transport_url": string(secret.Data[TransportURLSelector]),
"MemcachedServers": strings.Join(memcachedInstance.Status.ServerList, ","),
"MemcachedServersWithInet": strings.Join(memcachedInstance.Status.ServerListWithInet, ","),
"MemcachedServers": memcachedInstance.GetMemcachedServerListString(),
"MemcachedServersWithInet": memcachedInstance.GetMemcachedServerListWithInetString(),
}

var tlsCfg *tls.Service
Expand Down Expand Up @@ -629,7 +628,7 @@ func (r *NovaSchedulerReconciler) reconcileDelete(
Log.Info("Reconciling delete")

// Remove our finalizer from Memcached
memcached, _ := getMemcached(ctx, h, instance.Namespace, instance.Spec.MemcachedInstance)
memcached, _ := memcachedv1.GetMemcachedByName(ctx, h, instance.Spec.MemcachedInstance, instance.Namespace)

if memcached != nil {
if controllerutil.RemoveFinalizer(memcached, h.GetFinalizer()) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
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.20240304123904-038a5ec77a70
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.20240307113114-033a606862c3
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240306153230-dc65ab49ebc0
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240306153230-dc65ab49ebc0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240304123904-038a5ec77a70 h1:aLQuVEQKwV2nM4n232/7TnA50t5DD05deEvKyl6Gd5Y=
github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240304123904-038a5ec77a70/go.mod h1:yPqJ+WU8jApuDXNUjpTxMafihuZpX3Yik9ZXqGaxYBQ=
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.20240307113114-033a606862c3 h1:jMxdglPqLMuIM+s1aC1tYXz/NihB/BaMyutReg2fXpg=
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240307113114-033a606862c3/go.mod h1:UruMUJ8wX1fQPcY3olYneAx04Z1alk2Phq33prkoLZw=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240306153230-dc65ab49ebc0 h1:1Q/9F3SAKvLN9vX+YxwaEB0WvBekj9eakQPoQbI1K6w=
Expand Down

0 comments on commit d9341ba

Please sign in to comment.