Skip to content
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

Fix work cache in cross-dc setup #442

Merged
merged 2 commits into from
Jul 24, 2023
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: 43 additions & 10 deletions provision/infinispan/create_ispn_clusters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ spec:
locations:
- name: ${remote_site}
url: ${api_url}
namespace: ${remote_namespace}
secretName: ${XSITE_TOKEN_SECRET}
EOF
}
Expand Down Expand Up @@ -181,7 +182,7 @@ spec:
EOF
}

function deploy_cache_cr() {
function deploy_distributed_cache_cr() {
local kubecfg="${1}"
local namespace="${2}"
local cache_name="${3}"
Expand Down Expand Up @@ -214,6 +215,38 @@ spec:
EOF
}

function deploy_replicated_cache_cr() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this effectively the same as deploy_distributed_cache_cr except that we specify replicatedCache? I think it would be simpler to just make the cache type a parameter of the original deploy_cache_cr method so that we don't have to maintain duplicated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanemerson there is also the number of owners. I would say we can leave this as is now, as we plan to migrate to Helm anyway. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's fine, it was just a nitpick 👍

local kubecfg="${1}"
local namespace="${2}"
local cache_name="${3}"
local remote_site="${4}"
local xsite_mode="${5}"
local cr_name=$(echo "${cache_name}" | awk '{print tolower($0)}')

KUBECONFIG="${kubecfg}" oc apply -f - << EOF
apiVersion: infinispan.org/v2alpha1
kind: Cache
metadata:
name: ${cr_name}
namespace: ${namespace}
spec:
clusterName: infinispan
name: ${cache_name}
template: |-
replicatedCache:
mode: "SYNC"
statistics: "true"
stateTransfer:
chunkSize: 16
backups:
${remote_site}:
backup:
strategy: ${xsite_mode}
stateTransfer:
chunkSize: 16
EOF
}

function deploy_cache_cr_without_cross_site() {
local kubecfg="${1}"
local namespace="${2}"
Expand Down Expand Up @@ -243,14 +276,14 @@ function deploy_all_caches() {
local kubecfg="${1}"
local namespace="${2}"
local remote_site="${3}"
deploy_cache_cr "${kubecfg}" "${namespace}" "sessions" "${remote_site}" "${XSITE_MODE}"
deploy_cache_cr "${kubecfg}" "${namespace}" "actionTokens" "${remote_site}" "${XSITE_MODE}"
deploy_cache_cr "${kubecfg}" "${namespace}" "authenticationSessions" "${remote_site}" "${XSITE_MODE}"
deploy_cache_cr "${kubecfg}" "${namespace}" "offlineSessions" "${remote_site}" "${XSITE_MODE}"
deploy_cache_cr "${kubecfg}" "${namespace}" "clientSessions" "${remote_site}" "${XSITE_MODE}"
deploy_cache_cr "${kubecfg}" "${namespace}" "offlineClientSessions" "${remote_site}" "${XSITE_MODE}"
deploy_cache_cr "${kubecfg}" "${namespace}" "loginFailures" "${remote_site}" "${XSITE_MODE}"
deploy_cache_cr "${kubecfg}" "${namespace}" "work" "${remote_site}" "${XSITE_MODE}"
deploy_distributed_cache_cr "${kubecfg}" "${namespace}" "sessions" "${remote_site}" "${XSITE_MODE}"
deploy_distributed_cache_cr "${kubecfg}" "${namespace}" "actionTokens" "${remote_site}" "${XSITE_MODE}"
deploy_distributed_cache_cr "${kubecfg}" "${namespace}" "authenticationSessions" "${remote_site}" "${XSITE_MODE}"
deploy_distributed_cache_cr "${kubecfg}" "${namespace}" "offlineSessions" "${remote_site}" "${XSITE_MODE}"
deploy_distributed_cache_cr "${kubecfg}" "${namespace}" "clientSessions" "${remote_site}" "${XSITE_MODE}"
deploy_distributed_cache_cr "${kubecfg}" "${namespace}" "offlineClientSessions" "${remote_site}" "${XSITE_MODE}"
deploy_distributed_cache_cr "${kubecfg}" "${namespace}" "loginFailures" "${remote_site}" "${XSITE_MODE}"
deploy_replicated_cache_cr "${kubecfg}" "${namespace}" "work" "${remote_site}" "${XSITE_MODE}"
}

function get_api_url() {
Expand Down Expand Up @@ -318,7 +351,7 @@ function create_cross_site_multiple_clusters() {
deploy_all_caches "${KUBECONFIG_1}" "${NS_1}" "${site2}"

# Create caches on site B
deploy_all_caches "${KUBECONFIG_1}" "${NS_2}" "${site1}"
deploy_all_caches "${KUBECONFIG_2}" "${NS_2}" "${site1}"
}

function create_cluster_without_cross_site() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<!-- the statistics="true" attribute is not part of the original KC config and was added by Keycloak Benchmark -->
<cache-container name="keycloak" statistics="true">
<transport lock-timeout="60000"/>
<transport lock-timeout="60000" site="ISPN"/>
<metrics names-as-tags="true" />
<local-cache name="realms" simple-cache="true" statistics="true">
<encoding>
Expand Down Expand Up @@ -214,6 +214,30 @@
</local-cache>
<replicated-cache name="work" statistics="true">
<expiration lifespan="-1"/>
<persistence passivation="false">
<remote-store xmlns="urn:infinispan:config:store:remote:14.0"
cache="work"
raw-values="true"
shared="true"
segmented="false">
<remote-server host="${env.KC_REMOTE_STORE_HOST}"
port="${env.KC_REMOTE_STORE_PORT}"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
<security>
<authentication server-name="infinispan">
<digest username="${env.KC_REMOTE_STORE_USERNAME}"
password="${env.KC_REMOTE_STORE_PASSWORD}"
realm="default"/>
</authentication>
<encryption protocol="TLSv1.3" sni-hostname="${env.KC_REMOTE_STORE_HOST}">
<truststore filename="/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
type="pem"/>
</encryption>
</security>
</remote-store>
</persistence>

</replicated-cache>
<local-cache name="keys" simple-cache="true" statistics="true">
<encoding>
Expand Down