Skip to content

Commit

Permalink
kso-issues-376: Fix qoutes and add teardown with logs
Browse files Browse the repository at this point in the history
  • Loading branch information
domhanak committed Feb 5, 2024
1 parent 850a447 commit 6d117aa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .ci/jenkins/Jenkinsfile.e2e.cluster
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ helper = null
kindClusterPlatform = 'kind'
openshiftClusterPlatform = 'openshift'

kindLogsFolder = "/tmp/kind-logs"

pipeline {
agent {
docker {
Expand Down Expand Up @@ -108,6 +110,7 @@ pipeline {
make test-e2e
"""
} catch (err) {
kind.exportLogs("/tmp/kind-logs")
sh 'make undeploy'
throw err
}
Expand All @@ -118,6 +121,11 @@ pipeline {
}
}
post {
always {
script {
archiveArtifacts(artifacts: "**/tmp/kind-logs/")
}
}
cleanup {
script {
clean()
Expand Down
36 changes: 24 additions & 12 deletions .ci/jenkins/scripts/kind.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ void start(boolean debug = false) {

void waitUntilKubeSystemPodsAreStarted() {
println 'Wait for kube system pods to be in Running state'
def kindStatus = sh(returnStatus: true, script: '''
def kindStatus = sh(returnStatus: true, script: """
if ! kubectl wait -n kube-system --for=condition=ready pods --all --timeout=120s ; then
echo "some pods in the system are not running"
kubectl get pods -A -o wide || true
exit 1
fi
''')
""")

if (kindStatus != 0) {
error 'Error starting Kind ...'
Expand All @@ -55,12 +55,12 @@ void waitUntilKubeSystemPodsAreStarted() {

void createRegistryContainer() {
println 'Create container registry container'
def containerRegistryStatus = sh(returnStatus: true, script: '''
def containerRegistryStatus = sh(returnStatus: true, script: """
docker run \
-d --restart=always -p "127.0.0.1:${kindRegistryPort}:5000" --network bridge --name "${kindRegistryName}" \
-v /tmp/certs:/certs \
registry:2
''')
""")

if (containerRegistryStatus != 0) {
error 'Error while creating registry container ...'
Expand All @@ -69,11 +69,11 @@ void createRegistryContainer() {

void connectRegistryContainerToClusterNetwork() {
println 'Connect registry container to cluster network'
def containerRegistryConnectionStatus = sh(returnStatus: true, script: '''
def containerRegistryConnectionStatus = sh(returnStatus: true, script: """
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${kindRegistryName}")" = 'null' ]; then
docker network connect "kind" "${kindRegistryName}"
fi
''')
""")

if (containerRegistryConnectionStatus != 0) {
error 'Error while connecting registry container to the cluster ...'
Expand All @@ -82,7 +82,7 @@ void connectRegistryContainerToClusterNetwork() {

void addRegistryConfigToTheClusterNodes() {
println 'Add registry config to cluster nodes'
def addRegistryConfigStatus = sh(returnStatus: true, script: '''
def addRegistryConfigStatus = sh(returnStatus: true, script: """
export REGISTRY_DIR="/etc/containerd/certs.d/172.18.0.3:5000"
export IP_ADDRESS=$(docker inspect --format='{{(index (index .NetworkSettings.Networks "kind") ).IPAddress}}' ${kindRegistryName})
Expand All @@ -94,7 +94,7 @@ void addRegistryConfigToTheClusterNodes() {
skip_verify = true
EOF
done
''')
""")

if (addRegistryConfigStatus != 0) {
error 'Error while adding registry config to the cluster nodes ...'
Expand All @@ -103,7 +103,7 @@ void addRegistryConfigToTheClusterNodes() {

void documentLocalRegistry() {
println 'Document created local registry'
def documentLocalRegistryStatus = sh(returnStatus: true, script: '''
def documentLocalRegistryStatus = sh(returnStatus: true, script: """
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
Expand All @@ -115,7 +115,7 @@ void documentLocalRegistry() {
hostFromClusterNetwork: "${IP_ADDRESS}:5000"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF
''')
""")

if (documentLocalRegistryStatus != 0) {
error 'Error while adding registry config to the cluster nodes ...'
Expand All @@ -124,9 +124,21 @@ void documentLocalRegistry() {

void stop() {
println 'Stopping kind cluster'
def documentLocalRegistryStatus = sh(returnStatus: true, script: '''
def deleteKindClusterStatus = sh(returnStatus: true, script: """
kind delete cluster
''')
""")

if (deleteKindClusterStatus != 0) {
error 'Error while deleting kind cluster ...'
}
}

void exportLogs(String destination) {
println "Exporting kind logs to ${destination}"
def exportKindLogs = sh(returnStatus: true, script: """
mkdir -p .${destination}
kind export logs --loglevel=debug .${destination}
""")
}

void loadImage(String imageName) {
Expand Down

0 comments on commit 6d117aa

Please sign in to comment.