-
Notifications
You must be signed in to change notification settings - Fork 53
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
add systemd services for configuration after start #980
Open
anjannath
wants to merge
1
commit into
crc-org:master
Choose a base branch
from
anjannath:issue_638
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,34 @@ | ||
# Self sufficient bundles | ||
|
||
Since release 4.19.0 of OpenShift Local, the bundles generated by `snc` contain additional systemd services to provision the cluster and remove the need for | ||
an outside entity to provision the cluster, although an outside process needs to create some files on pre-defined locations inside the VM for the systemd | ||
services to do their work. | ||
|
||
## The following table lists the systemd services and the location of files they need to provision the cluster, users of SNC need to create those files | ||
|
||
| Systemd unit | Runs for (ocp, MicroShift, both) | Input files location | Marker env variables | | ||
| :----------------------------: | :------------------------------: | :----------------------------------: | :------------------: | | ||
| `crc-cluster-status.service` | both | none | none | | ||
| `crc-pullsecret.service` | both | /opt/crc/pull-secret | none | | ||
| `crc-dnsmasq.service` | both | none | none | | ||
| `crc-routes-controller.service`| both | none | none | | ||
| `ocp-cluster-ca.service` | ocp | /opt/crc/custom-ca.crt | CRC_CLOUD=1 | | ||
| `ocp-clusterid.service` | ocp | none | none | | ||
| `ocp-custom-domain.service` | ocp | none | CRC_CLOUD=1 | | ||
| `ocp-growfs.service` | ocp | none | none | | ||
| `ocp-userpasswords.service` | ocp | /opt/crc/pass_{kubeadmin, developer} | none | | ||
|
||
In addition to the above services we have `ocp-cluster-ca.path`, `crc-pullsecret.path` and `ocp-userpasswords.path` that monitors the filesystem paths | ||
related to their `*.service` counterparts and starts the service when the paths become available. | ||
|
||
> [!NOTE] | ||
> "Marker env variable" is set using an env file, if the required env variable is not set then unit is skipped | ||
> some units are run only when CRC_CLOUD=1 is set, these are only needed when using the bundles with crc-cloud | ||
The systemd services are heavily based on the [`clustersetup.sh`](https://github.com/crc-org/crc-cloud/blob/main/pkg/bundle/setup/clustersetup.sh) script found in the `crc-cloud` project. | ||
|
||
## Naming convention for the systemd unit files | ||
|
||
Systemd units that are needed for both 'OpenShift' and 'MicroShift' are named as `crc-*.service`, units that are needed only for 'OpenShift' are named | ||
as `ocp-*.service` and when we add units that are only needed for 'MicroShift' they should be named as `ucp-*.service` | ||
|
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,3 @@ | ||
#!/bin/bash | ||
|
||
echo -n "Machine lord: ${AVAR}" |
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,11 @@ | ||
[Unit] | ||
Description=CRC Unit checking if cluster is ready | ||
After=kubelet.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/local/bin/crc-cluster-status.sh | ||
RemainAfterExit=true | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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 | ||
|
||
set -x | ||
|
||
export KUBECONFIG=/opt/kubeconfig | ||
|
||
function check_cluster_healthy() { | ||
WAIT="authentication|console|etcd|ingress|openshift-apiserver" | ||
|
||
until `oc get co > /dev/null 2>&1` | ||
do | ||
sleep 2 | ||
done | ||
|
||
for i in $(oc get co | grep -P "$WAIT" | awk '{ print $3 }') | ||
do | ||
if [[ $i == "False" ]] | ||
then | ||
return 1 | ||
fi | ||
done | ||
return 0 | ||
} | ||
|
||
# rm -rf /tmp/.crc-cluster-ready | ||
|
||
COUNTER=0 | ||
CLUSTER_HEALTH_SLEEP=8 | ||
CLUSTER_HEALTH_RETRIES=500 | ||
|
||
while ! check_cluster_healthy | ||
do | ||
sleep $CLUSTER_HEALTH_SLEEP | ||
if [[ $COUNTER == $CLUSTER_HEALTH_RETRIES ]] | ||
then | ||
return 1 | ||
fi | ||
((COUNTER++)) | ||
done | ||
|
||
# need to set a marker to let `crc` know the cluster is ready | ||
# touch /tmp/.crc-cluster-ready | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, Are these commented-out lines important? If not, shall we remove them? |
||
|
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,15 @@ | ||
[Unit] | ||
Description=CRC Unit for configuring dnsmasq | ||
Wants=network-online.target | ||
After=network-online.target ssh-access.target ovs-configuration.service | ||
StartLimitIntervalSec=0 | ||
|
||
[Service] | ||
Type=oneshot | ||
Restart=on-failure | ||
EnvironmentFile=/etc/systemd/system/crc-env | ||
ExecStart=/usr/local/bin/crc-dnsmasq.sh | ||
ExecStartPost=/usr/bin/systemctl start dnsmasq.service | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,11 @@ | ||
[Unit] | ||
Description=CRC Unit for monitoring the pull secret path | ||
After=kubelet.service | ||
|
||
[Path] | ||
PathExists=/opt/crc/pull-secret | ||
TriggerLimitIntervalSec=1min | ||
TriggerLimitBurst=0 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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 @@ | ||
[Unit] | ||
Description=CRC Unit for adding pull secret to cluster | ||
After=kubelet.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/local/bin/crc-pullsecret.sh | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,21 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
source /usr/local/bin/crc-systemd-common.sh | ||
export KUBECONFIG="/opt/kubeconfig" | ||
|
||
wait_for_resource secret | ||
|
||
# check if existing pull-secret is valid if not add the one from /opt/crc/pull-secret | ||
existingPsB64=$(oc get secret pull-secret -n openshift-config -o jsonpath="{['data']['\.dockerconfigjson']}") | ||
existingPs=$(echo "${existingPsB64}" | base64 -d) | ||
|
||
echo "${existingPs}" | jq -e '.auths' | ||
|
||
if [[ $? != 0 ]]; then | ||
pullSecretB64=$(cat /opt/crc/pull-secret | base64 -w0) | ||
oc patch secret pull-secret -n openshift-config --type merge -p "{\"data\":{\".dockerconfigjson\":\"${pullSecretB64}\"}}" | ||
rm -f /opt/crc/pull-secret | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=CRC Unit starting routes controller | ||
Wants=network-online.target gvisor-tap-vsock.service sys-class-net-tap0.device | ||
After=sys-class-net-tap0.device network-online.target kubelet.service gvisor-tap-vsock.service | ||
|
||
[Service] | ||
Type=oneshot | ||
EnvironmentFile=/etc/systemd/system/crc-env | ||
ExecStart=/usr/local/bin/crc-routes-controller.sh | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,16 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
if [[ ${CRC_NETWORK_MODE_USER} -eq 0 ]]; then | ||
echo -n "network-mode 'system' detected: skipping routes-controller pod deployment" | ||
exit 0 | ||
fi | ||
|
||
source /usr/local/bin/crc-systemd-common.sh | ||
export KUBECONFIG=/opt/kubeconfig | ||
|
||
wait_for_resource pods | ||
|
||
oc apply -f /opt/crc/routes-controller.yaml | ||
|
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,12 @@ | ||
# $1 is the resource to check | ||
# $2 is an optional maximum retry count; default 20 | ||
function wait_for_resource() { | ||
local retry=0 | ||
local max_retry=${2:-20} | ||
until `oc get "$1" > /dev/null 2>&1` | ||
do | ||
[ $retry == $max_retry ] && exit 1 | ||
sleep 5 | ||
((retry++)) | ||
done | ||
} |
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,24 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
if [[ ${CRC_NETWORK_MODE_USER} -eq 1 ]]; then | ||
echo -n "network-mode 'user' detected: skipping dnsmasq configuration" | ||
exit 0 | ||
fi | ||
|
||
hostName=$(hostname) | ||
hostIp=$(hostname --all-ip-addresses | awk '{print $1}') | ||
|
||
cat << EOF > /etc/dnsmasq.d/crc-dnsmasq.conf | ||
listen-address=192.168.130.11 | ||
expand-hosts | ||
log-queries | ||
local=/crc.testing/ | ||
domain=crc.testing | ||
address=/${APPS_DOMAIN}/192.168.130.11 | ||
address=/api.crc.testing/192.168.130.11 | ||
address=/api-int.crc.testing/192.168.130.11 | ||
address=/$hostName/$hostIp | ||
EOF | ||
|
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,11 @@ | ||
[Unit] | ||
Description=CRC Unit monitoring custom-ca.crt file path | ||
After=kubelet.service | ||
|
||
[Path] | ||
PathExists=/opt/crc/custom-ca.crt | ||
TriggerLimitIntervalSec=1min | ||
TriggerLimitBurst=0 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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 @@ | ||
[Unit] | ||
Description=CRC Unit setting custom cluster ca | ||
After=kubelet.service ocp-clusterid.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/local/bin/ocp-cluster-ca.sh | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,22 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
source /usr/local/bin/crc-systemd-common.sh | ||
export KUBECONFIG="/opt/kubeconfig" | ||
|
||
wait_for_resource configmap | ||
|
||
custom_ca_path=/opt/crc/custom-ca.crt | ||
|
||
if [[ ! -f ${custom_ca_path} ]]; then | ||
echo "Cert bundle /opt/crc/custom-ca.crt not found" | ||
exit 0 | ||
fi | ||
|
||
oc create configmap client-ca-custom -n openshift-config --from-file=ca-bundle.crt=${custom_ca_path} | ||
oc patch apiserver cluster --type=merge -p '{"spec": {"clientCA": {"name": "client-ca-custom"}}}' | ||
oc create configmap admin-kubeconfig-client-ca -n openshift-config --from-file=ca-bundle.crt=${custom_ca_path} \ | ||
--dry-run -o yaml | oc replace -f - | ||
|
||
rm -f /opt/crc/custom-ca.crt |
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,11 @@ | ||
[Unit] | ||
Description=CRC Unit setting random cluster ID | ||
After=kubelet.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/local/bin/ocp-clusterid.sh | ||
Restart=on-failure | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,11 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
source /usr/local/bin/crc-systemd-common.sh | ||
export KUBECONFIG="/opt/kubeconfig" | ||
uuid=$(uuidgen) | ||
|
||
wait_for_resource clusterversion | ||
|
||
oc patch clusterversion version -p "{\"spec\":{\"clusterID\":\"${uuid}\"}}" --type merge |
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,11 @@ | ||
[Unit] | ||
Description=CRC Unit setting nip.io domain for cluster | ||
After=kubelet.service ocp-clusterid.service ocp-cluster-ca.service | ||
|
||
[Service] | ||
Type=oneshot | ||
EnvironmentFile=/etc/systemd/system/crc-env | ||
ExecStart=/usr/local/bin/ocp-custom-domain.sh | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/crc-org/snc/pull/980/files#r1888535323