Skip to content

Commit

Permalink
kso-issue-376: Redo the setup with make
Browse files Browse the repository at this point in the history
  • Loading branch information
domhanak committed Feb 6, 2024
1 parent c0dc08c commit 5cc5676
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 134 deletions.
9 changes: 6 additions & 3 deletions .ci/jenkins/Jenkinsfile.e2e.cluster
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pipeline {
cleanup {
script {
clean()
deleteKindCluster()
}
}
}
Expand All @@ -138,7 +139,6 @@ pipeline {
void clean() {
helper.cleanGoPath()
util.cleanNode(containerEngine)
cleanupCluster()
}

String getTestImage() {
Expand All @@ -156,9 +156,11 @@ String getOperatorVersion() {
void setupCluster() {
switch (getClusterName()) {
case kindClusterPlatform:
echo 'Creating kind cluster'
createKindCluster()
break
case openshiftClusterPlatform:
echo 'Setting up Openshift'
setupOpenshift()
break
default:
Expand All @@ -167,11 +169,11 @@ void setupCluster() {
}

void createKindCluster() {
sh(script: "make create-cluster", returnStdout: true).trim()
sh(script: "make KIND_VERSION=${KIND_VERSION} create-cluster", returnStdout: true)
}

void deleteKindCluster() {
sh(script: "make delete-cluster", returnStdout: true).trim()
sh(script: "make delete-cluster", returnStdout: true)
}

void setupOpenshift() {
Expand All @@ -182,6 +184,7 @@ void setupOpenshift() {
void cleanupCluster() {
switch (getClusterName()) {
case kindClusterPlatform:
echo 'Deleting kind cluster'
deleteKindCluster()
break
case openshiftClusterPlatform:
Expand Down
131 changes: 0 additions & 131 deletions .ci/jenkins/scripts/kind.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,137 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
kindVersion = env.KIND_VERSION ?: 'v0.20.0'
kindRegistryName = "kind-registry"
kindRegistryPort = "5001"

void installKind() {
println "Install kind using go install"
sh(script: "command -v kind >/dev/null || go install sigs.k8s.io/kind@${KIND_VERSION}", returnStdout: true)
sh(script: "kind version", returnStdout: true)
}

void start(boolean debug = false) {
def installKindStatus = installKind()
if (installKindStatus != 0) {
error 'Unable to install kind'
}

println "Create kind cluster with containerd registry config dir enabled."
def createKindClusterStatus = sh(returnStatus: true, script: """
cat <<EOF | kind create cluster -n kind --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
EOF
""")

if (debug) {
sh 'kubectl get events -n kube-system'
}

if (createKindClusterStatus != 0) {
error 'Error while creaing kind cluster'
}
}

void waitUntilKubeSystemPodsAreStarted() {
println 'Wait for kube system pods to be in Running state'
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 ...'
}
}

void createRegistryContainer() {
println 'Create container registry container'
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 ...'
}
}

void connectRegistryContainerToClusterNetwork() {
println 'Connect registry container to cluster network'
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 ...'
}
}

void addRegistryConfigToTheClusterNodes() {
println 'Add registry config to cluster nodes'
def addRegistryConfigStatus = sh(returnStatus: true, script: """
export IP_ADDRESS=\$(docker inspect --format='{{(index (index .NetworkSettings.Networks "kind") ).IPAddress}}' ${kindRegistryName})
export REGISTRY_DIR="/etc/containerd/certs.d/${IP_ADDRESS}:5000"
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://${IP_ADDRESS}:5000"]
capabilities = ["pull", "resolve", "push"]
skip_verify = true
EOF
done
""")

if (addRegistryConfigStatus != 0) {
error 'Error while adding registry config to the cluster nodes ...'
}
}

void documentLocalRegistry() {
println 'Document created local registry'
def documentLocalRegistryStatus = sh(returnStatus: true, script: """
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
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 ...'
}
}

void stop() {
println 'Stopping kind cluster'
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}"
Expand Down

0 comments on commit 5cc5676

Please sign in to comment.