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

feat: add option to enable delete operations on the registry #14

Merged
merged 1 commit into from
Jul 7, 2023
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
38 changes: 38 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,44 @@ jobs:
exit 1
fi

test-with-registry-with-delete-rights:
strategy:
matrix:
version:
- v0.17.0
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Create kind cluster with registry
uses: ./
with:
version: "${{ matrix.version }}"
registry_delete: true

- name: Test
run: |
kubectl cluster-info
kubectl get storageclass standard

# Checking env variable
if [[ "$KIND_REGISTRY" != "kind-registry:5000" ]]; then
echo "Wrong KIND_REGISTRY env variable: $KIND_REGISTRY"
exit 1
fi

# Test registry usage inside cluster
docker pull busybox
docker tag busybox kind-registry:5000/localbusybox

# Test delete API
OUTPUT=$(docker push kind-registry:5000/localbusybox | grep -o 'digest.*size')
TRIM=${OUTPUT//digest: /}
DIGEST=${TRIM// size/}
exit $(curl -X DELETE kind-registry:5000/v2/localbusybox/manifests/$DIGEST)

test-knative:
strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi
- `wait`: The duration to wait for the control plane to become ready (default: `60s`)
- `log_level`: The log level for KinD
- `registry`: Configures an insecure registry on `kind-registry:5000` to be used with KinD (default: `true`)
- `registry_delete`: Set to true to enable delete operations on the Image Registry (default is `false`)
- `kubectl_version`: The kubectl version to use (default: `v1.26.1`)
- `knative_serving`: The version of Knative Serving to install on the Kind cluster (not installed by default - example: `v1.0.0`)
- `knative_kourier`: The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: `v1.0.0`)
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ inputs:
description: "The log level for KinD"
registry:
description: "Configures an insecure registry on kind-registry:5000 to be used with KinD (default: true)"
registry_delete:
description: "Enables delete operations on the Image Registry (default is false)"
kubectl_version:
description: "The version of kubectl to use (default: v1.26.1)"
knative_serving:
Expand Down
5 changes: 5 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ main() {
args_registry+=(--memory "${INPUT_MEMORY}")
fi

if [[ -n "${INPUT_REGISTRY_DELETE:-}" ]]; then
args_registry+=(--registry-delete "${INPUT_REGISTRY_DELETE}")
fi


if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then
if [[ ${#args_registry[@]} -gt 0 ]]; then
"$SCRIPT_DIR/registry.sh" "${args_registry[@]}"
Expand Down
19 changes: 16 additions & 3 deletions registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Usage: $(basename "$0") <options>
--registry-image The registry image to use (default: $DEFAULT_REGISTRY_IMAGE)
--registry-name The registry name to use (default: $DEFAULT_REGISTRY_NAME)
--registry-port The local port used to bind the registry (default: $DEFAULT_REGISTRY_PORT)
--registry-delete Enable delete operations on the registry (default is false)
-n, --cluster-name The name of the cluster to create (default: $DEFAULT_CLUSTER_NAME)"
--document Document the local registry

Expand All @@ -45,6 +46,7 @@ main() {
local registry_image="$DEFAULT_REGISTRY_IMAGE"
local registry_name="$DEFAULT_REGISTRY_NAME"
local registry_port="$DEFAULT_REGISTRY_PORT"
local registry_delete="false"
local cluster_name="$DEFAULT_CLUSTER_NAME"
local cpu="$DEFAULT_CPU"
local disk="$DEFAULT_DISK"
Expand Down Expand Up @@ -132,6 +134,16 @@ parse_command_line() {
exit 1
fi
;;
--registry-delete)
if [[ -n "${2:-}" ]]; then
registry_delete="$2"
shift
else
echo "ERROR: '--registry-delete' cannot be empty." >&2
show_help
exit 1
fi
;;
-n|--cluster-name)
if [[ -n "${2:-}" ]]; then
cluster_name="$2"
Expand Down Expand Up @@ -170,9 +182,10 @@ install_docker() {
}

create_registry() {
echo "Creating registry \"$registry_name\" on port $registry_port from image \"$registry_image\"..."
docker run -d --restart=always -p "${registry_port}:5000" --name "${registry_name}" $registry_image > /dev/null

echo "Creating registry \"$registry_name\" on port $registry_port from image \"$registry_image\" with delete enabled $registry_delete ..."
docker run -d --restart=always -p "${registry_port}:5000" -e "REGISTRY_STORAGE_DELETE_ENABLED=${registry_delete}" --name "${registry_name}" $registry_image
> /dev/null

# Adding registry to /etc/hosts
echo "127.0.0.1 $registry_name" | sudo tee -a /etc/hosts

Expand Down