Skip to content

Modify setup.sh to delete cert-manager leases in E2E tests #4715

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

Closed
wants to merge 2 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions demo.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{"version": 2, "width": 120, "height": 30, "timestamp": 1742471351, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
[0.011902, "o", "\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u001b[00m$ "]
[3.948812, "o", "\r\n\u001b[?2004l\r"]
[3.949392, "o", "\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u001b[00m$ "]
[5.084461, "o", "\r\n\u001b[?2004l\r"]
[5.084761, "o", "\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u001b[00m$ "]
[9.575507, "o", "\u001b[?2004l\r\r\nexit\r\n"]
4 changes: 2 additions & 2 deletions designs/simplified-scaffolding.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ files, 6 are Kubebuilder-specific glue code, 4 are test setup, and
user-edited code.

This proliferation of files makes it difficult for users to understand how
their code relates to the library, posing some barrier for initial adoption
their code relates to the library, posing some barriers for initial adoption
and moving beyond a basic knowledge of functionality to actual
understanding of the structure. A common line of questioning amongst
newcomers to Kubebuilder includes "where should I put my code that adds
newcomers to Kubebuilder include "where should I put my code that adds
new types to a scheme" (and similar questions), which indicates that it's
not immediately obvious to these users why the project is structured the
way it is.
Expand Down
Empty file added pkg/mod/cache/lock
Empty file.
3 changes: 3 additions & 0 deletions scripts/demo/demo.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"version": 2, "width": 148, "height": 35, "timestamp": 1742463285, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
[0.015726, "o", "\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/scripts/demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/scripts/demo\u001b[00m$ "]
[11.406614, "o", "\u001b[?2004l\r\r\nexit\r\n"]
3 changes: 3 additions & 0 deletions scripts/demo/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module demo.kubebuilder.io

go 1.24.0
79 changes: 49 additions & 30 deletions scripts/demo/run.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,62 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

clear
. $(dirname ${BASH_SOURCE})/util.sh
# Determine the path to the Kubebuilder root directory
kubebuilder_root=$(git rev-parse --show-toplevel)

desc "Initialize Go modules"
run "go mod init demo.kubebuilder.io"
# Define the temporary directory
tmpdir="$kubebuilder_root/tmp-demo"

desc "Let's initialize the project"
run "kubebuilder init --domain tutorial.kubebuilder.io"
clear
# Remove the temporary directory if it exists
rm -rf -f "$tmpdir"

# Create the temporary directory
mkdir -p "$tmpdir"
echo "Creating temporary directory: $tmpdir"
cd "$tmpdir"

# Set GOPATH to the Kubebuilder root directory
export GOPATH="$kubebuilder_root"
export PATH="$PATH:$kubebuilder_root/bin"

# Source util.sh *before* starting Asciinema
# . "$kubebuilder_root/scripts/demo/util.sh"

# Start recording
asciinema rec --overwrite demo.cast

desc "Examine scaffolded files..."
run "tree ."
# Run the commands directly
echo "Initialize Go modules"
go mod init demo.kubebuilder.io

echo "Let's initialize the project"
kubebuilder init --domain tutorial.kubebuilder.io
clear

desc "Create our custom cronjob api"
run "kubebuilder create api --group batch --version v1 --kind CronJob"
echo "Examine scaffolded files..."
tree .
clear

desc "Let's take a look at the API and Controller files"
run "tree ./api ./internal/controller"
echo "Create our custom cronjob api"
kubebuilder create api --group batch --version v1 --kind CronJob
clear

desc "Install CRDs in Kubernetes cluster"
run "make install"
echo "Let's take a look at the API and Controller files"
tree ./api ./internal/controller
clear

desc "Run controller manager locally"
run "make run"
# Stop recording
echo "Recording finished. File saved as demo.cast"

# Copy the recording to the current directory
cp demo.cast "$kubebuilder_root/scripts/demo/demo.cast"

# Optionally upload to asciinema.org
# asciinema upload demo.cast

# Clean up the temporary directory
echo "Cleaning up temporary directory: $tmpdir"
cd "$kubebuilder_root/scripts/demo" # Go back to the original directory
rm -rf -f "$tmpdir"

echo "Asciinema recording saved to: scripts/demo/demo.cast"

93 changes: 27 additions & 66 deletions scripts/demo/util.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,83 +1,44 @@
#!/bin/bash
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is copied from @thockin's micro-demos repository:
# https://github.com/thockin/micro-demos/blob/master/util.sh

readonly reset=$(tput sgr0)
readonly green=$(tput bold; tput setaf 2)
# Color codes
readonly reset=$(tput sgr0)
readonly green=$(tput bold; tput setaf 2)
readonly yellow=$(tput bold; tput setaf 3)
readonly blue=$(tput bold; tput setaf 6)
readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
readonly blue=$(tput bold; tput setaf 6)
readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)

# Function to display descriptions
function desc() {
maybe_first_prompt
rate=25
if [ -n "$DEMO_RUN_FAST" ]; then
rate=1000
fi
echo "$blue# $@$reset" | pv -qL $rate
prompt
maybe_first_prompt
rate=25
if [ -n "$DEMO_RUN_FAST" ]; then
rate=1000
fi
echo "$blue# $@$reset" | pv -qL $rate
prompt
}

# Function to display prompt
function prompt() {
echo -n "$yellow\$ $reset"
echo -n "$yellow\$ $reset"
}

# Function to clear if not asciinema (Add this function)
function clear_if_not_asciinema() {
if ! $is_asciinema_running; then
clear
fi
}

started=""
function maybe_first_prompt() {
if [ -z "$started" ]; then
prompt
started=true
fi
if [ -z "$started" ]; then
prompt
started=true
fi
}

# After a `run` this variable will hold the stdout of the command that was run.
# If the command was interactive, this will likely be garbage.
# After a `run` this variable will hold the stdout of the command that was run
DEMO_RUN_STDOUT=""

function run() {
maybe_first_prompt
rate=25
if [ -n "$DEMO_RUN_FAST" ]; then
rate=1000
fi
echo "$green$1$reset" | pv -qL $rate
if [ -n "$DEMO_RUN_FAST" ]; then
sleep 0.5
fi
OFILE="$(mktemp -t $(basename $0).XXXXXX)"
if [ "$(uname)" == "Darwin" ]; then
script -q "$OFILE" $1
else
script -eq -c "$1" -f "$OFILE"
fi
r=$?
read -d '' -t "${timeout}" -n 10000 # clear stdin
prompt
if [ -z "$DEMO_AUTO_RUN" ]; then
read -s
fi
DEMO_RUN_STDOUT="$(tail -n +2 $OFILE | sed 's/\r//g')"
return $r
}

function relative() {
for arg; do
echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|"
done
}

trap "echo" EXIT
16 changes: 15 additions & 1 deletion test/e2e/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ function create_cluster {
# delete_cluster
function delete_cluster {
: ${KIND_CLUSTER:?"KIND_CLUSTER must be set"}
echo "Deleting cert-manager resources..."
kubectl delete --ignore-not-found=true -n kube-system deployment cert-manager-cainjector
kubectl delete --ignore-not-found=true -n kube-system deployment cert-manager-controller
kubectl delete --ignore-not-found=true -n kube-system deployment cert-manager-webhook

# Delete the cert-manager namespace itself (if it exists)
kubectl delete --ignore-not-found=true namespace cert-manager

# Delete Calico
echo "Deleting Calico..."
kubectl delete --ignore-not-found=true -f https://docs.projectcalico.org/manifests/calico.yaml

# Finally, delete the Kind cluster
echo "Deleting Kind cluster..."
kind delete cluster --name $KIND_CLUSTER
}

Expand All @@ -70,4 +84,4 @@ function test_cluster {
go test $(dirname "$0")/deployimage $flags -timeout 30m
go test $(dirname "$0")/v4 $flags -timeout 30m
go test $(dirname "$0")/alphagenerate $flags -timeout 30m
}
}
21 changes: 21 additions & 0 deletions tmp-demo/demo.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{"version": 2, "width": 148, "height": 35, "timestamp": 1742489499, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
[0.017399, "o", "\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u001b[00m$ "]
[268.627407, "o", "g"]
[268.802727, "o", "o"]
[269.063759, "o", " "]
[269.280452, "o", "v"]
[269.523229, "o", "e"]
[269.630183, "o", "r"]
[269.871157, "o", "s"]
[270.332394, "o", "i"]
[270.524995, "o", "o"]
[271.312465, "o", "n"]
[271.894893, "o", "\r\n\u001b[?2004l\r"]
[272.084343, "o", "go version go1.24.0 linux/amd64\r\n"]
[272.086449, "o", "\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u001b[00m$ "]
[281.098677, "o", "\u001b[7mecho $GOPATH\u001b[27m"]
[281.783162, "o", "\b\b\b\b\b\b\b\b\b\b\b\becho $GOPATH\r\n\u001b[?2004l\r/home/chethan/go\r\n\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u001b[00m$ "]
[290.07553, "o", "\u001b[7mecho $PATH\u001b[27m"]
[293.436667, "o", "\b\b\b\b\b\b\b\b\b\becho $PATH\r\n\u001b[?2004l\r"]
[293.436789, "o", "/home/chethan/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/MicrosoftCorporationII.WindowsSubsystemForLinux_2.4.12.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/Go/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Kubernetes/Minikube:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Users/HP/AppData/Local/Programs/Python/Launcher/:/mnt/c/Users/HP/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/HP/go/bin:/mnt/c/Users/HP/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/kubectl:/mnt/c/Users/HP/AppData/Local/Programs/Ollama:/snap/bin:/usr/local/go/bin:/usr/local/go/bin:/home/chethan/mygo/src/github.com/kubernetes-sigs/kubebuilder/bin:/usr/local/go/bin:/home/chethan/mygo/src/github.com/kubernetes-sigs/kubebuilder/bin:/home/chethan/mygo/src/github.com/kubernetes-sigs/kubebuilder/bin:/usr/local/go/bin:/home/chethan/mygo/src/github.com/kubernetes-sigs/kubebuilder/bin:/home/chethan/mygo/src/github.com/kubernetes-sigs/kubebuilder/bin:/usr/local/go/bin:/home/chethan/mygo/src/github.com/kubernetes-sigs/kubebuilder/bin:/usr/local/go/bin\r\n"]
[293.436994, "o", "\u001b[?2004h\u001b]0;chethan@chethan: ~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u0007\u001b[01;32mchethan@chethan\u001b[00m:\u001b[01;34m~/mygo/src/github.com/kubernetes-sigs/kubebuilder/tmp-demo\u001b[00m$ "]
26 changes: 26 additions & 0 deletions vendor/github.com/go-logr/logr/.golangci.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/go-logr/logr/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions vendor/github.com/go-logr/logr/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading