Skip to content

Disable REST endpoint by default #3958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 16, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ operations on a cluster. These policies monitor one or more types of WebLogic Se
in a policy is met, the policy is triggered, and the corresponding scaling action is executed. The WebLogic Kubernetes Operator project provides a shell script, [`scalingAction.sh`](https://github.com/oracle/weblogic-kubernetes-operator/blob/{{< latestMinorVersion >}}/operator/scripts/scaling/scalingAction.sh),
for use as a Script Action, which illustrates how to issue a request to the operator’s REST endpoint.

{{% notice note %}}
Beginning with operator version 4.0.5, the operator's REST endpoint is disabled by default. Install the operator with the Helm install option `--set "enableRest=true"` to enable the REST endpoint.
{{% /notice %}}

##### Configure automatic scaling of WebLogic clusters in Kubernetes with WLDF
The following steps are provided as a guideline on how to configure a WLDF Policy and Script Action component for issuing scaling requests to the operator's REST endpoint:

Expand Down
4 changes: 4 additions & 0 deletions documentation/4.0/content/managing-operators/the-rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ or for getting certain aspects of a domain's status (for example, instead of cal
You also can use the REST API as an alternative approach for initiating scaling operations
(instead of using the Kubernetes API or command line to alter a domain resource's `replicas` values).

{{% notice note %}}
Beginning with operator version 4.0.5, the operator's REST endpoint is disabled by default. Install the operator with the Helm install option `--set "enableRest=true"` to enable the REST endpoint.
{{% /notice %}}

### Configure the operator's external REST HTTPS interface

The operator can expose an external REST HTTPS interface which can be accessed from outside the Kubernetes cluster. As with the operator's internal REST interface, the external REST interface requires an SSL/TLS certificate and private key that the operator will use as the identity of the external REST interface.
Expand Down
10 changes: 9 additions & 1 deletion documentation/4.0/content/managing-operators/using-helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,16 @@ The REST interface configuration options are advanced settings for configuring t

For usage information, see the operator [REST Services]({{<relref "/managing-operators/the-rest-api.md">}}).

##### `enableRest`
Determines whether the operator's REST endpoint is enabled.

Beginning with operator version 4.0.5, the operator's REST endpoint is disabled by default.

Defaults to `false`.

##### `externalRestEnabled`
Determines whether the operator's REST interface will be exposed outside the Kubernetes cluster using a node port.
Determines whether the operator's REST interface will be exposed outside the Kubernetes cluster using a node port. This
value is ignored if `enableRest` is not `true`.

See also `externalRestHttpsPort` for customizing the port number.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, Oracle and/or its affiliates.
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -33,7 +33,7 @@
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
import static oracle.weblogic.kubernetes.actions.TestActions.imageTag;
import static oracle.weblogic.kubernetes.actions.TestActions.patchClusterCustomResource;
import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithRestApi;
import static oracle.weblogic.kubernetes.actions.TestActions.scaleCluster;
import static oracle.weblogic.kubernetes.actions.impl.Domain.patchDomainCustomResource;
import static oracle.weblogic.kubernetes.assertions.TestAssertions.verifyRollingRestartOccurred;
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainAndVerify;
Expand All @@ -43,8 +43,6 @@
import static oracle.weblogic.kubernetes.utils.DomainUtils.verifyDomainStatusConditionTypeDoesNotExist;
import static oracle.weblogic.kubernetes.utils.ImageUtils.createBaseRepoSecret;
import static oracle.weblogic.kubernetes.utils.ImageUtils.imageRepoLoginAndPushImageToRegistry;
import static oracle.weblogic.kubernetes.utils.OKDUtils.createRouteForOKD;
import static oracle.weblogic.kubernetes.utils.OKDUtils.setTlsTerminationForRoute;
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodDoesNotExist;
import static oracle.weblogic.kubernetes.utils.PodUtils.getPodCreationTime;
Expand Down Expand Up @@ -107,13 +105,6 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
installAndVerifyOperator(opNamespace, opServiceAccount, true, 0, domainNamespace1);
externalRestHttpsPort = getServiceNodePort(opNamespace, "external-weblogic-operator-svc");

// This test uses the operator restAPI to scale the domain. To do this in OKD cluster,
// we need to expose the external service as route and set tls termination to passthrough
logger.info("Create a route for the operator external service - only for OKD");
createRouteForOKD("external-weblogic-operator-svc", opNamespace);
// Patch the route just created to set tls termination to passthrough
setTlsTerminationForRoute("external-weblogic-operator-svc", opNamespace);

// create pull secrets for WebLogic image when running in non Kind Kubernetes cluster
// this secret is used only for non-kind cluster
createBaseRepoSecret(domainNamespace1);
Expand Down Expand Up @@ -512,7 +503,7 @@ void testCompleteAvailableConditionWithScaleUpDownCluster() {
// scale down the cluster
int newReplicaCount = 1;
assertDoesNotThrow(() ->
scaleClusterWithRestApi(domainUid, cluster1Name, 1, externalRestHttpsPort, opNamespace, opServiceAccount));
scaleCluster(clusterResName, domainNamespace1, 1));

// verify the admin server service exists
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace1);
Expand Down Expand Up @@ -544,7 +535,7 @@ void testCompleteAvailableConditionWithScaleUpDownCluster() {
// scale up the cluster
newReplicaCount = 2;
assertDoesNotThrow(() ->
scaleClusterWithRestApi(domainUid, cluster1Name, 2, externalRestHttpsPort, opNamespace, opServiceAccount));
scaleCluster(clusterResName, domainNamespace1, 2));

// verify the admin server service exists
checkPodReadyAndServiceExists(adminServerPodName, domainUid, domainNamespace1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
import static oracle.weblogic.kubernetes.actions.TestActions.getServicePort;
import static oracle.weblogic.kubernetes.actions.TestActions.now;
import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithRestApi;
import static oracle.weblogic.kubernetes.actions.TestActions.scaleCluster;
import static oracle.weblogic.kubernetes.actions.TestActions.shutdownDomain;
import static oracle.weblogic.kubernetes.actions.impl.Cluster.listClusterCustomResources;
import static oracle.weblogic.kubernetes.actions.impl.Domain.patchDomainCustomResource;
Expand All @@ -70,7 +70,6 @@
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterResource;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterResourceAndAddReferenceToDomain;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.removeReplicasSettingAndVerify;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.scaleCluster;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
Expand Down Expand Up @@ -104,8 +103,6 @@
import static oracle.weblogic.kubernetes.utils.K8sEvents.checkDomainFailedEventWithReason;
import static oracle.weblogic.kubernetes.utils.K8sEvents.getDomainEventCount;
import static oracle.weblogic.kubernetes.utils.K8sEvents.getOpGeneratedEventCount;
import static oracle.weblogic.kubernetes.utils.OKDUtils.createRouteForOKD;
import static oracle.weblogic.kubernetes.utils.OKDUtils.setTlsTerminationForRoute;
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
import static oracle.weblogic.kubernetes.utils.PatchDomainUtils.patchDomainResource;
import static oracle.weblogic.kubernetes.utils.PersistentVolumeUtils.createPV;
Expand Down Expand Up @@ -162,6 +159,7 @@ class ItKubernetesDomainEvents {
static String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase;
static final int managedServerPort = 8001;
static int replicaCount = 2;
String clusterRes2Name = cluster2Name;
String clusterRes1Name = cluster1Name;

static final String pvName1 = getUniqueName(domainUid + "-pv-");
Expand Down Expand Up @@ -219,13 +217,6 @@ public static void initAll(@Namespaces(6) List<String> namespaces) {
domainNamespace4, domainNamespace5);
externalRestHttpsPort = getServiceNodePort(opNamespace, "external-weblogic-operator-svc");

// This test uses the operator restAPI to scale the domain. To do this in OKD cluster,
// we need to expose the external service as route and set tls termination to passthrough
logger.info("Create a route for the operator external service - only for OKD");
String opExternalSvc = createRouteForOKD("external-weblogic-operator-svc", opNamespace);
// Patch the route just created to set tls termination to passthrough
setTlsTerminationForRoute("external-weblogic-operator-svc", opNamespace);

createDomain(domainNamespace3, domainUid, pvName3, pvcName3);
}

Expand Down Expand Up @@ -394,8 +385,7 @@ void testK8SEventsMultiClusterEvents() {
createNewCluster();
OffsetDateTime timestamp2 = now();
logger.info("Scale the newly-added cluster");
scaleClusterWithRestApi(domainUid, cluster2Name, 1,
externalRestHttpsPort, opNamespace, opServiceAccount);
scaleCluster(clusterRes2Name, domainNamespace3, 1);
logger.info("verify the Domain_Available event is generated");
checkEvent(opNamespace, domainNamespace3, domainUid,
DOMAIN_AVAILABLE, "Normal", timestamp);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -52,7 +52,7 @@
import static oracle.weblogic.kubernetes.actions.TestActions.deleteNamespace;
import static oracle.weblogic.kubernetes.actions.TestActions.deleteSecret;
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithRestApi;
import static oracle.weblogic.kubernetes.actions.TestActions.scaleCluster;
import static oracle.weblogic.kubernetes.actions.TestActions.uninstallOperator;
import static oracle.weblogic.kubernetes.utils.CleanupUtil.deleteNamespacedArtifacts;
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterResourceAndAddReferenceToDomain;
Expand Down Expand Up @@ -249,13 +249,7 @@ void testNameSpaceManageByRegularExpression() {
//verify domain is started
createSecrets(manageByLabelNS);
assertTrue(createDomainResourceAndVerifyDomainIsRunning(manageByLabelNS,manageByLabelDomainUid));
checkOperatorCanScaleDomain(opNamespaces[1],manageByLabelDomainUid);

//check operator can't manage anymore manageByExp1NS
assertTrue(isOperatorFailedToScaleDomain(opNamespaces[1], manageByExpDomain1Uid,
manageByExp1NS), "Operator can still manage domain "
+ manageByExp1NS + " in the namespace " + manageByExp1NS);

checkOperatorCanScaleDomain(manageByLabelNS, manageByLabelDomainUid);
}

/**
Expand Down Expand Up @@ -299,7 +293,7 @@ void testNameSpaceManagedByLabelSelector() {
"Failed to create domain CRD or "
+ "verify that domain " + domainsUid[1]
+ " is running in namespace " + domainNamespaces[1]);
checkOperatorCanScaleDomain(opNamespaces[0], domainsUid[1]);
checkOperatorCanScaleDomain(domainNamespaces[1], domainsUid[1]);

//check that with specific Selector default namespace is not under operator management
checkDomainNotStartedInDefaultNS();
Expand All @@ -325,11 +319,7 @@ void testNameSpaceManagedByLabelSelector() {
//verify domain is started in namespace with name starting with weblogic* and operator can scale it.
createSecrets(manageByExpDomainNS);
assertTrue(createDomainResourceAndVerifyDomainIsRunning(manageByExpDomainNS,manageByExpDomainUid));
checkOperatorCanScaleDomain(opNamespaces[0],manageByExpDomainUid);
//verify operator can't manage anymore domain running in the namespace with label
assertTrue(isOperatorFailedToScaleDomain(opNamespaces[0], domainsUid[0], domainNamespaces[0]),
"Operator can still manage domain "
+ domainsUid[0] + " in the namespace " + domainNamespaces[0]);
checkOperatorCanScaleDomain(manageByExpDomainNS, manageByExpDomainUid);

checkUpgradeFailedToAddNSManagedByAnotherOperator();
}
Expand Down Expand Up @@ -374,7 +364,7 @@ void testNameSpaceWithOperatorRbacFalse() {

assertTrue(upgradeAndVerifyOperator(opNamespaces[3], opParams));
assertTrue(createDomainResourceAndVerifyDomainIsRunning(manageByLabelDomainNS, manageByLabelDomainUid));
checkOperatorCanScaleDomain(opNamespaces[3], manageByLabelDomainUid);
checkOperatorCanScaleDomain(manageByLabelDomainNS, manageByLabelDomainUid);
}

private void checkUpgradeFailedToAddNSManagedByAnotherOperator() {
Expand Down Expand Up @@ -411,7 +401,7 @@ private HelmParams installAndVerifyOperatorCanManageDomainBySelector(Map<String,
createSecrets(domainNS);
assertTrue(createDomainResourceAndVerifyDomainIsRunning(domainNS, domainUid),
"can't start or verify domain in namespace " + domainNS);
checkOperatorCanScaleDomain(opNamespace, domainUid);
checkOperatorCanScaleDomain(domainNS, domainUid);
}
);
if (domainNamespacesValue != null) {
Expand All @@ -429,15 +419,13 @@ private HelmParams installAndVerifyOperatorCanManageDomainBySelector(Map<String,
return opHelmParam;
}

private boolean isOperatorFailedToScaleDomain(String opNamespace, String domainUid, String domainNamespace) {
private boolean isOperatorFailedToScaleDomain(String domainUid, String domainNamespace) {
try {
//check operator can't manage domainNamespace by trying to scale domain
int externalRestHttpsPort = getServiceNodePort(opNamespace, "external-weblogic-operator-svc");
String managedServerPodNamePrefix = domainUid + "-managed-server";
String opServiceAccount = OPERATOR_RELEASE_NAME + "-sa";
scaleAndVerifyCluster("cluster-1", domainUid, domainNamespace,
managedServerPodNamePrefix, 2, 1,
true, externalRestHttpsPort, opNamespace, opServiceAccount,
false, 0, null, null,
false, "", "scaleDown", 1, "", "", null, null);
return false;
} catch (TimeoutException ex) {
Expand All @@ -454,10 +442,8 @@ private static void setLabelToNamespace(String domainNS, Map<String, String> lab
assertDoesNotThrow(() -> Kubernetes.replaceNamespace(namespaceObject1));
}

private void checkOperatorCanScaleDomain(String opNamespace, String domainUid) {
int externalRestHttpsPort = getServiceNodePort(opNamespace, "external-weblogic-operator-svc");
assertTrue(scaleClusterWithRestApi(domainUid, clusterName, 3,
externalRestHttpsPort, opNamespace, OPERATOR_RELEASE_NAME + "-sa"),
private void checkOperatorCanScaleDomain(String domainNamespace, String domainUid) {
assertTrue(scaleCluster(domainUid + "-" + clusterName, domainNamespace, 3),
"Domain " + domainUid + " scaling operation failed");
}

Expand Down
Loading