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

Refactor of the Developer Environment setup script #43

Merged
merged 5 commits into from
May 13, 2024
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
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



160 changes: 87 additions & 73 deletions docs/tutorials/porch-development-environment/bin/setup.sh
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
#
Expand All @@ -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 "myemail@example.com"
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 | \
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator Author

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

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:secret@172.18.255.200:3000/api/v1/user/repos" --data '{"name":"management"}'
curl -k -H "content-type: application/json" "http://nephio:secret@172.18.255.200: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:secret@172.18.255.200: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:secret@172.18.255.200: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.