Skip to content

Commit 946e26b

Browse files
committed
Implement domain status switching behavior
1 parent 8ff6134 commit 946e26b

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

kubernetes/crd/domain-v1beta1-crd.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ spec:
1919
scale:
2020
specReplicasPath: .spec.replicas
2121
statusReplicasPath: .status.replicas
22-
status: {}
2322
validation:
2423
openAPIV3Schema:
2524
type: object

operator/src/main/java/oracle/kubernetes/operator/DomainStatusUpdater.java

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,44 @@ private Step createDomainStatusReplaceStep(DomainStatusUpdaterContext context, D
186186
if (LOGGER.isFinerEnabled()) {
187187
LOGGER.finer("status change: " + createPatchString(context, newStatus));
188188
}
189+
/* MARKER-2.6.0-ONLY */
190+
boolean useDomainStatusEndpoint = Main.useDomainStatusEndpoint.get();
191+
/* END-2.6.0-ONLY */
189192
Domain oldDomain = context.getDomain();
190193
Domain newDomain = new Domain()
191194
.withKind(KubernetesConstants.DOMAIN)
192195
.withApiVersion(oldDomain.getApiVersion())
193196
.withMetadata(oldDomain.getMetadata())
194-
.withSpec(null)
197+
/* MARKER-2.6.0-ONLY */
198+
// WAS .withSpec(null)
199+
.withSpec(useDomainStatusEndpoint ? null : oldDomain.getSpec())
200+
/* END-2.6.0-ONLY */
195201
.withStatus(newStatus);
196202

203+
/* MARKER-2.6.0-ONLY */
204+
/* WAS
197205
return new CallBuilder().replaceDomainStatusAsync(
198206
context.getDomainName(),
199207
context.getNamespace(),
200208
newDomain,
201209
createResponseStep(context, getNext()));
210+
*/
211+
if (useDomainStatusEndpoint) {
212+
return new CallBuilder()
213+
.replaceDomainStatusAsync(
214+
context.getDomainName(),
215+
context.getNamespace(),
216+
newDomain,
217+
createResponseStep(context, newStatus, useDomainStatusEndpoint, getNext()));
218+
} else {
219+
return new CallBuilder()
220+
.replaceDomainAsync(
221+
context.getDomainName(),
222+
context.getNamespace(),
223+
newDomain,
224+
createResponseStep(context, newStatus, useDomainStatusEndpoint, getNext()));
225+
}
226+
/* END-2.6.0-ONLY */
202227
}
203228

204229
private String createPatchString(DomainStatusUpdaterContext context, DomainStatus newStatus) {
@@ -207,24 +232,57 @@ private String createPatchString(DomainStatusUpdaterContext context, DomainStatu
207232
return builder.build().toString();
208233
}
209234

210-
private ResponseStep<Domain> createResponseStep(DomainStatusUpdaterContext context, Step next) {
211-
return new StatusReplaceResponseStep(this, context, next);
235+
private ResponseStep<Domain> createResponseStep(DomainStatusUpdaterContext context,
236+
/* MARKER-2.6.0-ONLY */
237+
DomainStatus newStatus, boolean useDomainStatusEndpoint,
238+
/* END-2.6.0-ONLY */
239+
Step next) {
240+
return new StatusReplaceResponseStep(this,
241+
/* MARKER-2.6.0-ONLY */
242+
newStatus, useDomainStatusEndpoint,
243+
/* END-2.6.0-ONLY */
244+
context, next);
212245
}
213246
}
214247

215248
static class StatusReplaceResponseStep extends DefaultResponseStep<Domain> {
216249
private final DomainStatusUpdaterStep updaterStep;
217250
private final DomainStatusUpdaterContext context;
251+
/* MARKER-2.6.0-ONLY */
252+
private final DomainStatus newStatus;
253+
private final boolean useDomainStatusEndpoint;
254+
/* END-2.6.0-ONLY */
218255

219256
public StatusReplaceResponseStep(DomainStatusUpdaterStep updaterStep,
257+
/* MARKER-2.6.0-ONLY */
258+
DomainStatus newStatus,
259+
boolean useDomainStatusEndpoint,
260+
/* END-2.6.0-ONLY */
220261
DomainStatusUpdaterContext context, Step nextStep) {
221262
super(nextStep);
222263
this.updaterStep = updaterStep;
223264
this.context = context;
265+
/* MARKER-2.6.0-ONLY */
266+
this.newStatus = newStatus;
267+
this.useDomainStatusEndpoint = useDomainStatusEndpoint;
268+
/* END-2.6.0-ONLY */
224269
}
225270

226271
@Override
227272
public NextAction onSuccess(Packet packet, CallResponse<Domain> callResponse) {
273+
/* MARKER-2.6.0-ONLY */
274+
// If the 3.0.0 operator updated the CRD to use status endpoint while this operator is running
275+
// then these domain replace calls will succeed, but the proposed domain status will have been
276+
// ignored. Check if the status on the returned domain is expected
277+
if (!useDomainStatusEndpoint && !newStatus.equals(callResponse.getResult().getStatus())) {
278+
// TEST
279+
System.out.println("**** **** ****: Domain status update ignored; switching to status endpoint");
280+
281+
// FIXME: would be better to recheck CRD
282+
Main.useDomainStatusEndpoint.set(true);
283+
return doNext(createRetry(context, getNext()), packet);
284+
}
285+
/* END-2.6.0-ONLY */
228286
packet.getSpi(DomainPresenceInfo.class).setDomain(callResponse.getResult());
229287
return doNext(packet);
230288
}
@@ -239,7 +297,7 @@ public NextAction onFailure(Packet packet, CallResponse<Domain> callResponse) {
239297
}
240298

241299
public Step createRetry(DomainStatusUpdaterContext context, Step next) {
242-
return Step.chain(createDomainRefreshStep(context), updaterStep);
300+
return Step.chain(createDomainRefreshStep(context), updaterStep, next);
243301
}
244302

245303
private Step createDomainRefreshStep(DomainStatusUpdaterContext context) {

0 commit comments

Comments
 (0)