Skip to content

Commit

Permalink
Refactor Hive Directory (#3765)
Browse files Browse the repository at this point in the history
* Move Hive hack files under one directory
Group the Hive files under hack directory to hack/hive

* Refactor Hive installation and hack files location
Group the Hive files under hack directory to hack/hive, and refactor Hive installation using main function and utils.sh

* Print troubleshooting for Hive deployment rollout
Trust in the operator installation and print two options to monitor Hive deployment rollout

* Small fixes for hive installation script
Use double quote to prevent word splitting, break long line into multiple, use '-n' over '! -z', simpler if check, use consistent function declaration syntax, trap outside main and after cleanup is declared
  • Loading branch information
razo7 authored Sep 11, 2024
1 parent fa7af61 commit abf4167
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 100 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ gomock_reflect_*
/portal/v2/node_modules/
portal/v2/.vscode/
.idea*
/hack/hive-config/crds
/hack/hive-config/hive-deployment.yaml
/hack/hive/hive-config/crds
/hack/hive/hive-config/hive-deployment.yaml
cmd/aro/__debug_bin
megalinter-reports/
/db
Expand Down
4 changes: 2 additions & 2 deletions docs/deploy-full-rp-service-in-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
1. Now that your machine is able access the AKS cluster, you can deploy Hive:
```bash
make aks.kubeconfig
./hack/hive-generate-config.sh
KUBECONFIG=$(pwd)/aks.kubeconfig ./hack/hive-dev-install.sh
./hack/hive/hive-generate-config.sh
KUBECONFIG=$(pwd)/aks.kubeconfig ./hack/hive/hive-dev-install.sh
```

1. Mirror the OpenShift images to your new Azure Container Registry (ACR)
Expand Down
13 changes: 7 additions & 6 deletions docs/hive.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## Version

The commit sha is used to specify the image tag and also used during config generation to checkout the correct version of the config files. The config files are subsequently used by the `hack/hive-dev-install.sh` script during installation or during config updates.
The commit sha is used to specify the image tag and also used during config generation to checkout the correct version of the config files. The config files are subsequently used by the `hack/hive/hive-dev-install.sh` script during installation or during config updates.

1. You can either
1. Provide the hive image commit has as an argument to `hack/hive-generate-config.sh`. This is useful for testing new hive images before hive releases.
1. Example: `./hack/hive-generate-config.sh d7ead609f4`
1. Provide the hive image commit has as an argument to `hack/hive/hive-generate-config.sh`. This is useful for testing new hive images before hive releases.
1. Example: `./hack/hive/hive-generate-config.sh d7ead609f4`
2. Accept the default version by providing no arguments, which should be the latest.
1. Example: `./hack/hive-generate-config.sh`
1. Example: `./hack/hive/hive-generate-config.sh`

## Generating config

Expand All @@ -18,7 +18,7 @@ In order to generate config for a dev environment you need to ensure you have th
# source your environment file
. ./env
# run the config generation
./hack/hive-generate-config.sh
./hack/hive/hive-generate-config.sh
```

This will download the latest source, reset to the hash specified in HIVE_IMAGE_COMMIT_HASH, and build the config using kustomise.
Expand All @@ -41,5 +41,6 @@ This will download the latest source, reset to the hash specified in HIVE_IMAGE_
```
4. Installing then simply requires the running of the install script.
```bash
./hack/hive-dev-install.sh
./hack/hive/hive-dev-install.sh
```
> __NOTE:__ When Hive is already installed and SKIP_DEPLOYMENTS is set to "true" then Hive installation can be skipped without user's approval.
85 changes: 0 additions & 85 deletions hack/hive-dev-install.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package hiveconfig
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

//go:generate go run ../genhiveconfig ./hive-additional-install-log-regexes.yaml
//go:generate go run ../../genhiveconfig ./hive-additional-install-log-regexes.yaml
File renamed without changes.
98 changes: 98 additions & 0 deletions hack/hive/hive-dev-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

set -o errexit \
-o nounset

declare -r utils=hack/util.sh
if [ -f "$utils" ]; then
# shellcheck source=../util.sh
source "$utils"
fi

HIVE_OPERATOR_NS="hive"
KUBECTL="$( which kubectl 2> /dev/null || which oc 2> /dev/null)"

if [ ! -f go.mod ] || [ ! -d ".git" ]; then
abort "this script must by run from the repo's root directory"
fi


function cleanup() {
[ -f "$(pwd)/kubectl" ] && rm -f "$(pwd)/kubectl"
}
trap cleanup EXIT

main() {
log "enter hive installation"
local skip_deployments=${1:-"none"}

if [ ! -f "./hack/hive/hive-config/hive-deployment.yaml" ] || [ ! -d "./hack/hive/hive-config/crds" ] ; then
log "hive config is missing, generating config, please rerun this script afterwards"
./hack/hive/hive-generate-config.sh
if [ $? -ne 0 ]; then
abort "error generating the hive configs"
fi
fi

if [ -z "$PULL_SECRET" ]; then
log "global pull secret variable required, please source ./env"
exit
fi
verify_tools

if [ "$( $KUBECTL get namespace $HIVE_OPERATOR_NS -o yaml 2>/dev/null | wc -l )" -ne 0 ]; then
log "hive is already installed in namespace $HIVE_OPERATOR_NS"
log -n "would you like to reapply the configs? (y/N): "
read answer
if [[ "$answer" != "y" ]]; then
exit
fi
else
$KUBECTL create namespace $HIVE_OPERATOR_NS
fi

log "Hive is ready to be installed"
$KUBECTL apply -f ./hack/hive/hive-config/crds
echo "$PULL_SECRET" > /tmp/.tmp-secret
# Using dry-run allows updates to work seamlessly
$KUBECTL create secret generic hive-global-pull-secret \
--from-file=.dockerconfigjson=/tmp/.tmp-secret \
--type=kubernetes.io/dockerconfigjson \
--namespace $HIVE_OPERATOR_NS \
-o yaml \
--dry-run=client \
| $KUBECTL apply -f - 2>/dev/null
rm -f /tmp/.tmp-secret

sed "s/HIVE_OPERATOR_NS/$HIVE_OPERATOR_NS/g" hack/hive/hive-config/hive-config.yaml | $KUBECTL apply -f -
$KUBECTL apply -f ./hack/hive/hive-config/hive-additional-install-log-regexes.yaml
$KUBECTL apply -f ./hack/hive/hive-config/hive-deployment.yaml
$KUBECTL wait --timeout=5m --for=condition=Available --namespace $HIVE_OPERATOR_NS deployment/hive-operator

log "Hive is installed but to check Hive readiness use one of the following options to monitor the deployment rollout:
'kubectl wait --timeout=5m --for=condition=Available --namespace "$HIVE_OPERATOR_NS" deployment/hive-controllers'
or 'kubectl wait --timeout=5m --for=condition=Ready --namespace "$HIVE_OPERATOR_NS" pod --selector control-plane=clustersync'"
}

function download_tmp_kubectl() {
if curl -sLO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"; then
abort ": error downloading kubectl"
fi
chmod 755 kubectl
KUBECTL="$(pwd)/kubectl"
}

function verify_tools() {
if [ -n "$KUBECTL" ]; then
return
fi
log "kubectl or oc not detected, downloading"
download_tmp_kubectl
log "done: downloading kubectl/oc was completed"

if [ "$( $KUBECTL get nodes 2>/dev/null | wc -l )" -eq 0 ]; then
abort "unable to connect to the cluster"
fi
}

main "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ generate_hive_config() {

# return to the repo directory to copy the generated config from $TMPDIR
popd 1> /dev/null
mv "$tmpd/hive-deployment.yaml" ./hack/hive-config/
mv "$tmpd/hive-deployment.yaml" ./hack/hive/hive-config/

if [ -d ./hack/hive-config/crds ]; then
rm -rf ./hack/hive-config/crds
if [ -d ./hack/hive/hive-config/crds ]; then
rm -rf ./hack/hive/hive-config/crds
fi
cp -R "$tmpd/config/crds" ./hack/hive-config/
cp -R "$tmpd/config/crds" ./hack/hive/hive-config/
}

if [ ! -f go.mod ] || [ ! -d ".git" ]; then
Expand Down

0 comments on commit abf4167

Please sign in to comment.