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

procedures: Migration to devworkspace engine #2159

Closed
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f7fd96b
Add doc about migration CHE from stable to stable all namespace CHE u…
AndrienkoAleksandr Nov 9, 2021
2f8e763
Fix up.
AndrienkoAleksandr Nov 9, 2021
b252cd8
Fix migrate script to set up minimal user profile info.
AndrienkoAleksandr Nov 9, 2021
79f3fe8
Update modules/administration-guide/partials/proc_migration_olm_stabl…
AndrienkoAleksandr Nov 22, 2021
e0402d2
Update modules/administration-guide/partials/proc_migration_olm_stabl…
AndrienkoAleksandr Nov 22, 2021
4739686
Use dev workspace reference.
AndrienkoAleksandr Nov 22, 2021
4848a2e
Set single host and set -e for migrate script.
AndrienkoAleksandr Nov 24, 2021
1675388
Make doc and script compatible with CRW.
AndrienkoAleksandr Nov 26, 2021
c75d2a5
Doc refactoring
tolusha Nov 26, 2021
13fdc85
Fixes
tolusha Nov 29, 2021
99f6d2b
Fix
tolusha Nov 29, 2021
f95698e
Fixes
tolusha Nov 30, 2021
a4a823a
Fixes
tolusha Dec 2, 2021
5fabedf
Merge branch 'master' into CHE-20614
tolusha Dec 2, 2021
23f538d
Fix
tolusha Dec 2, 2021
70a240a
Merge branch 'master' into CHE-20614
tolusha Dec 3, 2021
60faaae
Merge branch 'master' into CHE-20614
themr0c Dec 9, 2021
816781b
Merge branch 'master' into CHE-20614
themr0c Dec 9, 2021
07ad4f9
Merge branch 'master' into CHE-20614
themr0c Dec 10, 2021
9dea068
Set user's email
tolusha Dec 13, 2021
34d60bd
Merge branch 'master' into CHE-20614
tolusha Dec 14, 2021
6221b9b
Drop connection, fill in user profile
tolusha Dec 16, 2021
c030d4f
Merge branch 'master' into CHE-20614
themr0c Dec 16, 2021
448a42f
Merge branch 'master' into CHE-20614
themr0c Dec 22, 2021
83cda22
Fixes
tolusha Dec 28, 2021
82eb83e
Merge branch 'master' into CHE-20614
tolusha Dec 28, 2021
84a5b1d
Merge branch 'master' into CHE-20614
tolusha Jan 17, 2022
c4f58f1
Merge branch 'master' into CHE-20614
nickboldt Jan 19, 2022
10e8655
Merge branch 'master' into CHE-20614
themr0c Feb 9, 2022
bd3c49a
Merge branch 'master' into CHE-20614
l0rd Mar 29, 2022
1082018
Update modules/administration-guide/partials/proc_migration-to-devwor…
l0rd Mar 29, 2022
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
4 changes: 4 additions & 0 deletions antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ asciidoc:
theia-endpoint-image: eclipse/che-theia-endpoint-runtime:next
url-devfile-registry-repo: https://github.com/eclipse/che-devfile-registry
url-plug-in-registry-repo: https://github.com/eclipse/che-plugin-registry
prod-channel: stable
prod-tech-preview-channel: tech-preview-stable-all-namespaces
prod-catalog-source: community-operators
prod-tech-preview-olm-package: eclipse-che
2 changes: 1 addition & 1 deletion modules/administration-guide/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
** xref:external-database-setup.adoc[]

* xref:migration-from-postgresql-9-to-postgresql-13.adoc[]

* xref:migration-to-devworkspace-engine.adoc[]
* xref:readiness-init-containers.adoc[]
** xref:enabling-and-disabling-readiness-init-containers-for-the-operator-installer.adoc[]
*** xref:enabling-readiness-init-containers-for-the-operator-installer.adoc[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[id="migration-to-devworkspace-engine"]

:navtitle: Migration to DevWorkspace engine
:keywords: administration-guide, migration, devworkspace
:page-aliases: .:migration-to-devworskpace-engine

include::partial$proc_migration-to-devworkspace-engine.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@

[id="migration-to-devworkspace-engine_{context}"]
= Migration to {devworkspace} engine.

This procedure describes how to migration to {devworkspace} engine using https://docs.openshift.com/container-platform/latest/operators/understanding/olm/olm-understanding-olm.html[OLM] to support the Devfile 2.0.0 file format and mentions how to do so on existing instances.
tolusha marked this conversation as resolved.
Show resolved Hide resolved
l0rd marked this conversation as resolved.
Show resolved Hide resolved

.Prerequisites

* The `{orch-cli}` tool is available.
* An instance of {prod-short} deployed using xref:installation-guide:installing-che-on-openshift-4-using-operatorhub.adoc[Operator Hub] from `{prod-channel}` channel on OpenShift cluster version greater or equal to 4.8
* OpenShift OAuth is enabled. See xref:configuring-openshift-oauth.adoc[].
* Bundled PostgreSQL

.Procedure

. All workspaces must be stopped and changes pushed back to Git repositories.
Copy link
Contributor

@dmytro-ndp dmytro-ndp Dec 10, 2021

Choose a reason for hiding this comment

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

Is admin of Eclipse Che obligated to push back to Git repositories and then all stop workspaces?
Shouldn't workspace be stopped automatically?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not aware of such possibility. This is a general recommendation about working workspaces.

Copy link
Member

@ibuziuk ibuziuk Dec 10, 2021

Choose a reason for hiding this comment

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

@tolusha @skabashnyuk folks, what is the SOP for stopping all running che-server workspaces? atm the implementation for automatic stopping works only after the engine switch from che-server to devWorkpace - eclipse-che/che#20631
According to the procedure from this PR, the workspaces are expected to be stopped before the engine switch, so wondering how admin is expected to proceed in this case?


. Backup {prod-short} data. See xref:managing-backups-using-chectl.adoc[].

include::partial$snip_scaling-down-che.adoc[]

. Create the script to get all {prod-short} users:
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than displaying a script that the user should edit, could we have a script that can receive parameters and that the user can download without modifications?

Copy link
Contributor

Choose a reason for hiding this comment

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

User should not edit any scrits but copy/paster into console to run.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then the step should be "Download the script from following URL" (URL preferably including the release version) rather than "Select, copy and paste a script we display in the content of the script in the docs".

Copy link
Contributor

Choose a reason for hiding this comment

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

This script depends on doc templates like {prod-namespace} and {prod-checluster}.
I can't put this script anywhere but doc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have a script where {orch-cli}, {prod-namespace} and {prod-checluster} are arguments? Now we would be embedding untestable code inside the docs, it feels weird.

Copy link
Contributor

Choose a reason for hiding this comment

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

These parameters are something that users should not care about.

+
[source,shell,subs="+attributes"]
----
cat >get-all-{prod-id}-users.sh<<EOF
#!/bin/bash
set -e

ALL_USERS={prod-id}-users.txt
IDENTITY_PROVIDER_URL=\$({orch-cli} get checluster {prod-checluster} -n {prod-namespace} -o jsonpath="{.status.keycloakURL}" )
IDENTITY_PROVIDER_SECRET=\$({orch-cli} get checluster/{prod-checluster} -n {prod-namespace} -o jsonpath="{.spec.auth.identityProviderSecret}")
IDENTITY_PROVIDER_PASSWORD=\$(if [ -z "\$IDENTITY_PROVIDER_SECRET" ] || [ \$IDENTITY_PROVIDER_SECRET = "null" ]; then {orch-cli} get checluster/{prod-checluster} -n {prod-namespace} -o jsonpath="{.spec.auth.identityProviderPassword}"; else {orch-cli} get secret \$IDENTITY_PROVIDER_SECRET -n {prod-namespace} -o jsonpath="{.data.password}" | base64 -d; fi)
IDENTITY_PROVIDER_USERNAME=\$(if [ -z "\$IDENTITY_PROVIDER_SECRET" ] || [ \$IDENTITY_PROVIDER_SECRET = "null" ]; then {orch-cli} get checluster/{prod-checluster} -n {prod-namespace} -o jsonpath="{.spec.auth.IdentityProviderAdminUserName}"; else {orch-cli} get secret \$IDENTITY_PROVIDER_SECRET -n {prod-namespace} -o jsonpath="{.data.user}" | base64 -d; fi)
IDENTITY_PROVIDER_REALM=\$({orch-cli} get checluster {prod-checluster} -n {prod-namespace} -o jsonpath="{.spec.auth.identityProviderRealm}")
Copy link
Member

Choose a reason for hiding this comment

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

An observation is that the scripts would work only if Eclipse Che / CRW is installed in the recomended namespace e.g. eclipse-che for upstream. However, there is possibility for installing operator in different namespaces e.g. dogfooding on che-dev cluster


refreshToken() {
IDENTITY_PROVIDER_TOKEN=\$(curl -ks \
-d "client_id=admin-cli" \
-d "username=\${IDENTITY_PROVIDER_USERNAME}" \
-d "password=\${IDENTITY_PROVIDER_PASSWORD}" \
-d "grant_type=password" \
"\${IDENTITY_PROVIDER_URL}/realms/master/protocol/openid-connect/token" | jq -r ".access_token")
}

run() {
rm -f \${ALL_USERS}
refreshToken
USER_IDS=(\$(curl -ks -H "Authorization: bearer \${IDENTITY_PROVIDER_TOKEN}" "\${IDENTITY_PROVIDER_URL}/\${IDENTITY_PROVIDER_USERNAME}/realms/\${IDENTITY_PROVIDER_REALM}/users" | jq ".[] | .id" | tr "\r\n" " "))

for USER_ID in "\${USER_IDS[@]}"; do
refreshToken

USER_ID=\$(echo "\${USER_ID}" | tr -d "\"")
FEDERATED_IDENTITY=\$(curl -ks -H "Authorization: bearer \${IDENTITY_PROVIDER_TOKEN}" "\${IDENTITY_PROVIDER_URL}/\${IDENTITY_PROVIDER_USERNAME}/realms/\${IDENTITY_PROVIDER_REALM}/users/\${USER_ID}/federated-identity")
IDENTITY_PROVIDER=\$(echo "\${FEDERATED_IDENTITY}" | jq -r ".[] | select(.identityProvider == \"openshift-v4\")")
if [ -n "\${IDENTITY_PROVIDER}" ]; then
OPENSHIFT_USER_ID=\$(echo "\${IDENTITY_PROVIDER}" | jq ".userId" | tr -d "\"")
echo "[INFO] Find {prod-short} user: \${USER_ID} and corresponding OpenShift user: \${OPENSHIFT_USER_ID}"
echo "\${USER_ID} \${OPENSHIFT_USER_ID}" >> \${ALL_USERS}
fi
done
}

run
echo "[INFO] Done."
EOF

bash get-all-{prod-id}-users.sh
----

include::partial$snip_scaling-down-keycloak.adoc[]

include::partial$snip_finding-che-database-name.adoc[]

include::partial$snip_finding-postgresql-pod.adoc[]

include::partial$snip_dumping-che-database.adoc[]

include::partial$snip_droping-che-database.adoc[]

include::partial$snip_creating-che-database.adoc[]

. Migrate {prod-short} users:
+
[subs="+quotes,+attributes"]
----
DUMP="che.sql"
ALL_USERS={prod-id}-users.txt
Copy link
Member

Choose a reason for hiding this comment

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

@AndrienkoAleksandr I tried to verify the procedure, but there are no instructions for generating eclipse-che-users.txt
Running the script from step 4 just prints smth.like:

[INFO] Find Che user: d5cce9c5-9586-415a-bc5e-ff4b03b187ee and corresponding OpenShift user: 0caf37d3-0ae4-40ff-8b1a-23f7b6049b0d
[INFO] Done.

Copy link
Member

Choose a reason for hiding this comment

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

while IFS= read -r line
do
IDS=($line)
USER_ID=${IDS[0]}
OPENSHIFT_USER_ID=${IDS[1]}

sed -i -e "s|${USER_ID}|${OPENSHIFT_USER_ID}|g" "${DUMP}"

echo "[INFO] Migrated User ID from \"${USER_ID}\" to \"${OPENSHIFT_USER_ID}\""
done < "${ALL_USERS}"
----

include::partial$snip_restoring-che-database.adoc[]

. Add empty users profiles:
+
[subs="+quotes,+attributes"]
----
ALL_USERS={prod-id}-users.txt
while IFS= read -r line
do
IDS=($line)
OPENSHIFT_USER_ID=${IDS[1]}

{orch-cli} exec $POSTGRES_POD -n {prod-namespace} -- bash -c "psql ${CHE_POSTGRES_DB} -tAc \"insert into profile(userid) values ('${OPENSHIFT_USER_ID}');\""

echo "[INFO] Added profile for \"${OPENSHIFT_USER_ID}\""
done < "${ALL_USERS}"
----

. Find Cluster Service Version name:
tolusha marked this conversation as resolved.
Show resolved Hide resolved
+
[subs="+quotes,+attributes"]
----
CSV=$({orch-cli} get subscription {prod-id} -n {prod-namespace} -o jsonpath="{.status.currentCSV}")
----

. Delete Cluster Service Version:
+
[subs="+quotes,+attributes"]
----
{orch-cli} delete csv ${CSV} -n {prod-namespace}
----

. Delete Subscription:
+
[subs="+quotes,+attributes"]
----
{orch-cli} delete subscription {prod-id} -n {prod-namespace}
----

. Enable {devworkspace} engine:
+
[subs="+quotes,+attributes"]
----
{orch-cli} patch checluster/{prod-checluster} -n {prod-namespace} --type=json -p \
'[{"op": "replace", "path": "/spec/devWorkspace/enable", "value": true}]'
----

. Enable single-host exposure strategy:
+
[subs="+quotes,+attributes"]
----
{orch-cli} patch checluster/{prod-checluster} -n {prod-namespace} --type=json -p \
'[{"op": "replace", "path": "/spec/server/serverExposureStrategy", "value": "single-host"}]'
----

. Delete {identity-provider} route:
+
[subs="+quotes,+attributes"]
----
{orch-cli} delete route keycloak -n {prod-namespace}
----

. Delete {identity-provider} service:
+
[subs="+quotes,+attributes"]
----
{orch-cli} delete service keycloak -n {prod-namespace}
----

. Delete {identity-provider} deployment:
+
[subs="+quotes,+attributes"]
----
{orch-cli} delete deployment keycloak -n {prod-namespace}
----

. Create a new subscription to `{prod-tech-preview-channel}` channel:
+
[subs="+quotes,+attributes"]
----
{orch-cli} apply -f - <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: {prod-id}
namespace: openshift-operators
spec:
channel: {prod-tech-preview-channel}
installPlanApproval: Automatic
name: {prod-tech-preview-olm-package}
source: {prod-catalog-source}
sourceNamespace: openshift-marketplace
EOF
----

. Wait until Operator is ready:
+
:k8s-component: {prod-operator}
:k8s-namespace: openshift-operators
include::partial$snip_waiting-for-component.adoc[]

. Wait until {prod-short} is ready:
+
:k8s-component: {prod-deployment}
:k8s-namespace: {prod-namespace}
include::partial$snip_waiting-for-component.adoc[]

include::partial$snip_verification-che-working.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
. Create {prod-short} database:
tolusha marked this conversation as resolved.
Show resolved Hide resolved
+
[subs="+quotes,+attributes"]
----
{orch-cli} exec -it $POSTGRES_POD -n {prod-namespace} -- bash -c "psql postgres -tAc \"CREATE DATABASE $CHE_POSTGRES_DB\""
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
. Drop {prod-short} database:
tolusha marked this conversation as resolved.
Show resolved Hide resolved
+
[subs="+quotes,+attributes"]
----
{orch-cli} exec -it $POSTGRES_POD -n {prod-namespace} -- bash -c "dropdb $CHE_POSTGRES_DB"
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
. Dump {prod-short} database:
+
[subs="+quotes,+attributes"]
----
{orch-cli} exec -it $POSTGRES_POD -n {prod-namespace} -- bash -c "pg_dump $CHE_POSTGRES_DB > /tmp/che.sql"
----

. Copy {prod-short} database to a local file system:
+
[subs="+quotes,+attributes"]
----
{orch-cli} cp {prod-namespace}/$POSTGRES_POD:/tmp/che.sql che.sql
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
. Find {prod-short} database name:
+
[subs="+quotes,+attributes"]
----
CHE_POSTGRES_DB=$({orch-cli} get cm/che -n {prod-namespace} -o json | jq -r '.data.CHE_JDBC_URL' | awk -F '/' '{print $NF}')
if [ -z "$CHE_POSTGRES_DB" ] || [ $CHE_POSTGRES_DB = "null" ]; then CHE_POSTGRES_DB="dbche"; fi
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POSTGRES_SECRET=$({orch-cli} get checluster/{prod-checluster} -n {prod-namespace} -o json | jq -r '.spec.database.chePostgresSecret')
CHE_USER_NAME=$(if [ -z "$POSTGRES_SECRET" ] || [ $POSTGRES_SECRET = "null" ]; then {orch-cli} get checluster/{prod-checluster} -n {prod-namespace} -o json | jq -r '.spec.database.chePostgresUser'; else {orch-cli} get secret $POSTGRES_SECRET -n {prod-namespace} -o json | jq -r '.data.user' | base64 -d; fi)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
. Find PostgreSQL pod:
+
[subs="+quotes,+attributes"]
----
POSTGRES_POD=$({orch-cli} get pods -n {prod-namespace} | grep postgres | awk '{print $1}')
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
. Copy {prod-short} database from a local file system:
+
[subs="+quotes,+attributes"]
----
{orch-cli} cp che.sql {prod-namespace}/$POSTGRES_POD:/tmp/che.sql
----

. Restore {prod-short} database:
+
[subs="+quotes,+attributes"]
----
{orch-cli} exec -it $POSTGRES_POD -n {prod-namespace} -- bash -c "psql $CHE_POSTGRES_DB < /tmp/che.sql"
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
. Scale down the {prod-short} deployment:
+
[subs="+quotes,+attributes"]
----
{orch-cli} scale deployment {prod-deployment} --replicas=0 -n {prod-namespace}
Copy link
Member

Choose a reason for hiding this comment

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

I believe it would be great to use some env var for namespace. Otherwise, it will work only for defaults installations, and will not work for specific setups like dogfooding / Developer Sandbox

Copy link
Contributor

@tolusha tolusha Dec 10, 2021

Choose a reason for hiding this comment

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

It make perfect sense but all documentation is based on the fact that Eclipse Che is deployed in {prod-namespace}
which is eclipse-che (openshift-workspaces)
So, to be honest I don't know how to handle this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume if namespace is different, then user must change it in the scrips manually.

Copy link
Member

@ibuziuk ibuziuk Dec 10, 2021

Choose a reason for hiding this comment

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

I would probably introduce NAMESPACE env var, it is really error-prone to expect from an admin to patch the scripts manually

Copy link
Contributor

Choose a reason for hiding this comment

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

I fully agree with @ibuziuk.

Copy link
Contributor

Choose a reason for hiding this comment

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

so into which repo will we move the script(s) so that they can evolve outside the docs, and not be beholden to doc-related validation rules? Also then we can tell a user "set your namespace variable, curl this URL, run this script, and you're done!"

Copy link
Contributor

@nickboldt nickboldt Mar 15, 2022

Choose a reason for hiding this comment

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

----
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
. Scale down the {identity-provider} deployment:
+
[subs="+quotes,+attributes"]
----
{orch-cli} scale deployment keycloak --replicas=0 -n {prod-namespace}
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
. Open Dashboard:
+
[subs="+quotes,+attributes"]
----
{prod-cli} dashboard:open -n {prod-namespace}
----

. Log in the {prod}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[subs="+quotes,+attributes"]
----
while [[ $({orch-cli} get pod -l app.kubernetes.io/component={k8s-component} -n {k8s-namespace} -o go-template='{{len .items}}') == 0 ]]
do
echo "Waiting..."
sleep 10s
done
{orch-cli} wait --for=condition=ready pod -l app.kubernetes.io/component={k8s-component} -n {k8s-namespace} --timeout=120s
----