Skip to content

Fix using the Coherence console via kubectl exec #696

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 12 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ TEST_COHERENCE_IMAGE ?= $(COHERENCE_IMAGE)
TEST_COHERENCE_VERSION ?= $(COHERENCE_VERSION)
TEST_COHERENCE_GID ?= com.oracle.coherence.ce

# The minimum certified OpenShift version the Operator runs on
OPENSHIFT_MIN_VERSION := v4.15
OPENSHIFT_COMPONENT_PID := 67b738ef88736e8a179ac976

# The current working directory
CURRDIR := $(shell pwd)

Expand Down Expand Up @@ -340,13 +344,15 @@ SHELL = /usr/bin/env bash -o pipefail
# Capture the Git commit to add to the build information that is then embedded in the Go binary
# ----------------------------------------------------------------------------------------------------------------------
GITCOMMIT ?= $(shell git rev-list -1 HEAD)
GITBRANCH ?= $(shell git branch --show-current)
GITREPO := https://github.com/oracle/coherence-operator.git
SOURCE_DATE_EPOCH := $(shell git show -s --format=format:%ct HEAD)
DATE_FMT := "%Y-%m-%dT%H:%M:%SZ"
BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "+${DATE_FMT}" 2>/dev/null || date -u "+${DATE_FMT}")
#BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "+${DATE_FMT}" 2>/dev/null || date -u "+${DATE_FMT}")
BUILD_DATE := $(shell date -u "+${DATE_FMT}")
BUILD_USER := $(shell whoami)

LDFLAGS = -X main.Version=$(VERSION) -X main.Commit=$(GITCOMMIT) -X main.Date=$(BUILD_DATE) -X main.Author=$(BUILD_USER)
LDFLAGS = -X main.Version=$(VERSION) -X main.Commit=$(GITCOMMIT) -X main.Branch=$(GITBRANCH) -X main.Date=$(BUILD_DATE) -X main.Author=$(BUILD_USER)
GOS = $(shell find . -type f -name "*.go" ! -name "*_test.go")
HELM_FILES = $(shell find helm-charts/coherence-operator -type f)
API_GO_FILES = $(shell find . -type f -name "*.go" ! -name "*_test.go" ! -name "zz*.go")
Expand Down Expand Up @@ -460,7 +466,9 @@ $(BUILD_PROPS):
clean: ## Cleans the build
-rm -rf $(BUILD_OUTPUT) || true
-rm -rf $(BUILD_BIN) || true
-rm -rf artifacts || true
-rm -rf bundle || true
-rm bundle.Dockerfile || true
rm config/crd/bases/*.yaml || true
rm -rf config/crd-small || true
rm pkg/data/zz_generated_*.go || true
Expand Down Expand Up @@ -895,6 +903,13 @@ bundle: $(BUILD_PROPS) ensure-sdk $(TOOLS_BIN)/kustomize $(BUILD_TARGETS)/manife
$(OPERATOR_SDK) generate kustomize manifests
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
@echo "" >> ./bundle/metadata/annotations.yaml
@echo " # OpenShift annotations" >> ./bundle/metadata/annotations.yaml
@echo " com.redhat.openshift.versions: $(OPENSHIFT_MIN_VERSION)" >> ./bundle/metadata/annotations.yaml
@echo "" >> bundle.Dockerfile
@echo "# OpenShift labels" >> bundle.Dockerfile
@echo "LABEL com.redhat.openshift.versions=$(OPENSHIFT_MIN_VERSION)" >> bundle.Dockerfile
@echo "cert_project_id: $(OPENSHIFT_COMPONENT_PID)" > bundle/ci.yaml
$(OPERATOR_SDK) bundle validate ./bundle
$(OPERATOR_SDK) bundle validate ./bundle --select-optional suite=operatorframework --optional-values=k8s-version=1.26
$(OPERATOR_SDK) bundle validate ./bundle --select-optional name=operatorhubv2 --optional-values=k8s-version=1.26
Expand Down Expand Up @@ -952,7 +967,7 @@ catalog-build: opm ## Build a catalog image.
# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(DOCKER_CMD) push $(CATALOG_IMAGE)
$(DOCKER_CMD) push $(PUSH_ARGS) $(CATALOG_IMAGE)

.PHONY: scorecard
scorecard: $(BUILD_PROPS) ensure-sdk bundle ## Run the Operator SDK scorecard tests.
Expand Down Expand Up @@ -1037,9 +1052,6 @@ jk: $(BUILD_PREFLIGHT)/preflight.yaml

# Generate the preflight job yaml
$(BUILD_PREFLIGHT)/preflight.yaml: hack/preflight.yaml
#ifeq ($(PREFLIGHT_REGISTRY_CRED),)
# $(error $(n)The PREFLIGHT_REGISTRY_CRED variable must be specified to run preflight$(n)Typically using the command$(n)$(n) export PREFLIGHT_REGISTRY_CRED=$$(echo -n bogus:$$(oc whoami -t) | base64)$(n)$(n))
#endif
cp hack/preflight.yaml $(BUILD_PREFLIGHT)/preflight.yaml
$(SED) -e 's^image-placeholder^$(OPERATOR_IMAGE)^g' $(BUILD_PREFLIGHT)/preflight.yaml
$(SED) -e 's/registry-credential-placeholder/$(PREFLIGHT_REGISTRY_CRED)/g' $(BUILD_PREFLIGHT)/preflight.yaml
Expand Down Expand Up @@ -2299,6 +2311,7 @@ PUSH_ARGS ?=
push-operator-image: $(BUILD_TARGETS)/build-operator
$(DOCKER_CMD) push $(PUSH_ARGS) $(OPERATOR_IMAGE_AMD)
$(DOCKER_CMD) push $(PUSH_ARGS) $(OPERATOR_IMAGE_ARM)
$(DOCKER_CMD) rmi $(OPERATOR_IMAGE) || true
$(DOCKER_CMD) manifest create $(PUSH_ARGS) $(OPERATOR_IMAGE) \
--amend $(OPERATOR_IMAGE_AMD) \
--amend $(OPERATOR_IMAGE_ARM)
Expand Down Expand Up @@ -2326,27 +2339,27 @@ push-test-images:
.PHONY: push-ttl-test-images
push-ttl-test-images:
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE) $(TTL_APPLICATION_IMAGE)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_CLIENT) $(TTL_APPLICATION_IMAGE_CLIENT)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_CLIENT)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_CLIENT)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_HELIDON) $(TTL_APPLICATION_IMAGE_HELIDON)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_HELIDON)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_HELIDON)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_HELIDON_3) $(TTL_APPLICATION_IMAGE_HELIDON_3)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_HELIDON_3)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_HELIDON_3)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_HELIDON_2) $(TTL_APPLICATION_IMAGE_HELIDON_2)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_HELIDON_2)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_HELIDON_2)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_SPRING) $(TTL_APPLICATION_IMAGE_SPRING)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_SPRING)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_SPRING)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_SPRING_FAT) $(TTL_APPLICATION_IMAGE_SPRING_FAT)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_SPRING_FAT)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_SPRING_FAT)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_SPRING_CNBP) $(TTL_APPLICATION_IMAGE_SPRING_CNBP)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_SPRING_CNBP)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_SPRING_CNBP)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_SPRING_2) $(TTL_APPLICATION_IMAGE_SPRING_2)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_SPRING_2)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_SPRING_2)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_SPRING_FAT_2) $(TTL_APPLICATION_IMAGE_SPRING_FAT_2)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_SPRING_FAT_2)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_SPRING_FAT_2)
$(DOCKER_CMD) tag $(TEST_APPLICATION_IMAGE_SPRING_CNBP_2) $(TTL_APPLICATION_IMAGE_SPRING_CNBP_2)
$(DOCKER_CMD) push $(TTL_APPLICATION_IMAGE_SPRING_CNBP_2)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_APPLICATION_IMAGE_SPRING_CNBP_2)

# ----------------------------------------------------------------------------------------------------------------------
# Build the Operator Test images
Expand All @@ -2365,15 +2378,15 @@ build-compatibility-image: $(BUILD_TARGETS)/java
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: push-compatibility-image
push-compatibility-image: build-compatibility-image
$(DOCKER_CMD) push $(TEST_COMPATIBILITY_IMAGE)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TEST_COMPATIBILITY_IMAGE)

# ----------------------------------------------------------------------------------------------------------------------
# Push the Operator JIB Test Docker images to ttl.sh
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: push-ttl-compatibility-image
push-ttl-compatibility-image:
$(DOCKER_CMD) tag $(TEST_COMPATIBILITY_IMAGE) $(TTL_COMPATIBILITY_IMAGE)
$(DOCKER_CMD) push $(TTL_COMPATIBILITY_IMAGE)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_COMPATIBILITY_IMAGE)

# ----------------------------------------------------------------------------------------------------------------------
# Push all of the Docker images
Expand All @@ -2387,7 +2400,7 @@ push-all-images: push-test-images push-operator-image
.PHONY: push-ttl-operator-images
push-ttl-operator-images:
$(DOCKER_CMD) tag $(OPERATOR_IMAGE) $(TTL_OPERATOR_IMAGE)
$(DOCKER_CMD) push $(TTL_OPERATOR_IMAGE)
$(DOCKER_CMD) push $(PUSH_ARGS) $(TTL_OPERATOR_IMAGE)

# ----------------------------------------------------------------------------------------------------------------------
# Push all the images to ttl.sh
Expand Down
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ spec:
version: "3.4.3"
app.kubernetes.io/component: manager
app.kubernetes.io/part-of: coherence-operator
annotations:
alpha.image.policy.openshift.io/resolve-names: '*'
spec:
serviceAccountName: service-account
terminationGracePeriodSeconds: 10
Expand Down

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions hack/setup-podman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ export OPERATOR_IMAGE_REGISTRY=${REGISTRY}/oracle
export PREFLIGHT_REGISTRY_CRED=$(echo -n bogus:$(oc whoami -t) | base64)

podman login -u bogus -p $(oc whoami -t) --tls-verify=false ${REGISTRY}
podman login -u bogus -p $(oc whoami -t) --tls-verify=false ${OPERATOR_IMAGE_REGISTRY}

#oc new-project oracle || true
#oc -n oracle create is coherence-operator || true
# Allow anyone to pull oracle images
#oc adm policy add-role-to-group system:image-puller system:authenticated --namespace=oracle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
Expand Down Expand Up @@ -157,7 +157,7 @@ public void preStart(Context context) {
context.getConfigurableCacheFactory().getInterceptorRegistry().registerEventInterceptor(this);
}
catch (Throwable t) {
LOGGER.error("Failed to initialise the Coherence Operator", t);
LOGGER.error("CoherenceOperator: Failed to initialise the Coherence Operator", t);
}
}

Expand Down Expand Up @@ -281,59 +281,126 @@ void initCohCtl() {
String provider = Config.getProperty("coherence.management.http.provider");
String defaultProtocol = provider == null || provider.isEmpty() ? "http" : "https";
String protocol = Config.getProperty("coherence.operator.cli.protocol", defaultProtocol);
String home = System.getProperty("user.home");
File fileHome = new File(home);
String connectionType = "http";

if (!fileHome.exists() || !fileHome.isDirectory()) {
LOGGER.info("CoherenceOperator: user home \"" + home
+ "\" does not exist, creating default cohctl config at /coherence-operator/utils");
home = "/coherence-operator/utils";
fileHome = new File(home);

// If COHCTL_HOME is set use that for the config location
String cohCtlHome = System.getenv("COHCTL_HOME");
if (cohCtlHome == null || !cohCtlHome.isEmpty()) {
// Try corresponding system property
cohCtlHome = Config.getProperty("cohctl.home");
}

if (!fileHome.exists() || !fileHome.isDirectory()) {
LOGGER.error("CoherenceOperator: Cannot create cohctl config, directory " + home + " does not exist");
// If we have a COHCTL_HOME env var or property try to create the config there
if (cohCtlHome != null && !cohCtlHome.isEmpty()
&& tryCreateConfig(new File(cohCtlHome), connectionType, protocol, port, clusterName)) {
return;
}

File cohctlHome = new File(home + File.separator + ".cohctl");
File configFile = new File(cohctlHome, "cohctl.yaml");
// Either COHCTL_HOME was not set or we failed to create a config there, try ${user.home}
String userHome = System.getProperty("user.home");
File fileUserHome = new File(userHome);
File fileCohCtlHome = null;

if (fileUserHome.exists() && fileUserHome.isDirectory()) {
// use ${user.home}/.cohctl
fileCohCtlHome = new File(fileUserHome, ".cohctl");
if (!fileCohCtlHome.exists()) {
try {
if (!fileCohCtlHome.mkdirs()) {
fileCohCtlHome = null;
}
}
catch (Exception e) {
LOGGER.error("CoherenceOperator: Failed to create cohctl home directory at " + fileCohCtlHome, e);
fileCohCtlHome = null;
}
}
}

if (!configFile.exists()) {
LOGGER.info("CoherenceOperator: creating default cohctl config at " + configFile.getAbsolutePath());
if (!cohctlHome.exists()) {
cohctlHome.mkdirs();
boolean success = false;
if (fileCohCtlHome != null) {
if (fileCohCtlHome.exists() && fileCohCtlHome.isDirectory()) {
success = tryCreateConfig(fileCohCtlHome, connectionType, protocol, port, clusterName);
}
else {
if (!fileCohCtlHome.exists()) {
LOGGER.error("CoherenceOperator: Cannot create cohctl config, directory "
+ fileCohCtlHome + " does not exist");
}
else {
LOGGER.error("CoherenceOperator: Cannot create cohctl config, location "
+ fileCohCtlHome + " is not a directory");
}
}
try (PrintWriter out = new PrintWriter(configFile)) {
out.println("clusters:");
out.println(" - name: default");
out.println(" discoverytype: manual");
out.println(" connectiontype: " + connectionType);
out.println(" connectionurl: " + protocol + "://127.0.0.1:" + port + "/management/coherence/cluster");
out.println(" nameservicediscovery: \"\"");
out.println(" clusterversion: \"" + CacheFactory.VERSION + "\"");
out.println(" clustername: \"" + clusterName + "\"");
out.println(" clustertype: Standalone");
out.println(" manuallycreated: false");
out.println(" baseclasspath: \"\"");
out.println(" additionalclasspath: \"\"");
out.println(" arguments: \"\"");
out.println(" managementport: 0");
out.println(" persistencemode: \"\"");
out.println(" loggingdestination: \"\"");
out.println(" managementavailable: false");
out.println("color: \"on\"");
out.println("currentcontext: default");
out.println("debug: false");
out.println("defaultbytesformat: m");
out.println("ignoreinvalidcerts: false");
out.println("requesttimeout: 30");
}

if (!success) {
if (fileCohCtlHome != null) {
LOGGER.info("CoherenceOperator: unable to create cohctl config in \"" + fileCohCtlHome
+ "\" creating cohctl config at /coherence-operator/utils");
}
tryCreateConfig(new File("/coherence-operator/utils"), connectionType, protocol, port, clusterName);
}
}
catch (Exception e) {
LOGGER.error("Coherence Operator: Failed to create default cohctl config. " + e.getMessage());
}
}

/**
* Try to create the Coherence CLI configuration.
*
* @param home the location of the CLI home directory
* @param connectionType the type of the connection http or https
* @param protocol the protocol for the connection http or https
* @param port the management over REST port
* @param clusterName the cluster name
*
* @return {@code true} of the configuration was created
*/
protected boolean tryCreateConfig(File home, String connectionType, String protocol, String port, String clusterName) {
File configFile = new File(home, "cohctl.yaml");

if (configFile.exists()) {
return true;
}

try {
LOGGER.info("CoherenceOperator: creating default cohctl config at " + configFile.getAbsolutePath());
if (!home.exists()) {
home.mkdirs();
}
try (PrintWriter out = new PrintWriter(configFile)) {
out.println("clusters:");
out.println(" - name: default");
out.println(" discoverytype: manual");
out.println(" connectiontype: " + connectionType);
out.println(" connectionurl: " + protocol + "://127.0.0.1:" + port + "/management/coherence/cluster");
out.println(" nameservicediscovery: \"\"");
out.println(" clusterversion: \"" + CacheFactory.VERSION + "\"");
out.println(" clustername: \"" + clusterName + "\"");
out.println(" clustertype: Standalone");
out.println(" manuallycreated: false");
out.println(" baseclasspath: \"\"");
out.println(" additionalclasspath: \"\"");
out.println(" arguments: \"\"");
out.println(" managementport: 0");
out.println(" persistencemode: \"\"");
out.println(" loggingdestination: \"\"");
out.println(" managementavailable: false");
out.println("color: \"on\"");
out.println("currentcontext: default");
out.println("debug: false");
out.println("defaultbytesformat: m");
out.println("ignoreinvalidcerts: false");
out.println("requesttimeout: 30");
}
return true;
}
catch (Exception e) {
LOGGER.error("Coherence Operator: Failed to create default cohctl config. " + e.getMessage());
return false;
}
}
}
2 changes: 1 addition & 1 deletion java/operator-compatibility/image-build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh -e

docker build -t jk/coherence:1.0.0 -f operator-compatibility/target/classes/Dockerfile ./operator-compatibility
docker build --load -t jk/coherence:1.0.0 -f operator-compatibility/target/classes/Dockerfile ./operator-compatibility
1 change: 1 addition & 0 deletions java/operator-compatibility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<executable>docker</executable>
<arguments>
<argument>build</argument>
<argument>--load</argument>
<argument>-t</argument>
<argument>${coherence.compatibility.image.name}</argument>
<argument>-f</argument>
Expand Down
4 changes: 4 additions & 0 deletions java/operator-test-helidon-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<artifactId>coherence</artifactId>
<version>${coherence.version}</version>
</dependency>
<dependency>
<groupId>${coherence.groupId}</groupId>
<artifactId>coherence-json</artifactId>
</dependency>
<dependency>
<groupId>${coherence.groupId}</groupId>
<artifactId>coherence-cdi-server</artifactId>
Expand Down
Loading
Loading