-
Notifications
You must be signed in to change notification settings - Fork 20
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
Refactor of the Developer Environment setup script #43
Merged
nephio-prow
merged 5 commits into
nephio-project:main
from
nokia:dev-env-setup-refactor
May 13, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0af3fbe
Dev Env script: discard edge1 cluster (not needed for porch testing)
kispaljr 0e93369
Dev Env setup script: major refactor
kispaljr 21061e4
Dev Env setup script: ensure that Gitea's nodePort matches with the p…
kispaljr 3000799
Dev Env setup script: wait for Deployment availability instead of Pod…
kispaljr 7688c9c
Dev Env setup script: check if git user.name config is set
kispaljr 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
21 changes: 21 additions & 0 deletions
21
docs/tutorials/porch-development-environment/bin/replace-gitea-service-ports.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,21 @@ | ||
apiVersion: fn.kpt.dev/v1alpha1 | ||
kind: ApplyReplacements | ||
metadata: | ||
name: replace-gitea-service | ||
replacements: | ||
- source: | ||
group: kind.x-k8s.io | ||
kind: Cluster | ||
fieldPath: nodes.0.extraPortMappings.0.containerPort | ||
targets: | ||
- select: | ||
kind: Service | ||
name: gitea | ||
namespace: gitea | ||
fieldPaths: | ||
- spec.ports.[name=http].nodePort | ||
options: | ||
create: true | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#! /bin/bash | ||
#! /bin/bash -e | ||
|
||
# Copyright 2024 The kpt and Nephio Authors | ||
# | ||
|
@@ -14,93 +14,107 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
os_type=$(uname) | ||
if [ "$os_type" = "Darwin" ] | ||
then | ||
SED="gsed" | ||
else | ||
SED="sed" | ||
porch_cluster_name=porch-test | ||
git_repo_name="$porch_cluster_name" | ||
gitea_ip=172.18.255.200 # should be from the address range specified here: https://github.com/nephio-project/porch/blob/main/docs/tutorials/starting-with-porch/metallb-conf.yaml | ||
self_dir="$(dirname "$(readlink -f "$0")")" | ||
|
||
function h1() { | ||
echo | ||
echo "** $*" | ||
echo | ||
} | ||
|
||
# check if git user.name is set in your environment | ||
if ! git config --global user.name > /dev/null ; then | ||
cat << ENDOFEMSG | ||
Please set the user.name and user.email global configuration values in your git environment. | ||
This is needed for porch tests to run correctly. | ||
E.g: | ||
git config --global user.name "My Name" | ||
git config --global user.email "[email protected]" | ||
ENDOFEMSG | ||
exit 128 | ||
fi | ||
|
||
# Create mgmt and edge1 clusters in kind | ||
curl -s https://raw.githubusercontent.com/nephio-project/porch/main/docs/tutorials/starting-with-porch/kind_management_cluster.yaml | \ | ||
kind create cluster --config=- | ||
|
||
curl -s https://raw.githubusercontent.com/nephio-project/porch/main/docs/tutorials/starting-with-porch/kind_edge1_cluster.yaml | \ | ||
kind create cluster --config=- | ||
|
||
kind get kubeconfig --name=management > ~/.kube/kind-management-config | ||
kind get kubeconfig --name=edge1 > ~/.kube/kind-edge1-config | ||
############################################## | ||
h1 "Install kind cluster: $porch_cluster_name" | ||
if ! kind get clusters | grep -q "^$porch_cluster_name\$" ; then | ||
curl -s https://raw.githubusercontent.com/nephio-project/porch/main/docs/tutorials/starting-with-porch/kind_management_cluster.yaml | \ | ||
kind create cluster --config=- --name "$porch_cluster_name" || true | ||
|
||
export KUBECONFIG=~/.kube/kind-management-config | ||
mkdir -p ~/.kube | ||
kind get kubeconfig --name="$porch_cluster_name" > ~/.kube/"kind-$porch_cluster_name" | ||
else | ||
echo "Cluster already exists." | ||
fi | ||
kind export kubeconfig --name="$porch_cluster_name" | ||
|
||
# Instal MetalLB | ||
############################################## | ||
h1 Instal MetalLB | ||
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.12/config/manifests/metallb-native.yaml | ||
kubectl wait --namespace metallb-system \ | ||
--for=condition=ready pod \ | ||
--selector=component=controller \ | ||
sleep 1 | ||
echo "Waiting for controller to become ready..." | ||
kubectl wait --namespace metallb-system deploy controller \ | ||
--for=condition=available \ | ||
--timeout=90s | ||
|
||
kubectl apply -f https://raw.githubusercontent.com/nephio-project/porch/main/docs/tutorials/starting-with-porch/metallb-conf.yaml | ||
|
||
############################################ | ||
h1 Prepare tmp dir | ||
TMP_DIR=$(mktemp -d) | ||
echo "$TMP_DIR" | ||
|
||
pushd "$TMP_DIR" || exit | ||
|
||
mkdir kpt_packages | ||
pushd kpt_packages || exit | ||
|
||
# Install Gitea | ||
############################################ | ||
h1 Install Gitea | ||
mkdir "$TMP_DIR/kpt_packages" | ||
cd "$TMP_DIR/kpt_packages" | ||
kpt pkg get https://github.com/nephio-project/catalog/tree/main/distros/sandbox/gitea | ||
$SED -i 's/ metallb.universe.tf/ #metallb.universe.tf/' gitea/service-gitea.yaml | ||
kpt fn eval gitea \ | ||
--image gcr.io/kpt-fn/set-annotations:v0.1.4 \ | ||
--match-kind Service \ | ||
--match-name gitea \ | ||
--match-namespace gitea \ | ||
-- "metallb.universe.tf/loadBalancerIPs=${gitea_ip}" | ||
curl -o gitea/cluster-config.yaml https://raw.githubusercontent.com/nephio-project/porch/main/docs/tutorials/starting-with-porch/kind_management_cluster.yaml | ||
echo "metadata: { name: "porch-test" }" >> gitea/cluster-config.yaml | ||
kpt fn eval gitea \ | ||
--image gcr.io/kpt-fn/set-annotations:v0.1.4 \ | ||
--match-kind Cluster \ | ||
--match-api-version kind.x-k8s.io/v1alpha4 \ | ||
-- "config.kubernetes.io/local-config=true" | ||
kpt fn eval gitea \ | ||
--image gcr.io/kpt-fn/apply-replacements:v0.1.1 \ | ||
--fn-config "${self_dir}/replace-gitea-service-ports.yaml" | ||
|
||
kpt fn render gitea | ||
kpt live init gitea | ||
kpt live apply gitea | ||
|
||
popd || exit | ||
|
||
# Create management and edge1 repos in gitea | ||
curl -k -H "content-type: application/json" "http://nephio:[email protected]:3000/api/v1/user/repos" --data '{"name":"management"}' | ||
curl -k -H "content-type: application/json" "http://nephio:[email protected]:3000/api/v1/user/repos" --data '{"name":"edge1"}' | ||
|
||
mkdir repos | ||
pushd repos || exit | ||
|
||
# Initialize management and edge1 repos in Gitea | ||
git clone http://172.18.255.200:3000/nephio/management | ||
pushd management || exit | ||
|
||
touch README.md | ||
git init | ||
git checkout -b main | ||
git config user.name nephio | ||
git add README.md | ||
|
||
git commit -m "first commit" | ||
git remote remove origin | ||
git remote add origin http://nephio:[email protected]:3000/nephio/management.git | ||
git remote -v | ||
git push -u origin main | ||
popd || exit | ||
|
||
git clone http://172.18.255.200:3000/nephio/edge1 | ||
pushd edge1 || exit | ||
|
||
touch README.md | ||
git init | ||
git checkout -b main | ||
git config user.name nephio | ||
git add README.md | ||
|
||
git commit -m "first commit" | ||
git remote remove origin | ||
git remote add origin http://nephio:[email protected]:3000/nephio/edge1.git | ||
git remote -v | ||
git push -u origin main | ||
popd || exit | ||
|
||
popd || exit | ||
############################################ | ||
h1 Create git repos in gitea | ||
curl -k -H "content-type: application/json" "http://nephio:secret@${gitea_ip}:3000/api/v1/user/repos" --data "{\"name\":\"$git_repo_name\"}" | ||
|
||
mkdir "$TMP_DIR/repos" | ||
cd "$TMP_DIR/repos" | ||
git clone "http://nephio:secret@${gitea_ip}:3000/nephio/$git_repo_name" | ||
cd "$git_repo_name" | ||
|
||
if ! git rev-parse -q --verify refs/remotes/origin/main >/dev/null; then | ||
git switch -c main | ||
touch README.md | ||
git add README.md | ||
git config user.name nephio | ||
git commit -m "first commit" | ||
git push -u origin main | ||
else | ||
echo "main branch already exists in git repo." | ||
fi | ||
|
||
############################################ | ||
h1 "Clean up" | ||
cd "$self_dir" | ||
rm -fr "$TMP_DIR" | ||
|
||
kubectl config use-context kind-management | ||
echo | ||
echo Done. |
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.
Not a major issue but I think the orig guide, which this is an extension of is using the egde1 cluster.
https://github.com/nephio-project/porch/tree/main/docs/tutorials/starting-with-porch#deploying-a-blueprint-onto-a-workload-cluster
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.
Yes, I was a bit uncertain regarding removing edge1. My rationale was that the "Starting with Porch" tutorial is more like a "User's Guide", while this script belongs to the "Setup the Developer Environment" guide. And I think edge1 is not needed to develop and test porch, it belongs more to ConfigSync.
All-in-all I can add back edge1 if we think there is need for it during development.
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.
Maybe adding back the edge1 git repo only, but not the kind cluster would also make sense.
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.
Ye I guess either way the README guides will need to be updated a bit.
May be best to get @liamfallon direction on it when he is back on 13/05
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.
I am planning to update the text of the tutorial as part of #44