From 788e5b8175fcd4641f7de85a46407e1b37ece3c9 Mon Sep 17 00:00:00 2001 From: Ryan Emerson Date: Thu, 27 Jun 2024 09:48:57 +0100 Subject: [PATCH] Enable RESP and Memcached endpoints by default for Infinispan 15 servers Resolves #2119 --- go.mod | 4 +- go.sum | 9 ++++- .../templates/infinispan-base-15.xml | 13 +----- test/e2e/infinispan/smoke_test.go | 6 +++ test/e2e/utils/common.go | 40 ++++++++++++------- 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index e851554e3..27cc0a005 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/operator-framework/api v0.4.0 github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.44.0 github.com/r3labs/sse/v2 v2.10.0 + github.com/redis/go-redis/v9 v9.5.3 github.com/stretchr/testify v1.9.0 go.uber.org/zap v1.27.0 gopkg.in/cenkalti/backoff.v1 v1.1.0 @@ -31,6 +32,7 @@ require ( github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/emicklei/go-restful v2.16.0+incompatible // indirect github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect @@ -52,7 +54,7 @@ require ( github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect diff --git a/go.sum b/go.sum index 0600fa3a4..db817f3d0 100644 --- a/go.sum +++ b/go.sum @@ -107,13 +107,16 @@ github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -152,6 +155,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -573,6 +578,8 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0= github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= +github.com/redis/go-redis/v9 v9.5.3 h1:fOAp1/uJG+ZtcITgZOfYFmTKPE7n4Vclj1wZFgRciUU= +github.com/redis/go-redis/v9 v9.5.3/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/pkg/templates/templates/infinispan-base-15.xml b/pkg/templates/templates/infinispan-base-15.xml index 15ef8221d..5c48cb0d0 100644 --- a/pkg/templates/templates/infinispan-base-15.xml +++ b/pkg/templates/templates/infinispan-base-15.xml @@ -98,18 +98,7 @@ - - {{ if .Endpoints.Authenticate }} - - - - - - {{ else }} - - {{ end }} - - + diff --git a/test/e2e/infinispan/smoke_test.go b/test/e2e/infinispan/smoke_test.go index 25e98d3d6..35abf469b 100644 --- a/test/e2e/infinispan/smoke_test.go +++ b/test/e2e/infinispan/smoke_test.go @@ -66,6 +66,12 @@ func TestBaseFunctionality(t *testing.T) { verifyLabelsAndAnnotations(assert, require, ispn) verifyDefaultAuthention(require, ispn) verifyScheduling(assert, require, ispn) + + // Verify that the Redis endpoint is accessible + redis := tutils.RedisClientForCluster(ispn, testKube) + size, err := redis.DBSize(context.TODO()).Result() + tutils.ExpectNoError(err) + assert.Equal(int64(0), size) } // Make sure no PVCs were created diff --git a/test/e2e/utils/common.go b/test/e2e/utils/common.go index 6da2e693a..2d050556e 100644 --- a/test/e2e/utils/common.go +++ b/test/e2e/utils/common.go @@ -17,6 +17,7 @@ import ( users "github.com/infinispan/infinispan-operator/pkg/infinispan/security" "github.com/infinispan/infinispan-operator/pkg/infinispan/version" routev1 "github.com/openshift/api/route/v1" + "github.com/redis/go-redis/v9" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -398,10 +399,8 @@ func clientForCluster(i *ispnv1.Infinispan, kube *TestKubernetes) HTTPClient { return NewHTTPClientNoAuth(protocol) } - user := constants.DefaultDeveloperUser - pass, err := users.UserPassword(user, i.GetSecretName(), i.Namespace, kube.Kubernetes, context.TODO()) - ExpectNoError(err) - return NewHTTPClient(user, pass, protocol) + user, pass := userAndPassword(i, kube) + return NewHTTPClient(*user, *pass, protocol) } func HTTPClientForCluster(i *ispnv1.Infinispan, kube *TestKubernetes) HTTPClient { @@ -413,26 +412,18 @@ func HTTPClientForClusterWithVersionManager(i *ispnv1.Infinispan, kube *TestKube } func HTTPSClientForCluster(i *ispnv1.Infinispan, tlsConfig *tls.Config, kube *TestKubernetes) HTTPClient { - - userAndPassword := func() (*string, *string) { - user := constants.DefaultDeveloperUser - pass, err := users.UserPassword(user, i.GetSecretName(), i.Namespace, kube.Kubernetes, context.TODO()) - ExpectNoError(err) - return &user, &pass - } - var client HTTPClient clientCert := i.Spec.Security.EndpointEncryption.ClientCert if clientCert != "" && clientCert != ispnv1.ClientCertNone { if clientCert == ispnv1.ClientCertAuthenticate || !i.IsAuthenticationEnabled() { client = NewClient(authCert, nil, nil, "https", tlsConfig) } else { - user, pass := userAndPassword() + user, pass := userAndPassword(i, kube) client = NewClient(authDigest, user, pass, "https", tlsConfig) } } else { if i.IsAuthenticationEnabled() { - user, pass := userAndPassword() + user, pass := userAndPassword(i, kube) client = NewClient(authDigest, user, pass, "https", tlsConfig) } else { client = NewClient(authNone, nil, nil, "https", tlsConfig) @@ -441,6 +432,20 @@ func HTTPSClientForCluster(i *ispnv1.Infinispan, tlsConfig *tls.Config, kube *Te return kube.WaitForExternalService(i, RouteTimeout, client, nil) } +func RedisClientForCluster(i *ispnv1.Infinispan, kube *TestKubernetes) *redis.Client { + // Create a HTTPClient as this waits for the external service to be ready and prevents unnecessary duplication of code + // We can then use the host and port of the client to initialize the redis client as access is via the Single port + httpClient := HTTPClientForClusterWithVersionManager(i, kube, nil) + user, pass := userAndPassword(i, kube) + httpClient.GetHostAndPort() + return redis.NewClient(&redis.Options{ + Addr: httpClient.GetHostAndPort(), + Username: *user, + Password: *pass, + DB: 0, // use default DB + }) +} + // Operand replicates the semantics of InitialiseOperandVersion pipeline handler for determing Operand version when no version is explicitly provided func Operand(ref string, manager *version.Manager) version.Operand { if ref == "" { @@ -450,3 +455,10 @@ func Operand(ref string, manager *version.Manager) version.Operand { ExpectNoError(err) return operand } + +func userAndPassword(i *ispnv1.Infinispan, kube *TestKubernetes) (*string, *string) { + user := constants.DefaultDeveloperUser + pass, err := users.UserPassword(user, i.GetSecretName(), i.Namespace, kube.Kubernetes, context.TODO()) + ExpectNoError(err) + return &user, &pass +}