Skip to content

Commit f369307

Browse files
committed
WIP use anonymous HTTP client
1 parent fe2fb8f commit f369307

File tree

7 files changed

+48
-27
lines changed

7 files changed

+48
-27
lines changed

pkg/infinispan/client/api/infinispan.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bytes"
66
"fmt"
77

8+
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
89
"github.com/infinispan/infinispan-operator/pkg/mime"
910
)
1011

@@ -18,6 +19,7 @@ type Infinispan interface {
1819
ProtobufMetadataCacheName() string
1920
ScriptCacheName() string
2021
Server() Server
22+
Version() version.Operand
2123
}
2224

2325
// Container interface contains all operations and sub-interfaces related to interactions with the Infinispan cache-container

pkg/infinispan/client/client.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@ import (
5656

5757
// New Factory to obtain Infinispan implementation
5858
func New(operand version.Operand, client httpClient.HttpClient) api.Infinispan {
59-
return ispnClient(operand.UpstreamVersion.Major, client)
59+
return ispnClient(operand, client)
6060
}
6161

6262
func NewUnknownVersion(client httpClient.HttpClient) (api.Infinispan, error) {
6363
wrapError := func(e error) error {
6464
return fmt.Errorf("unable to determine server version: %w", e)
6565
}
66-
info, err := v15.New(client).Container().Info()
66+
upstreamVersion := semver.MustParse("15.0.0")
67+
info, err := v15.New(version.Operand{UpstreamVersion: &upstreamVersion}, client).Container().Info()
6768
if err != nil {
68-
info, err = v14.New(client).Container().Info()
69+
upstreamVersion = semver.MustParse("14.0.0")
70+
info, err = v14.New(version.Operand{UpstreamVersion: &upstreamVersion}, client).Container().Info()
6971
if err != nil {
7072
return nil, wrapError(err)
7173
}
@@ -76,17 +78,17 @@ func NewUnknownVersion(client httpClient.HttpClient) (api.Infinispan, error) {
7678
if err != nil {
7779
return nil, wrapError(fmt.Errorf("unable to parse server version: %w", err))
7880
}
79-
return ispnClient(_version.Major, client), nil
81+
return ispnClient(version.Operand{UpstreamVersion: &_version}, client), nil
8082
}
8183

82-
func ispnClient(majorVersion uint64, client httpClient.HttpClient) api.Infinispan {
83-
switch majorVersion {
84+
func ispnClient(operand version.Operand, client httpClient.HttpClient) api.Infinispan {
85+
switch operand.UpstreamVersion.Major {
8486
// We must still return a client for the dropped Infinispan 13 so that we can interact with the server when upgrading
8587
// to a supported version. The only difference between the 13 and 14 client was the Cache EqualConfiguration implementation
8688
// which is not required for upgrades.
8789
case 13, 14:
88-
return v14.New(client)
90+
return v14.New(operand, client)
8991
default:
90-
return v15.New(client)
92+
return v15.New(operand, client)
9193
}
9294
}

pkg/infinispan/client/v14/infinispan_v14.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ package v14
33
import (
44
"github.com/infinispan/infinispan-operator/pkg/http"
55
"github.com/infinispan/infinispan-operator/pkg/infinispan/client/api"
6+
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
67
)
78

89
type infinispan struct {
910
api.PathResolver
1011
http.HttpClient
12+
operand version.Operand
1113
}
1214

13-
func New(client http.HttpClient) api.Infinispan {
14-
return NewWithPathResolver(client, NewPathResolver())
15+
func New(operand version.Operand, client http.HttpClient) api.Infinispan {
16+
return NewWithPathResolver(operand, client, NewPathResolver())
1517
}
1618

17-
func NewWithPathResolver(client http.HttpClient, pathResolver api.PathResolver) api.Infinispan {
18-
return &infinispan{pathResolver, client}
19+
func NewWithPathResolver(operand version.Operand, client http.HttpClient, pathResolver api.PathResolver) api.Infinispan {
20+
return &infinispan{pathResolver, client, operand}
1921
}
2022

2123
func (i *infinispan) Cache(name string) api.Cache {
@@ -49,3 +51,7 @@ func (i *infinispan) ScriptCacheName() string {
4951
func (i *infinispan) Server() api.Server {
5052
return &server{i.PathResolver, i.HttpClient}
5153
}
54+
55+
func (i *infinispan) Version() version.Operand {
56+
return i.operand
57+
}

pkg/infinispan/client/v15/infinispan_v15.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"github.com/infinispan/infinispan-operator/pkg/http"
55
"github.com/infinispan/infinispan-operator/pkg/infinispan/client/api"
66
v14 "github.com/infinispan/infinispan-operator/pkg/infinispan/client/v14"
7+
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
78
)
89

910
type infinispan struct {
1011
http.HttpClient
1112
api.Infinispan
1213
}
1314

14-
func New(client http.HttpClient) api.Infinispan {
15+
func New(operand version.Operand, client http.HttpClient) api.Infinispan {
1516
return &infinispan{
1617
HttpClient: client,
17-
Infinispan: v14.NewWithPathResolver(client, NewPathResolver()),
18+
Infinispan: v14.NewWithPathResolver(operand, client, NewPathResolver()),
1819
}
1920
}

pkg/reconcile/pipeline/infinispan/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ type Context interface {
8383
// InfinispanClientForPod returns a client for the specific pod
8484
InfinispanClientForPod(podName string) ispnApi.Infinispan
8585

86+
// InfinispanClientForPodAnonymous returns a client for the specified pod with no credentials configured
87+
InfinispanClientForPodAnonymous(podName string, operand version.Operand) ispnApi.Infinispan
88+
8689
// InfinispanClientUnknownVersion returns a client for a specified pod based upon the version returned by the server
8790
InfinispanClientUnknownVersion(podName string) (ispnApi.Infinispan, error)
8891

pkg/reconcile/pipeline/infinispan/context/context.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ func (c *contextImpl) InfinispanClientForPod(podName string) api.Infinispan {
113113
return ispnClient.New(c.Operand(), curlClient)
114114
}
115115

116+
func (c *contextImpl) InfinispanClientForPodAnonymous(podName string, operand version.Operand) api.Infinispan {
117+
config := c.curlConfig(podName)
118+
config.Credentials = nil
119+
curlClient := curl.New(config, c.kubernetes)
120+
return ispnClient.New(operand, curlClient)
121+
}
122+
116123
func (c *contextImpl) InfinispanClientUnknownVersion(podName string) (api.Infinispan, error) {
117124
curlClient := c.curlClient(podName)
118125
return ispnClient.NewUnknownVersion(curlClient)
@@ -142,8 +149,8 @@ func (c *contextImpl) InfinispanPods() (*corev1.PodList, error) {
142149
return c.ispnPods.DeepCopy(), nil
143150
}
144151

145-
func (c *contextImpl) curlClient(podName string) *curl.Client {
146-
return curl.New(curl.Config{
152+
func (c *contextImpl) curlConfig(podName string) curl.Config {
153+
return curl.Config{
147154
Credentials: &curl.Credentials{
148155
Username: c.ispnConfig.AdminIdentities.Username,
149156
Password: c.ispnConfig.AdminIdentities.Password,
@@ -153,7 +160,11 @@ func (c *contextImpl) curlClient(podName string) *curl.Client {
153160
Namespace: c.infinispan.Namespace,
154161
Protocol: "http",
155162
Port: consts.InfinispanAdminPort,
156-
}, c.kubernetes)
163+
}
164+
}
165+
166+
func (c *contextImpl) curlClient(podName string) *curl.Client {
167+
return curl.New(c.curlConfig(podName), c.kubernetes)
157168
}
158169

159170
func (c *contextImpl) ConfigFiles() *pipeline.ConfigFiles {

pkg/reconcile/pipeline/infinispan/handler/manage/upgrades.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
consts "github.com/infinispan/infinispan-operator/controllers/constants"
1010
ispnApi "github.com/infinispan/infinispan-operator/pkg/infinispan/client/api"
1111
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
12-
kube "github.com/infinispan/infinispan-operator/pkg/kubernetes"
1312
pipeline "github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan"
1413
"github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan/handler/provision"
1514
routev1 "github.com/openshift/api/route/v1"
@@ -131,7 +130,8 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
131130
// Initiate the GracefulShutdown if it's not already in progress
132131
if i.Spec.Replicas == 0 {
133132
logger.Info(".Spec.Replicas==0")
134-
if *statefulSet.Spec.Replicas != 0 {
133+
replicas := *statefulSet.Spec.Replicas
134+
if replicas != 0 {
135135
logger.Info("StatefulSet.Spec.Replicas!=0")
136136
// Only send a GracefulShutdown request to the server if it hasn't succeeded already
137137
if !i.IsConditionTrue(ispnv1.ConditionStopping) {
@@ -153,12 +153,6 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
153153
var podMetaMap = make(map[string]*PodMeta, len(podList.Items))
154154
var shutdownAlreadyInitiated bool
155155
for _, pod := range podList.Items {
156-
// We should only proceed with a GracefulShutdown if all pods are marked as Ready
157-
if !kube.IsPodReady(pod) {
158-
ctx.Requeue(fmt.Errorf("postponing GracefulShutdown as pod '%s' is not ready", pod.Name))
159-
return
160-
}
161-
162156
podMeta := &PodMeta{}
163157
podMetaMap[pod.Name] = podMeta
164158
podMeta.client, err = ctx.InfinispanClientUnknownVersion(pod.Name)
@@ -187,7 +181,7 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
187181
return
188182
}
189183

190-
if info.ClusterSize != i.Spec.Replicas {
184+
if info.ClusterSize != replicas {
191185
err = fmt.Errorf(
192186
"unable to proceed with GracefulShutdown as pod '%s' has '%d' cluster members, expected '%d'. Members: '%s'",
193187
pod.Name,
@@ -199,7 +193,9 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
199193
return
200194
}
201195

202-
health, err := podMeta.client.Container().HealthStatus()
196+
// We must always use an anonymous client to retrieve the health/status as it does not support DIGEST auth
197+
anonClient := ctx.InfinispanClientForPodAnonymous(pod.Name, podMeta.client.Version())
198+
health, err := anonClient.Container().HealthStatus()
203199
if err != nil {
204200
ctx.Requeue(fmt.Errorf("unable to retrieve cluster health status for pod '%s': %w", pod.Name, err))
205201
return

0 commit comments

Comments
 (0)