Skip to content

Commit 8ff6134

Browse files
committed
Domain status patching switching behavior
1 parent c144315 commit 8ff6134

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ public class Main {
105105
private static String principal;
106106
private static KubernetesVersion version = null;
107107

108+
/* MARKER-2.6.0-ONLY */
109+
// This is needed only for 2.6.0 -- do not forward port to 3.x
110+
// In 3.0.0, we are switching the CRD to enable the domain status endpoint. This means that all updates to the
111+
// domain status must be made against that REST endpoint and that (according to the K8s doc) attempts to
112+
// update the domain status through the normal endpoint will be ignored.
113+
//
114+
// However, for Kubernetes versions less than 1.16, the 2.6.0 CRD needs to remain
115+
// unchanged for interoperability with 2.5.0. Therefore, 2.6.0 will detect if a 3.x operator has changed the
116+
// CRD and modify its behavior. This provides an upgrade path from 2.x to 3.x, which is that all operators
117+
// must be updated to 2.6.0 before a 3.0.0 operator is introduced to the cluster, but if this strategy is used
118+
// then 2.5.0 is compatible with 2.6.0 and 2.6.0 is compatible with 3.0.0.
119+
//
120+
// When running on 1.16 and above, 2.6.0 will also create a CRD with the status endpoint enabled since there is
121+
// no need to be compatible with 2.5.0.
122+
public static AtomicBoolean useDomainStatusEndpoint = new AtomicBoolean(false);
123+
/* END-2.6.0-ONLY */
124+
108125
static {
109126
try {
110127
// suppress System.err since we catch all necessary output with Logger

operator/src/main/java/oracle/kubernetes/operator/helpers/CrdHelper.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import io.kubernetes.client.util.Yaml;
4040
import oracle.kubernetes.json.SchemaGenerator;
4141
import oracle.kubernetes.operator.KubernetesConstants;
42+
import oracle.kubernetes.operator.Main;
4243
import oracle.kubernetes.operator.calls.CallResponse;
4344
import oracle.kubernetes.operator.logging.LoggingFacade;
4445
import oracle.kubernetes.operator.logging.LoggingFactory;
@@ -240,7 +241,11 @@ static V1CustomResourceSubresources createSubresources() {
240241

241242
static V1beta1CustomResourceSubresources createBetaSubresources() {
242243
return new V1beta1CustomResourceSubresources()
243-
.status(new HashMap<String, String>()) // this just needs an empty object to enable status subresource
244+
/* MARKER-2.6.0-ONLY */
245+
// for 2.6.0 we will not enable the status subresource for the beta version of CRD
246+
// the 3.0.0 operator will enable this subresource so 2.6.0 will still check the actual CRD
247+
// .status(new HashMap<String, String>()) // this just needs an empty object to enable status subresource
248+
/* END-2.6.0-ONLY */
244249
.scale(
245250
new V1beta1CustomResourceSubresourceScale()
246251
.specReplicasPath(".spec.replicas")
@@ -251,6 +256,9 @@ static List<V1CustomResourceDefinitionVersion> getCrdVersions() {
251256
Map<String, String> schemas = schemaReader.loadFilesFromClasspath();
252257
List<V1CustomResourceDefinitionVersion> versions = schemas.entrySet().stream()
253258
.sorted(Comparator.comparing(Map.Entry::getKey))
259+
/* MARKER-2.6.0-ONLY */
260+
.filter(entry -> !KubernetesConstants.DOMAIN_VERSION.equals(getVersionFromCrdSchemaFileName(entry.getKey())))
261+
/* END-2.6.0-ONLY */
254262
.map(entry -> new V1CustomResourceDefinitionVersion()
255263
.name(getVersionFromCrdSchemaFileName(entry.getKey()))
256264
.schema(getValidationFromCrdSchemaFile(entry.getValue()))
@@ -274,6 +282,9 @@ static List<V1beta1CustomResourceDefinitionVersion> getBetaCrdVersions() {
274282
Map<String, String> schemas = schemaReader.loadFilesFromClasspath();
275283
List<V1beta1CustomResourceDefinitionVersion> versions = schemas.entrySet().stream()
276284
.sorted(Comparator.comparing(Map.Entry::getKey))
285+
/* MARKER-2.6.0-ONLY */
286+
.filter(entry -> !KubernetesConstants.DOMAIN_VERSION.equals(getVersionFromCrdSchemaFileName(entry.getKey())))
287+
/* END-2.6.0-ONLY */
277288
.map(entry -> new V1beta1CustomResourceDefinitionVersion()
278289
.name(getVersionFromCrdSchemaFileName(entry.getKey()))
279290
.served(true)
@@ -353,7 +364,7 @@ static SchemaGenerator createSchemaGenerator() {
353364

354365
Step verifyCrd(Step next) {
355366
return new CallBuilder().readCustomResourceDefinitionAsync(
356-
model.getMetadata().getName(), createReadResponseStep(next));
367+
model.getMetadata().getName(), createReadResponseStep(next));
357368
}
358369

359370
ResponseStep<V1CustomResourceDefinition> createReadResponseStep(Step next) {
@@ -371,7 +382,7 @@ ResponseStep<V1beta1CustomResourceDefinition> createBetaReadResponseStep(Step ne
371382

372383
Step createCrd(Step next) {
373384
return new CallBuilder().createCustomResourceDefinitionAsync(
374-
model, createCreateResponseStep(next));
385+
model, createCreateResponseStep(next));
375386
}
376387

377388
ResponseStep<V1CustomResourceDefinition> createCreateResponseStep(Step next) {
@@ -436,7 +447,7 @@ Step updateExistingCrd(Step next, V1CustomResourceDefinition existingCrd) {
436447
.served(true));
437448

438449
return new CallBuilder().replaceCustomResourceDefinitionAsync(
439-
existingCrd.getMetadata().getName(), existingCrd, createReplaceResponseStep(next));
450+
existingCrd.getMetadata().getName(), existingCrd, createReplaceResponseStep(next));
440451
}
441452

442453
Step updateExistingBetaCrd(Step next, V1beta1CustomResourceDefinition existingCrd) {
@@ -518,6 +529,9 @@ public NextAction onSuccess(
518529
Packet packet, CallResponse<V1beta1CustomResourceDefinition> callResponse) {
519530
V1beta1CustomResourceDefinition existingCrd = callResponse.getResult();
520531
if (version.isCrdV1Supported()) {
532+
/* MARKER-2.6.0-ONLY */
533+
Main.useDomainStatusEndpoint.set(true);
534+
/* END-2.6.0-ONLY */
521535
if (existingCrd == null) {
522536
return doNext(createCrd(getNext()), packet);
523537
} else {
@@ -529,12 +543,26 @@ public NextAction onSuccess(
529543
} else if (isOutdatedBetaCrd(existingCrd)) {
530544
return doNext(updateBetaCrd(getNext(), existingCrd), packet);
531545
} else if (!existingBetaCrdContainsVersion(existingCrd)) {
546+
/* MARKER-2.6.0-ONLY */
547+
checkForStatusSubresource(existingCrd);
548+
/* END-2.6.0-ONLY */
532549
return doNext(updateExistingBetaCrd(getNext(), existingCrd), packet);
533550
}
551+
/* MARKER-2.6.0-ONLY */
552+
checkForStatusSubresource(existingCrd);
553+
/* END-2.6.0-ONLY */
534554
}
535555
return doNext(packet);
536556
}
537557

558+
/* MARKER-2.6.0-ONLY */
559+
private void checkForStatusSubresource(V1beta1CustomResourceDefinition existingCrd) {
560+
if (existingCrd.getSpec().getSubresources().getStatus() != null) {
561+
Main.useDomainStatusEndpoint.set(true);
562+
}
563+
}
564+
/* END-2.6.0-ONLY */
565+
538566
@Override
539567
protected NextAction onFailureNoRetry(Packet packet, CallResponse<V1beta1CustomResourceDefinition> callResponse) {
540568
return isNotAuthorizedOrForbidden(callResponse)

0 commit comments

Comments
 (0)