Skip to content

Commit 233f921

Browse files
authored
Fail Helm install and operator runtime on Kubernetes 1.25 (#3474)
* Fail Helm install and operator runtime on Kubernetes 1.25
1 parent 60201cf commit 233f921

File tree

6 files changed

+73
-9
lines changed

6 files changed

+73
-9
lines changed

kubernetes/charts/weblogic-operator/templates/_validate-inputs.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
{{- define "operator.validateInputs" -}}
@@ -7,6 +7,10 @@
77
{{- $ignore := include "utils.pushValidationContext" (list $scope "Release") -}}
88
{{- $ignore := include "utils.verifyResourceName" (list $scope "Namespace" 63) -}}
99
{{- $ignore := include "utils.popValidationContext" $scope -}}
10+
{{- if not (.APIVersions.Has "policy/v1beta1") }}
11+
{{- $errorMsg := "Kubernetes version must be between 1.19 and 1.24." -}}
12+
{{- include "utils.recordValidationError" (list $scope $errorMsg) -}}
13+
{{- end -}}
1014
{{- $ignore := include "utils.verifyString" (list $scope "serviceAccount") -}}
1115
{{- $ignore := include "utils.verifyK8SResource" (list $scope .serviceAccount "ServiceAccount" .Release.Namespace) -}}
1216
{{- $ignore := include "utils.verifyString" (list $scope "image") -}}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2017, 2022, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.helpers;
@@ -78,9 +78,6 @@ public final class HealthCheckHelper {
7878
Operation.patch
7979
};
8080

81-
// default namespace or svc account name
82-
private static final String DEFAULT_NAMESPACE = "default";
83-
8481
static {
8582
clusterAccessChecks.put(Resource.NAMESPACES, glwOperations);
8683
clusterAccessChecks.put(Resource.CRDS, crdOperations);
@@ -218,7 +215,9 @@ public static KubernetesVersion performK8sVersionCheck() {
218215
CallBuilder cb = new CallBuilder();
219216
return createAndValidateKubernetesVersion(
220217
cb.executeSynchronousCallWithRetry(cb::readVersionCode,
221-
TuningParameters.getInstance().getMainTuning().initializationRetryDelaySeconds));
218+
TuningParameters.getInstance().getMainTuning().initializationRetryDelaySeconds));
219+
} catch (IllegalStateException ise) {
220+
throw ise;
222221
} catch (Throwable t) {
223222
LOGGER.warning(MessageKeys.K8S_VERSION_CHECK_FAILURE, t);
224223
return KubernetesVersion.UNREADABLE;
@@ -236,6 +235,11 @@ private static KubernetesVersion createAndValidateKubernetesVersion(VersionInfo
236235
} else {
237236
LOGGER.info(MessageKeys.K8S_VERSION_CHECK, kubernetesVersion.asDisplayString());
238237
}
238+
239+
if (kubernetesVersion.isTooHigh()) {
240+
throw new IllegalStateException(LOGGER.formatMessage(MessageKeys.K8S_VERSION_TOO_HIGH,
241+
KubernetesVersion.TOO_HIGH.asDisplayString(), kubernetesVersion.asDisplayString()));
242+
}
239243
return kubernetesVersion;
240244
}
241245
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
/** Major and minor version of Kubernetes API Server. */
99
public class KubernetesVersion extends SemanticVersion {
1010
private static final String[] MINIMUM_K8S_VERSIONS = {"1.19.15", "1.20.11", "1.21.5", "1.22.5", "1.23.4", "1.24.0"};
11+
static final KubernetesVersion TOO_HIGH = new KubernetesVersion(1, 25);
12+
1113
static final KubernetesVersion UNREADABLE = new KubernetesVersion(0, 0);
1214
private final String version;
1315

@@ -58,6 +60,10 @@ boolean isCompatible() {
5860
return numHigher == MINIMUM_K8S_VERSIONS.length;
5961
}
6062

63+
boolean isTooHigh() {
64+
return compareTo(TOO_HIGH) >= 0;
65+
}
66+
6167
boolean isPublishNotReadyAddressesSupported() {
6268
return getMajor() > 1 || (getMajor() == 1 && getMinor() >= 8);
6369
}

operator/src/main/java/oracle/kubernetes/operator/logging/MessageKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class MessageKeys {
5252
public static final String APIEXCEPTION_FROM_SUBJECT_ACCESS_REVIEW = "WLSKO-0069";
5353
public static final String REPLICA_MORE_THAN_WLS_SERVERS = "WLSKO-0071";
5454
public static final String K8S_VERSION_TOO_LOW = "WLSKO-0073";
55+
public static final String K8S_VERSION_TOO_HIGH = "WLSKO-0228";
5556
public static final String VERIFY_K8S_MIN_VERSION = "WLSKO-0074";
5657
public static final String DOMAIN_UID_UNIQUENESS_FAILED = "WLSKO-0076";
5758
public static final String PV_NOT_FOUND_FOR_DOMAIN_UID = "WLSKO-0077";

operator/src/main/resources/Operator.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ WLSKO-0224=Fluentd configmap created.
153153
WLSKO-0225=Fluentd configmap replaced.
154154
WLSKO-0226=Pod {0} was evicted due to {1}; validating domain
155155
WLSKO-0227=Pod {0} was evicted due to {1} but the operator is configured not to restart it.
156+
WLSKO-0228=Kubernetes maximum version check failed. Kubernetes version must be prior to {0}, but found version {1}
156157

157158
# Domain status messages
158159

operator/src/test/java/oracle/kubernetes/operator/helpers/VersionCheckTest.java

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@
1414
import oracle.kubernetes.utils.TestUtils;
1515
import org.hamcrest.Description;
1616
import org.hamcrest.Matcher;
17+
import org.hamcrest.TypeSafeMatcher;
1718
import org.junit.jupiter.api.AfterEach;
1819
import org.junit.jupiter.api.BeforeEach;
1920
import org.junit.jupiter.params.ParameterizedTest;
2021
import org.junit.jupiter.params.provider.Arguments;
2122
import org.junit.jupiter.params.provider.MethodSource;
2223

24+
import static oracle.kubernetes.operator.helpers.VersionCheckTest.FailsWithMatcher.failsWith;
2325
import static oracle.kubernetes.operator.helpers.VersionCheckTest.TestType.LOG_MSG_TEST;
2426
import static oracle.kubernetes.operator.helpers.VersionCheckTest.TestType.VERSION_TEST;
27+
import static oracle.kubernetes.operator.helpers.VersionCheckTest.TestType.VERSION_TOO_HIGH_TEST;
2528
import static oracle.kubernetes.operator.helpers.VersionCheckTest.VersionMatcher.returnsVersion;
2629
import static oracle.kubernetes.operator.logging.MessageKeys.K8S_VERSION_CHECK;
2730
import static oracle.kubernetes.operator.logging.MessageKeys.K8S_VERSION_CHECK_FAILURE;
2831
import static oracle.kubernetes.operator.logging.MessageKeys.K8S_VERSION_TOO_LOW;
29-
import static oracle.kubernetes.utils.LogMatcher.containsInfo;
3032
import static oracle.kubernetes.utils.LogMatcher.containsWarning;
33+
import static org.hamcrest.Matchers.allOf;
34+
import static org.hamcrest.Matchers.instanceOf;
3135
import static org.hamcrest.junit.MatcherAssert.assertThat;
3236

3337
class VersionCheckTest {
@@ -62,8 +66,8 @@ private static Stream<Arguments> getTestParams() {
6266
Arguments.of(VERSION_TEST, "1", "21", "10", returnsVersion(1, 21), ignoring(K8S_VERSION_CHECK)),
6367
Arguments.of(VERSION_TEST, "1", "22", "5", returnsVersion(1, 22), ignoring(K8S_VERSION_CHECK)),
6468
Arguments.of(VERSION_TEST, "1", "23", "7", returnsVersion(1, 23), ignoring(K8S_VERSION_CHECK)),
65-
Arguments.of(VERSION_TEST, "2", "7", "", returnsVersion(2, 7), ignoring(K8S_VERSION_CHECK)),
66-
Arguments.of(LOG_MSG_TEST, "2", "", "", containsInfo(K8S_VERSION_CHECK), noIgnores())
69+
Arguments.of(VERSION_TOO_HIGH_TEST, "1", "25", "", null, ignoring(K8S_VERSION_CHECK)),
70+
Arguments.of(VERSION_TOO_HIGH_TEST, "2", "7", "", null, ignoring(K8S_VERSION_CHECK))
6771
);
6872
}
6973

@@ -134,6 +138,12 @@ void runTest(List<LogRecord> logRecords, Matcher matcher) {
134138
void runTest(List<LogRecord> logRecords, Matcher matcher) {
135139
assertThat(HealthCheckHelper.performK8sVersionCheck(), matcher);
136140
}
141+
},
142+
VERSION_TOO_HIGH_TEST {
143+
@Override
144+
void runTest(List<LogRecord> logRecords, Matcher matcher) {
145+
assertThat(HealthCheckHelper::performK8sVersionCheck, failsWith(IllegalStateException.class));
146+
}
137147
};
138148

139149
abstract void runTest(List<LogRecord> logRecords, Matcher matcher);
@@ -172,4 +182,42 @@ public void describeTo(Description description) {
172182
describe(description, expectedMajor, expectedMinor);
173183
}
174184
}
185+
186+
@FunctionalInterface
187+
public interface IThrowingRunnable<E extends Throwable> {
188+
void run() throws E;
189+
}
190+
191+
static class FailsWithMatcher<E extends Throwable> extends TypeSafeMatcher<IThrowingRunnable<E>> {
192+
private final Matcher<? super E> matcher;
193+
194+
private FailsWithMatcher(final Matcher<? super E> matcher) {
195+
this.matcher = matcher;
196+
}
197+
198+
public static <E extends Throwable> Matcher<IThrowingRunnable<E>> failsWith(final Class<E> throwableType) {
199+
return new FailsWithMatcher<>(instanceOf(throwableType));
200+
}
201+
202+
public static <E extends Throwable> Matcher<IThrowingRunnable<E>> failsWith(
203+
final Class<E> throwableType, final Matcher<? super E> throwableMatcher) {
204+
return new FailsWithMatcher<>(allOf(instanceOf(throwableType), throwableMatcher));
205+
}
206+
207+
@Override
208+
protected boolean matchesSafely(final IThrowingRunnable<E> runnable) {
209+
try {
210+
runnable.run();
211+
return false;
212+
} catch (final Throwable ex) {
213+
return matcher.matches(ex);
214+
}
215+
}
216+
217+
@Override
218+
public void describeTo(final Description description) {
219+
description.appendText("fails with ").appendDescriptionOf(matcher);
220+
}
221+
222+
}
175223
}

0 commit comments

Comments
 (0)