Skip to content

Commit

Permalink
dev-env setup script improvements
Browse files Browse the repository at this point in the history
- make the setup script rely on local config files instead of remote ones from github
- keep gitea deployment kpt package in .build directory (as opposed to a temp dir) in order to keep the local inventory for future updates
- vscode: remove kpt-related folders from workspace
- vscode: adopt porch-server launch paremeters to the porch components running in the test kind cluster
  • Loading branch information
kispaljr committed May 22, 2024
1 parent bb1e1ec commit da9c821
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"--secure-port=9443",
"--v=7",
"--standalone-debug-mode",
"--kubeconfig=${workspaceFolder}/deployments/local/kubeconfig",
"--kubeconfig=${env:KUBECONFIG}",
"--cache-directory=${workspaceFolder}/.cache",
"--function-runner=192.168.8.202:9445"
"--function-runner=localhost:30001",
"--repo-sync-frequency=60s"
],
"cwd": "${workspaceFolder}"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: management
networking:
apiServerAddress: 127.0.0.1
apiServerPort: 31000
podSubnet: 10.97.0.0/16
serviceSubnet: 10.197.0.0/16
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30000 # Gitea NodePort
hostPort: 3000
- containerPort: 30001 # function-runner NodePort
hostPort: 30001
65 changes: 37 additions & 28 deletions docs/tutorials/porch-development-environment/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

porch_cluster_name=porch-test
porch_cluster_name=${PORCH_TEST_CLUSTER:-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
gitea_ip=172.18.255.200 # should be from the address range specified here: docs/tutorials/starting-with-porch/metallb-conf.yaml
self_dir="$(dirname "$(readlink -f "$0")")"
git_root="$(readlink -f "${self_dir}/../../../..")"
cd "${git_root}"

function h1() {
echo
Expand All @@ -40,8 +42,9 @@ fi
##############################################
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
kind create cluster \
--config="${git_root}/docs/tutorials/porch-development-environment/bin/kind_porch_test_cluster.yaml" \
--name "$porch_cluster_name" || true

mkdir -p ~/.kube
kind get kubeconfig --name="$porch_cluster_name" > ~/.kube/"kind-$porch_cluster_name"
Expand All @@ -58,49 +61,56 @@ 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"
kubectl apply -f "${git_root}/docs/tutorials/starting-with-porch/metallb-conf.yaml"

############################################
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
mkdir -p "${git_root}/.build"
cd "${git_root}/.build"
if [ -d gitea ]; then
kpt pkg update gitea
else
kpt pkg get https://github.com/nephio-project/catalog/tree/main/distros/sandbox/gitea
fi

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"

cp -f "${git_root}/docs/tutorials/porch-development-environment/bin/kind_porch_test_cluster.yaml" gitea/cluster-config.yaml
# turn kind's cluster-config into a valid KRM
cat >> gitea/cluster-config.yaml <<EOF1
metadata:
name: not-used
annotations:
config.kubernetes.io/local-config: "true"
EOF1
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
kpt live init gitea || true
kpt live apply gitea --inventory-policy=adopt --output=table
echo "Waiting for gitea to become ready..."
kubectl wait --namespace gitea statefulset gitea \
--for='jsonpath={.status.readyReplicas}=1' \
--timeout=90s

############################################
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"
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
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
echo "Add main branch to git repo:"
git switch -c main
touch README.md
git add README.md
Expand All @@ -110,15 +120,14 @@ if ! git rev-parse -q --verify refs/remotes/origin/main >/dev/null; then
else
echo "main branch already exists in git repo."
fi
cd "${git_root}"
rm -fr "$TMP_DIR"

############################################
h1 Generate certs and keys
cd "${self_dir}/../../../../"
cd "${git_root}"
deployments/local/makekeys.sh

############################################
h1 "Clean up"
cd "$self_dir"
rm -fr "$TMP_DIR"
echo
echo Done.
8 changes: 0 additions & 8 deletions porch.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@
"name": "porch",
"path": "."
},
{
"name": "kpt",
"path": ".."
},
{
"name": "controllers",
"path": "controllers"
},
{
"name": "rollouts",
"path": "../rollouts"
}
]
}

0 comments on commit da9c821

Please sign in to comment.