Skip to content

Commit

Permalink
setup part of local registry
Browse files Browse the repository at this point in the history
Signed-off-by: YaoZengzeng <yaozengzeng@huawei.com>
  • Loading branch information
YaoZengzeng committed Jun 19, 2024
1 parent c3f3c77 commit dec0648
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ build:
docker: build
docker build --build-arg arch=$(DIR) -f build/docker/kmesh.dockerfile -t $(HUB)/$(TARGET):$(TAG) .

docker.push: docker
docker push $(HUB)/$(TARGET):$(TAG)

e2e:
./test/e2e/run_test.sh

Expand Down
2 changes: 1 addition & 1 deletion deploy/yaml/kmesh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spec:
path: istio-token
containers:
- name: kmesh
image: ghcr.io/kmesh-net/kmesh:latest
image: localhost:5000/kmesh:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c"]
args: ["./start_kmesh.sh --mode=workload"]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
k8s.io/api v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/client-go v0.30.1
sigs.k8s.io/gateway-api v1.1.0
sigs.k8s.io/yaml v1.4.0
)

Expand Down Expand Up @@ -231,7 +232,6 @@ require (
k8s.io/kubectl v0.30.1 // indirect
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 // indirect
sigs.k8s.io/controller-runtime v0.18.3 // indirect
sigs.k8s.io/gateway-api v1.1.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.16.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/baseline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ var (
}
)

func TestKmesh(t *testing.T) {
framework.NewTest(t).Run(func(t framework.TestContext) {
time.Sleep(100 * time.Second)
})
}

func TestTrafficSplit(t *testing.T) {
runTest(t, func(t framework.TestContext, src echo.Instance, dst echo.Instance, opt echo.CallOptions) {
// Need at least one waypoint proxy and HTTP
Expand Down
78 changes: 76 additions & 2 deletions test/e2e/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,73 @@ function setup_kind_cluster() {
fi

# Create KinD cluster.
if ! (kind create cluster --name="${NAME}" -v4 --retain --image "${IMAGE}"); then
cat <<EOF | kind create cluster --name="${NAME}" -v4 --retain --image "${IMAGE}" --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
EOF

status=$?
if [ $status -ne 0 ]; then
echo "Could not setup KinD environment. Something wrong with KinD setup. Exporting logs."
fi
fi
}

export KIND_REGISTRY_NAME="kind-registry"
export KIND_REGISTRY_PORT="5000"
export KIND_REGISTRY="localhost:${KIND_REGISTRY_PORT}"
export HUB="${KIND_REGISTRY}"

# Provision a local docker registry, so KinD nodes could pull images from.
# https://kind.sigs.k8s.io/docs/user/local-registry/
function setup_kind_registry() {
running="$(docker inspect -f '{{.State.Running}}' "${KIND_REGISTRY_NAME}" 2>/dev/null || true)"
if [[ "${running}" != 'true' ]]; then
docker run \
-d --restart=always -p "${KIND_REGISTRY_PORT}:5000" --name "${KIND_REGISTRY_NAME}" \
gcr.io/istio-testing/registry:2

# Allow kind nodes to reach the registry
docker network connect "kind" "${KIND_REGISTRY_NAME}"
fi

# Add the registry config to the nodes
#
# This is necessary because localhost resolves to loopback addresses that are network-namespace local.
# In other words: localhost in the container is not localhost on the host.
#
# We want a consistent name that works from both ends, so we tell containerd to alias localhost:${reg_port}
# to the registry container when pulling images
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${KIND_REGISTRY_PORT}"
for node in $(kind get nodes); do
docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
cat << EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
[host."http://${KIND_REGISTRY_NAME}:5000"]
EOF
done

# Allow kind nodes to reach the registry
# docker network connect "kind" "${KIND_REGISTRY_NAME}"

# Document the local registry
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF
}

function build_and_push_images() {
make docker.push
}

while (( "$#" )); do
Expand All @@ -32,11 +96,21 @@ while (( "$#" )); do
SKIP_SETUP=true
shift
;;
--skip-build)
SKIP_BUILD=true
shift
;;
esac
done

if [[ -z "${SKIP_SETUP:-}" ]]; then
setup_kind_cluster
fi

if [[ -z "${SKIP_BUILD:-}" ]]; then
setup_kind_registry

build_and_push_images
fi

go test -v -tags=integ ./test/e2e/...

0 comments on commit dec0648

Please sign in to comment.