This is an automated email from the ASF dual-hosted git repository.

rantunes pushed a commit to branch kie-issues_755
in repository 
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-operator.git


The following commit(s) were added to refs/heads/kie-issues_755 by this push:
     new 4a93a700 Setup minikube
4a93a700 is described below

commit 4a93a700db6c7749f874e656f59663ab0683e631
Author: Rodrigo Antunes <[email protected]>
AuthorDate: Tue Jan 9 15:45:12 2024 -0300

    Setup minikube
---
 .ci/jenkins/Jenkinsfile.deploy      |  15 ++++-
 .ci/jenkins/scripts/helper.groovy   |   2 +
 .ci/jenkins/scripts/minikube.groovy | 121 ++++++++++++++++++++++++++++++++++++
 hack/ci/install-minikube.sh         |  59 ++++++++++++++++++
 hack/kube-utils.sh                  |  37 +++++++++++
 5 files changed, 233 insertions(+), 1 deletion(-)

diff --git a/.ci/jenkins/Jenkinsfile.deploy b/.ci/jenkins/Jenkinsfile.deploy
index fe458914..f5c1d174 100644
--- a/.ci/jenkins/Jenkinsfile.deploy
+++ b/.ci/jenkins/Jenkinsfile.deploy
@@ -114,7 +114,10 @@ pipeline {
                 }
             }
             steps {
-                sh 'make test'
+                script {
+                    setupMinikube()
+                    sh 'make test'
+                }
             }
             post {
                 unsuccessful {
@@ -353,3 +356,13 @@ String getBDDParameters() {
     echo "BDD parameters = ${testParams}"
     return testParams
 }
+
+
+void setupMinikube() {
+    // Start minikube
+    minikube.minikubeMemory = '12g'
+    minikube.start()
+
+    minikube.waitForMinikubeStarted()
+    minikube.waitForMinikubeRegistry()
+}
diff --git a/.ci/jenkins/scripts/helper.groovy 
b/.ci/jenkins/scripts/helper.groovy
index afade057..7eec2362 100644
--- a/.ci/jenkins/scripts/helper.groovy
+++ b/.ci/jenkins/scripts/helper.groovy
@@ -36,6 +36,8 @@ void initPipeline() {
     container.containerEngine = env.CONTAINER_ENGINE ?: 'docker'
     container.containerTlsOptions = env.CONTAINER_ENGINE_TLS_OPTIONS ?: ''
     container.containerOpenshift = openshift
+
+    minikube = load '.ci/jenkins/scripts/minikube.groovy'
 }
 
 void updateDisplayName() {
diff --git a/.ci/jenkins/scripts/minikube.groovy 
b/.ci/jenkins/scripts/minikube.groovy
new file mode 100644
index 00000000..1b921db4
--- /dev/null
+++ b/.ci/jenkins/scripts/minikube.groovy
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+minikubeVersion = env.MINIKUBE_VERSION ?: '1.30.1'
+minikubeKubernetesVersion = env.KUBERNETES_VERSION ?: '1.26.3'
+minikubeContainerEngine = env.CONTAINER_ENGINE ?: 'docker'
+
+minikubeCpus = 'max'
+minikubeMemory = '4g'
+minikubeAddons = [ 'registry', 'metrics-server' ]
+minikubeRegistryMirror = env.DOCKER_REGISTRY_MIRROR ?: ''
+minikubeInsecureRegistries = []
+
+void start(boolean debug = false) {
+    preChecks()
+
+    def minikubeOpts = [
+        "--driver=${minikubeContainerEngine}",
+        "--kubernetes-version ${minikubeKubernetesVersion}",
+        "--cpus ${minikubeCpus}",
+        "--memory ${minikubeMemory}",
+        // Default insecure registries added
+        '--insecure-registry "192.168.0.0/16"',
+        '--insecure-registry "localhost:5000"',
+    ]
+    minikubeOpts.addAll(minikubeAddons.collect { "--addons ${it}" })
+    minikubeOpts.addAll(minikubeInsecureRegistries.collect { 
"--insecure-registry '${it}'" })
+    if (minikubeRegistryMirror) {
+        minikubeOpts.addAll([
+            "--registry-mirror http://${minikubeRegistryMirror}";,
+            "--insecure-registry ${minikubeRegistryMirror}",
+        ])
+    }
+
+    println "Start minikube with options ${minikubeOpts}"
+    sh """
+        minikube delete
+        minikube start ${minikubeOpts.join(' ')}
+        minikube status
+
+        kubectl version
+        kubectl get pods -A
+    """
+
+    if (debug) {
+        sh 'kubectl get events -n kube-system'
+    }
+}
+
+void waitForMinikubeStarted() {
+    println 'Wait for Minikube components to be in Running state'
+    def minikubeStatus = sh(returnStatus: true, script: '''
+        set -x
+        source ./hack/kube-utils.sh
+        MINIKUBE_COMPONENTS=(etcd kube-apiserver kube-controller-manager 
kube-scheduler)
+        for component in "${MINIKUBE_COMPONENTS[@]}"
+        do
+            echo "Check component '${component}' is in 'Running' state"
+            waitKubeSystemForPodReady "-l tier=control-plane -l 
component=${component}"
+        done
+
+        echo "Check kube-dns is in 'Running' state"
+        waitKubeSystemForPodReady "-l k8s-app=kube-dns"
+    ''')
+    if (minikubeStatus != 0) {
+        error 'Error starting Minikube ...'
+    }
+}
+
+void waitForMinikubeRegistry() {
+    println 'Wait for Minikube registry to be in Running state'
+    def minikubeStatus = sh(returnStatus: true, script: '''
+        set -x
+        kubectl get pods -A
+        source ./hack/kube-utils.sh
+        waitKubeSystemForPodReady "-l kubernetes.io/minikube-addons=registry 
-l actual-registry=true"
+    ''')
+    if (minikubeStatus != 0) {
+        error 'Error waiting for Minikube registry ...'
+    }
+}
+
+void preChecks() {
+    sh """
+        ${minikubeContainerEngine} info
+
+        if [[ ! \$(command -v minikube) ]]; then
+            sudo ./hack/ci/install-minikube.sh /usr/local/bin
+            sudo chmod +x /usr/local/bin/minikube
+        fi
+    """
+}
+
+void stop() {
+    if (sh(returnStatus: true, script: 'which minikube') == 0) {
+        sh '''
+            minikube delete
+        '''
+    }
+}
+
+String getImageRegistry() {
+    return sh(returnStdout: true, script: 'echo "$(minikube ip):5000"').trim()
+}
+
+return this
diff --git a/hack/ci/install-minikube.sh b/hack/ci/install-minikube.sh
new file mode 100755
index 00000000..9a1e1844
--- /dev/null
+++ b/hack/ci/install-minikube.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+set -e
+
+install_path=$1
+default_minikube_version=v1.31.1
+
+if [[ -z ${MINIKUBE_VERSION} ]]; then
+  MINIKUBE_VERSION=$default_minikube_version
+fi
+
+download_path="${HOME}/.minikube/download/"
+
+echo "---> Minikube version to install is ${MINIKUBE_VERSION}"
+
+# get the arch and os
+arch=$(uname -m)
+case $(uname -m) in
+"x86_64") arch="amd64" ;;
+"aarch64") arch="arm64" ;;
+esac
+os=$(uname | awk '{print tolower($0)}')
+
+if [ -e "${download_path}/minikube-${os}-${arch}" ]; then
+  echo "---> Minikube ${MINIKUBE_VERSION} (OS ${os} Architecture ${arch}) 
already exists in '${download_path}', skipping downloading"
+else
+  mkdir -p "${download_path}"
+  cd "${download_path}"
+  echo "---> Downloading minikube ${MINIKUBE_VERSION} (OS ${os} Architecture 
${arch}) to ${download_path}"
+  curl -LO 
"https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/minikube-${os}-${arch}";
+  cd -
+fi
+
+if [ -z "${install_path}" ]; then
+  install_path="${HOME}/runner/bin"
+  [[ "${os}" == "darwin" ]]; install_path="${HOME}/runner/bin"
+fi
+
+echo "---> Ensuring minikube installation at ${install_path}"
+
+mkdir -p "${install_path}"
+chmod +x "${install_path}"
+cp "${download_path}/minikube-${os}-${arch}" "${install_path}/minikube"
diff --git a/hack/kube-utils.sh b/hack/kube-utils.sh
new file mode 100755
index 00000000..32fbf005
--- /dev/null
+++ b/hack/kube-utils.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+getKubeSystemPodStatusConditions() { 
+  kubectl get pods $1 -n kube-system -o json | jq 
'.items[].status.conditions[]'
+}
+
+getKubeSystemPodReadyStatus() { 
+  echo $(kubectl get pods $1 -n kube-system -o json | jq -r 
'.items[].status.conditions[] | select(.type == "Ready") | .status') 
+}
+
+waitKubeSystemForPodReady() {
+  local selector=${1}
+  local timeout_time=${2:-60s}
+
+  export -f getKubeSystemPodStatusConditions
+  export -f getKubeSystemPodReadyStatus
+
+  echo "Wait for Kube System pod with selector '${selector}' and timeout 
${timeout_time}"
+
+  timeout ${timeout_time} bash -c "getKubeSystemPodStatusConditions 
'${selector}' && while [[ \"$(getKubeSystemPodReadyStatus "${selector}")\" != 
"True" ]] ; do sleep 2 && getKubeSystemPodStatusConditions '${selector}'; done"
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to