Skip to content

Commit 8f0d96d

Browse files
committed
Revert "WIP use anonymous HTTP client"
This reverts commit f369307.
1 parent f369307 commit 8f0d96d

File tree

7 files changed

+27
-48
lines changed

7 files changed

+27
-48
lines changed

pkg/infinispan/client/api/infinispan.go

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

8-
"github.com/infinispan/infinispan-operator/pkg/infinispan/version"
98
"github.com/infinispan/infinispan-operator/pkg/mime"
109
)
1110

@@ -19,7 +18,6 @@ type Infinispan interface {
1918
ProtobufMetadataCacheName() string
2019
ScriptCacheName() string
2120
Server() Server
22-
Version() version.Operand
2321
}
2422

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

pkg/infinispan/client/client.go

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

5757
// New Factory to obtain Infinispan implementation
5858
func New(operand version.Operand, client httpClient.HttpClient) api.Infinispan {
59-
return ispnClient(operand, client)
59+
return ispnClient(operand.UpstreamVersion.Major, 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-
upstreamVersion := semver.MustParse("15.0.0")
67-
info, err := v15.New(version.Operand{UpstreamVersion: &upstreamVersion}, client).Container().Info()
66+
info, err := v15.New(client).Container().Info()
6867
if err != nil {
69-
upstreamVersion = semver.MustParse("14.0.0")
70-
info, err = v14.New(version.Operand{UpstreamVersion: &upstreamVersion}, client).Container().Info()
68+
info, err = v14.New(client).Container().Info()
7169
if err != nil {
7270
return nil, wrapError(err)
7371
}
@@ -78,17 +76,17 @@ func NewUnknownVersion(client httpClient.HttpClient) (api.Infinispan, error) {
7876
if err != nil {
7977
return nil, wrapError(fmt.Errorf("unable to parse server version: %w", err))
8078
}
81-
return ispnClient(version.Operand{UpstreamVersion: &_version}, client), nil
79+
return ispnClient(_version.Major, client), nil
8280
}
8381

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

pkg/infinispan/client/v14/infinispan_v14.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ 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"
76
)
87

98
type infinispan struct {
109
api.PathResolver
1110
http.HttpClient
12-
operand version.Operand
1311
}
1412

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

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

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

pkg/infinispan/client/v15/infinispan_v15.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ 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"
87
)
98

109
type infinispan struct {
1110
http.HttpClient
1211
api.Infinispan
1312
}
1413

15-
func New(operand version.Operand, client http.HttpClient) api.Infinispan {
14+
func New(client http.HttpClient) api.Infinispan {
1615
return &infinispan{
1716
HttpClient: client,
18-
Infinispan: v14.NewWithPathResolver(operand, client, NewPathResolver()),
17+
Infinispan: v14.NewWithPathResolver(client, NewPathResolver()),
1918
}
2019
}

pkg/reconcile/pipeline/infinispan/api.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ 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-
8986
// InfinispanClientUnknownVersion returns a client for a specified pod based upon the version returned by the server
9087
InfinispanClientUnknownVersion(podName string) (ispnApi.Infinispan, error)
9188

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ 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-
123116
func (c *contextImpl) InfinispanClientUnknownVersion(podName string) (api.Infinispan, error) {
124117
curlClient := c.curlClient(podName)
125118
return ispnClient.NewUnknownVersion(curlClient)
@@ -149,8 +142,8 @@ func (c *contextImpl) InfinispanPods() (*corev1.PodList, error) {
149142
return c.ispnPods.DeepCopy(), nil
150143
}
151144

152-
func (c *contextImpl) curlConfig(podName string) curl.Config {
153-
return curl.Config{
145+
func (c *contextImpl) curlClient(podName string) *curl.Client {
146+
return curl.New(curl.Config{
154147
Credentials: &curl.Credentials{
155148
Username: c.ispnConfig.AdminIdentities.Username,
156149
Password: c.ispnConfig.AdminIdentities.Password,
@@ -160,11 +153,7 @@ func (c *contextImpl) curlConfig(podName string) curl.Config {
160153
Namespace: c.infinispan.Namespace,
161154
Protocol: "http",
162155
Port: consts.InfinispanAdminPort,
163-
}
164-
}
165-
166-
func (c *contextImpl) curlClient(podName string) *curl.Client {
167-
return curl.New(c.curlConfig(podName), c.kubernetes)
156+
}, c.kubernetes)
168157
}
169158

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

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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"
1213
pipeline "github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan"
1314
"github.com/infinispan/infinispan-operator/pkg/reconcile/pipeline/infinispan/handler/provision"
1415
routev1 "github.com/openshift/api/route/v1"
@@ -130,8 +131,7 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
130131
// Initiate the GracefulShutdown if it's not already in progress
131132
if i.Spec.Replicas == 0 {
132133
logger.Info(".Spec.Replicas==0")
133-
replicas := *statefulSet.Spec.Replicas
134-
if replicas != 0 {
134+
if *statefulSet.Spec.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,6 +153,12 @@ 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+
156162
podMeta := &PodMeta{}
157163
podMetaMap[pod.Name] = podMeta
158164
podMeta.client, err = ctx.InfinispanClientUnknownVersion(pod.Name)
@@ -181,7 +187,7 @@ func GracefulShutdown(i *ispnv1.Infinispan, ctx pipeline.Context) {
181187
return
182188
}
183189

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

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()
202+
health, err := podMeta.client.Container().HealthStatus()
199203
if err != nil {
200204
ctx.Requeue(fmt.Errorf("unable to retrieve cluster health status for pod '%s': %w", pod.Name, err))
201205
return

0 commit comments

Comments
 (0)