Skip to content

Commit

Permalink
kind: Support local registry at "--deploy"
Browse files Browse the repository at this point in the history
This allow to use kind.sh and `--deploy` with kind local registry.
  • Loading branch information
qinqon committed Feb 28, 2023
1 parent c4b18ef commit 63bb8e0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
47 changes: 45 additions & 2 deletions contrib/kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ set_cluster_cidr_ip_families() {
create_kind_cluster() {
# Output of the j2 command
KIND_CONFIG_LCL=${DIR}/kind-${KIND_CLUSTER_NAME}.yaml
local reg_name='kind-registry'
local reg_port='5000'

ovn_ip_family=${IP_FAMILY} \
ovn_ha=${OVN_HA} \
Expand All @@ -603,7 +605,41 @@ create_kind_cluster() {
if kind get clusters | grep ovn; then
delete
fi
if [[ "${KIND_LOCAL_REGISTRY}" == true ]]; then
# create registry container unless it already exists
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
registry:2
fi
fi
kind create cluster --name "${KIND_CLUSTER_NAME}" --kubeconfig "${KUBECONFIG}" --image "${KIND_IMAGE}":"${K8S_VERSION}" --config=${KIND_CONFIG_LCL} --retain
# connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi
if [[ "${KIND_LOCAL_REGISTRY}" == true ]]; then

# connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi

# Document the local registry
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-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
fi

cat "${KUBECONFIG}"
}

Expand Down Expand Up @@ -685,10 +721,16 @@ build_ovn_image() {
}

create_ovn_kube_manifests() {
local ovnkube_image=${OVN_IMAGE}
if [ "$KIND_LOCAL_REGISTRY" == true ];then
# When updating with local registry we have to reference the sha
ovnkube_image=$(docker inspect --format='{{index .RepoDigests 0}}' $OVN_IMAGE)
fi
pushd ${DIR}/../dist/images
./daemonset.sh \
--output-directory="${MANIFEST_OUTPUT_DIR}"\
--image="${OVN_IMAGE}" \
--ovnkube-image="${ovnkube_image}" \
--net-cidr="${NET_CIDR}" \
--svc-cidr="${SVC_CIDR}" \
--gateway-mode="${OVN_GATEWAY_MODE}" \
Expand Down Expand Up @@ -768,8 +810,9 @@ install_ovn() {
run_kubectl apply -f ovnkube-node.yaml
popd

# Force pod reload just the ones with golang containers
if [ "${KIND_CREATE}" == false ]; then
# When using internal registry force pod reload just the ones with
# golang containers
if [ "${KIND_CREATE}" == false ] && [ "${KIND_LOCAL_REGISTRY}" == false ] ; then
for pod in ${OVN_DEPLOY_PODS}; do
run_kubectl delete pod -n ovn-kubernetes -l name=$pod
done
Expand Down
10 changes: 8 additions & 2 deletions dist/images/daemonset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ while [ "$1" != "" ]; do
--image)
OVN_IMAGE=$VALUE
;;
--ovnkube-image)
OVNKUBE_IMAGE=$VALUE
;;
--image-pull-policy)
OVN_IMAGE_PULL_POLICY=$VALUE
;;
Expand Down Expand Up @@ -291,6 +294,9 @@ echo "output_dir: $output_dir"
image=${OVN_IMAGE:-"docker.io/ovnkube/ovn-daemonset:latest"}
echo "image: ${image}"

ovnkube_image=${OVNKUBE_IMAGE:-${image}}
echo "ovnkube_image: ${ovnkube_image}"

image_pull_policy=${OVN_IMAGE_PULL_POLICY:-"IfNotPresent"}
echo "imagePullPolicy: ${image_pull_policy}"

Expand Down Expand Up @@ -406,7 +412,7 @@ echo "ovnkube_node_mgmt_port_netdev: ${ovnkube_node_mgmt_port_netdev}"
ovnkube_config_duration_enable=${OVNKUBE_CONFIG_DURATION_ENABLE}
echo "ovnkube_config_duration_enable: ${ovnkube_config_duration_enable}"

ovn_image=${image} \
ovn_image=${ovnkube_image} \
ovn_image_pull_policy=${image_pull_policy} \
ovn_unprivileged_mode=${ovn_unprivileged_mode} \
ovn_gateway_mode=${ovn_gateway_mode} \
Expand Down Expand Up @@ -478,7 +484,7 @@ ovn_image=${image} \
ovnkube_app_name=ovnkube-node-dpu-host \
j2 ../templates/ovnkube-node.yaml.j2 -o ${output_dir}/ovnkube-node-dpu-host.yaml

ovn_image=${image} \
ovn_image=${ovnkube_image} \
ovn_image_pull_policy=${image_pull_policy} \
ovnkube_master_loglevel=${master_loglevel} \
ovn_loglevel_northd=${ovn_loglevel_northd} \
Expand Down

0 comments on commit 63bb8e0

Please sign in to comment.