-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Coherence CLI to the Operator image (#606)
- Loading branch information
1 parent
63917a1
commit ab02646
Showing
9 changed files
with
293 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
Copyright (c) 2023, Oracle and/or its affiliates. | ||
Licensed under the Universal Permissive License v 1.0 as shown at | ||
http://oss.oracle.com/licenses/upl. | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
= The Coherence CLI | ||
== The Coherence CLI | ||
If Coherence Management over REST is enabled, it is possible to use the | ||
https://github.com/oracle/coherence-cli[Coherence CLI] | ||
to access management information. The Operator enables Coherence Management over REST by default, so unless it | ||
has specifically been disabled, the CLI can be used. | ||
See the https://oracle.github.io/coherence-cli/docs/latest/#/docs/about/01_overview[Coherence CLI Documentation] | ||
for more information on how to use the CLI. | ||
The Coherence CLI is automatically added to Coherence Pods by the Operator, so it is available as an executable | ||
that can be run using `kubectl exec`. | ||
At start-up of a Coherence container a default Coherence CLI configuration is created so that the CLI | ||
knows about the local cluster member. | ||
=== Using the CLI in Pods | ||
The Operator installs the CLI at the location `/coherence-operator/utils/cohctl`. | ||
Most official Coherence images are distroless images so they do not have a shell that can be used to create a session and execute commands. Each `cohctl` command will need to be executed as a separate `kubectl exec` command. | ||
Once a Pod is running is it simple to use the CLI. | ||
For example, the yaml below will create a simple three member cluster. | ||
[source] | ||
.minimal.yaml | ||
---- | ||
apiVersion: coherence.oracle.com/v1 | ||
kind: Coherence | ||
metadata: | ||
name: storage | ||
spec: | ||
replicas: 3 | ||
---- | ||
The cluster name is `storage` and there will be three Pods created, `storage-0`, `storage-1` and `storage-2`. | ||
To list the services running in the `storage-0` Pod the following command can be run: | ||
[source,bash] | ||
---- | ||
kubectl exec storage-0 -c coherence -- /coherence-operator/utils/cohctl get services | ||
---- | ||
The `-c coherence` option tells `kubectl` to exec the command in the `coherence` container. | ||
By default this is the only container that will be running in the Pod, so the option could be omitted. | ||
If the option is omitted, `kubectl` will display a warning to say it assumes you mean the `coherence` container. | ||
Everything after the `--` is the command to run in the Pod. In this case we execute: | ||
[source,bash] | ||
---- | ||
/coherence-operator/utils/cohctl get services | ||
---- | ||
which runs the Coherence CLI binary at `/coherence-operator/utils/cohctl` with the command `get services`. | ||
The output displayed by the command will look something like this: | ||
[source,bash] | ||
---- | ||
Using cluster connection 'default' from current context. | ||
SERVICE NAME TYPE MEMBERS STATUS HA STORAGE PARTITIONS | ||
"$GRPC:GrpcProxy" Proxy 3 n/a -1 -1 | ||
"$SYS:Concurrent" DistributedCache 3 NODE-SAFE 3 257 | ||
"$SYS:ConcurrentProxy" Proxy 3 n/a -1 -1 | ||
"$SYS:Config" DistributedCache 3 NODE-SAFE 3 257 | ||
"$SYS:HealthHttpProxy" Proxy 3 n/a -1 -1 | ||
"$SYS:SystemProxy" Proxy 3 n/a -1 -1 | ||
ManagementHttpProxy Proxy 3 n/a -1 -1 | ||
MetricsHttpProxy Proxy 3 n/a -1 -1 | ||
PartitionedCache DistributedCache 3 NODE-SAFE 3 257 | ||
PartitionedTopic PagedTopic 3 NODE-SAFE 3 257 | ||
Proxy Proxy 3 n/a -1 -1 | ||
---- | ||
The exact output will vary depending on the version of Coherence and the configurations being used. | ||
More CLI commands can be run by changing the CLI commands specified after `/coherence-operator/utils/cohctl`. | ||
For example, to list all the members of the cluster: | ||
[source,bash] | ||
---- | ||
kubectl exec storage-0 -c coherence -- /coherence-operator/utils/cohctl get members | ||
---- | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2019, 2023, Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at | ||
# http://oss.oracle.com/licenses/upl. | ||
# | ||
VERSION=$(curl -s https://oracle.github.io/coherence-cli/stable.txt) | ||
|
||
function set_arch() { | ||
if [ "$ARCH" == "x86_64" ] ; then | ||
ARCH="amd64" | ||
elif [ "$ARCH" == "aarch64" -o "$ARCH" == "arm64" ] ; then | ||
ARCH="arm64" | ||
else | ||
echo "Unsupported architecture: $ARCH" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function installed() { | ||
echo "Installed cohctl into ${COHCTL_HOME}" | ||
} | ||
|
||
echo "Installing Coherence CLI ${VERSION} for ${OS}/${ARCH} into ${COHCTL_HOME} ..." | ||
|
||
if [ "$OS" == "Darwin" ]; then | ||
set_arch | ||
TEMP=`mktemp -d` | ||
PKG="Oracle-Coherence-CLI-${VERSION}-darwin-${ARCH}.pkg" | ||
DEST=${TEMP}/${PKG} | ||
echo "Downloading and opening ${DEST}" | ||
URL=https://github.com/oracle/coherence-cli/releases/download/${VERSION}/${PKG} | ||
curl -sLo ${DEST} $URL && open ${DEST} && installed | ||
elif [ "$OS" == "Linux" ]; then | ||
set_arch | ||
TEMP=`mktemp -d` | ||
URL=https://github.com/oracle/coherence-cli/releases/download/${VERSION}/cohctl-${VERSION}-linux-${ARCH} | ||
curl -sLo ${TEMP}/cohctl $URL && chmod u+x ${TEMP}/cohctl | ||
mv ${TEMP}/cohctl ${COHCTL_HOME} && installed | ||
else | ||
echo "For all other platforms, please see: https://github.com/oracle/coherence-cli/releases" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. | ||
* Licensed under the Universal Permissive License v 1.0 as shown at | ||
* http://oss.oracle.com/licenses/upl. | ||
*/ | ||
|
||
package local | ||
|
||
import ( | ||
. "github.com/onsi/gomega" | ||
coh "github.com/oracle/coherence-operator/api/v1" | ||
"github.com/oracle/coherence-operator/test/e2e/helper" | ||
"os/exec" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"testing" | ||
) | ||
|
||
// Test that the Coherence CLI can be executed in a Pod | ||
func TestCoherenceCLI(t *testing.T) { | ||
// Make sure we defer clean-up when we're done!! | ||
testContext.CleanupAfterTest(t) | ||
g := NewWithT(t) | ||
|
||
deployments, _ := helper.AssertDeployments(testContext, t, "deployment-cli.yaml") | ||
|
||
data, ok := deployments["storage"] | ||
g.Expect(ok).To(BeTrue(), "did not find expected 'storage' deployment") | ||
|
||
hasFinalizer := controllerutil.ContainsFinalizer(&data, coh.CoherenceFinalizer) | ||
g.Expect(hasFinalizer).To(BeTrue()) | ||
|
||
_, err := exec.Command("kubectl", "-n", data.Namespace, "exec", "storage-0", | ||
"-c", "coherence", "--", "/coherence-operator/utils/cohctl", "get", "members").CombinedOutput() | ||
g.Expect(err).NotTo(HaveOccurred()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: coherence.oracle.com/v1 | ||
kind: Coherence | ||
metadata: | ||
name: storage | ||
spec: | ||
env: | ||
- name: COH_SKIP_SITE | ||
value: "true" | ||
|
||
|