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

Developer Env Setup script: add more automation steps #44

Merged
merged 32 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
875c82b
Dev Env setup script: add new step: generate certs and keys necessary…
kispaljr May 8, 2024
bb1e1ec
Dev Env setup script: bugfix: call the makekeys.sh script properly
kispaljr May 8, 2024
da9c821
dev-env setup script improvements
kispaljr May 22, 2024
8aa0e94
Bump up local kube-apiserver version to 1.30.1 to keep it aligned wit…
kispaljr May 22, 2024
d1b8498
dev-env setup script: additional automated steps
kispaljr May 23, 2024
d200903
dev-env setup script: minor fixes
kispaljr May 24, 2024
2710e2a
dev-env tutorial README update
kispaljr May 24, 2024
0850696
Update dev-env setup tutorial to reflect the changes in the new setup…
kispaljr May 27, 2024
030fd85
Update the dev env setup docs
kispaljr May 27, 2024
d96f6db
minor improvements in dev env documentation.
kispaljr May 27, 2024
c9c91f7
Document the requirement to register the api service in /etc/hosts fo…
kispaljr May 27, 2024
684dca8
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
9b3bffd
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
24e305e
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
004c683
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
618d52d
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
596d200
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
76a4094
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
1c6cc25
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
7baa216
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
108c0a5
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
f3ca8fa
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
5b60313
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
2b4db85
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
8b02be8
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
4111d2e
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
6facb88
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
505d3f1
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
9836cd9
Update docs/tutorials/porch-development-environment/README.md
kispaljr May 28, 2024
c0d58ed
dev-env setup script: de-duplicating CRD installation
kispaljr May 28, 2024
2e27c19
dev-env setup script: actually remove porch-server from the deploymen…
kispaljr May 28, 2024
af2b432
Revert "Bump up local kube-apiserver version to 1.30.1 to keep it ali…
kispaljr May 28, 2024
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
30 changes: 4 additions & 26 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/porch/main.go",
"args": [
"--secure-port=9443",
"--secure-port=4443",
"--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=172.18.255.201:9445",
"--repo-sync-frequency=60s"
],
"cwd": "${workspaceFolder}"
},
Expand All @@ -44,29 +45,6 @@
"--",
"namespace=foo"
]
},
{
"name": "Launch kpt",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/../main.go",
"args": [
"alpha", "rpkg", "get"
],
"cwd": "${workspaceFolder}/.."
},
{
"name": "Launch kpt e2e test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/../e2e",
"args": [
"-v",
"-test.run",
"TestPorch"
]
}
]
}
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ generate: generate-api
tidy:
@for f in $(MODULES); do (cd $$f; echo "Tidying $$f"; go mod tidy) || exit 1; done

.PHONY: test-e2e
test-e2e:
E2E=1 go test -v -race --count=1 -failfast ./test/e2e

.PHONY: configure-git
configure-git:
git config --global --add user.name test
Expand Down Expand Up @@ -266,8 +270,8 @@ push-and-deploy: push-images deploy
# `push-and-deploy` etc.)
.PHONY: deployment-config-no-sa
deployment-config-no-sa:
rm -rf $(DEPLOYCONFIG_NO_SA_DIR) || true
mkdir -p $(DEPLOYCONFIG_NO_SA_DIR)
find $(DEPLOYCONFIG_NO_SA_DIR) ! -name 'resourcegroup.yaml' -type f -exec rm -f {} +
./scripts/create-deployment-blueprint.sh \
--destination "$(DEPLOYCONFIG_NO_SA_DIR)" \
--server-image "$(IMAGE_REPO)/$(PORCH_SERVER_IMAGE):$(IMAGE_TAG)" \
Expand Down
18 changes: 18 additions & 0 deletions deployments/local/porch-api-endpoints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Endpoints
metadata:
annotations:
config.kubernetes.io/target-path: 3-porch-server-endpoints.yaml
name: api
namespace: porch-system
subsets:
- addresses:
- ip: 172.17.0.1
ports:
- appProtocol: https
name: api
port: 4443
protocol: TCP
- name: webhooks
port: 8443
protocol: TCP
455 changes: 99 additions & 356 deletions docs/tutorials/porch-development-environment/README.md

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions docs/tutorials/porch-development-environment/bin/cleardown.sh

This file was deleted.

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
158 changes: 129 additions & 29 deletions docs/tutorials/porch-development-environment/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
# 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
function_runner_ip=172.18.255.201

self_dir="$(dirname "$(readlink -f "$0")")"
git_root="$(readlink -f "${self_dir}/../../../..")"
cd "${git_root}"

function h1() {
echo
Expand All @@ -40,8 +44,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 +63,54 @@ 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
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,11 +120,101 @@ 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
kispaljr marked this conversation as resolved.
Show resolved Hide resolved
cd "${git_root}"
deployments/local/makekeys.sh

############################################
h1 Load container images into kind cluster
cd "${git_root}"
export IMAGE_TAG=v2.0.0
export KIND_CONTEXT_NAME="$porch_cluster_name"
if ! docker exec -it "$porch_cluster_name-control-plane" crictl images | grep -q docker.io/nephio/test-git-server ; then
make build-images
kind load docker-image docker.io/nephio/porch-controllers:${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
kind load docker-image docker.io/nephio/porch-function-runner:${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
kind load docker-image docker.io/nephio/porch-wrapper-server:${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
kind load docker-image docker.io/nephio/test-git-server:${IMAGE_TAG} -n ${KIND_CONTEXT_NAME}
efiacor marked this conversation as resolved.
Show resolved Hide resolved
else
echo "Images already loaded into kind cluster."
fi

############################################
h1 "Clean up"
cd "$self_dir"
rm -fr "$TMP_DIR"
h1 Install all porch components, except porch-server
cd "${git_root}"
make deployment-config-no-sa
efiacor marked this conversation as resolved.
Show resolved Hide resolved
cd .build/deploy-no-sa
# expose function-runner to local processes
kpt fn eval \
--image gcr.io/kpt-fn/starlark:v0.5.0 \
--match-kind Service \
--match-name function-runner \
--match-namespace porch-system \
-- "ip=${function_runner_ip}" 'source=
ip = ctx.resource_list["functionConfig"]["data"]["ip"]
for resource in ctx.resource_list["items"]:
resource["metadata"].setdefault("annotations", {})["metallb.universe.tf/loadBalancerIPs"] = ip
resource["spec"]["type"] = "LoadBalancer"
resource["spec"]["ports"][0]["nodePort"] = 30001'
# "remove" porch-server from package
kispaljr marked this conversation as resolved.
Show resolved Hide resolved
kpt fn eval \
--image gcr.io/kpt-fn/starlark:v0.5.0 \
--match-kind Deployment \
--match-name porch-server \
--match-namespace porch-system \
-- 'source=ctx.resource_list["items"] = []'
# make the api service point to the local porch-server
if [ "$(uname)" = "Darwin" ]
then
# MAC
kpt fn eval \
--image gcr.io/kpt-fn/starlark:v0.5.0 \
--match-kind Service \
--match-name api \
--match-namespace porch-system \
-- 'source=
for resource in ctx.resource_list["items"]:
resource["spec"] = {
"type": "ExternalName",
"externalName": "host.docker.internal"
}
'

else
# Linux
docker_bridge_ip="$(docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}')"
kpt fn eval \
--image upsert-resource:v0.2.0 \
--fn-config "${git_root}/deployments/local/porch-api-endpoints.yaml"
kpt fn eval \
--image gcr.io/kpt-fn/search-replace:v0.2.0 \
--match-kind Endpoints \
--match-name api \
--match-namespace porch-system \
-- 'by-path=subsets[0].addresses[0].ip' "put-value=$docker_bridge_ip"
kpt fn eval \
--image gcr.io/kpt-fn/starlark:v0.5.0 \
--match-kind Service \
--match-name api \
--match-namespace porch-system \
-- 'source=
for resource in ctx.resource_list["items"]:
resource["spec"].pop("selector")'
fi
kpt fn render
kpt live init || true
kpt live apply --inventory-policy=adopt

############################################
h1 "Build the porch CLI (.build/porchctl)"
cd "${git_root}"
make porchctl


############################################
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"
}
]
}
Loading