Skip to content

Commit

Permalink
Merge pull request #1 from thelastpickle/mck/license-defaults-precond…
Browse files Browse the repository at this point in the history
…itions-namespace-teardown/infracloud/infracloud/cassandra-5.0

SQUASH – Add license, defaults, preconditions, namespace, teardown
  • Loading branch information
richamishra006 authored Oct 11, 2023
2 parents 3f99f2f + f1775f9 commit d98613e
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions .build/run-ci.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
#!/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.
#

# variables, with defaults
[ "x${CASSANDRA_DIR}" != "x" ] || CASSANDRA_DIR="$(readlink -f $(dirname "$0")/..)"
[ "x${KUBECONFIG}" != "x" ] || KUBECONFIG="${HOME}/.kube/config"
[ "x${KUBE_NS}" != "x" ] || KUBE_NS="default" # FIXME – doesn't work in other namespaces :shrug:

# pre-conditions
command -v kubectl >/dev/null 2>&1 || { echo >&2 "kubectl needs to be installed"; exit 1; }
command -v helm >/dev/null 2>&1 || { echo >&2 "helm needs to be installed"; exit 1; }

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
Expand All @@ -10,6 +36,7 @@ while [[ $# -gt 0 ]]; do
shift # This is an additional shift to move to the argument after the option value.
;;
-ctx|--kubecontext)
unset KUBECONFIG
KUBECONTEXT="$2" # This sets the KUBECONTEXT variable to the next argument.
shift # This shifts the arguments to the left, discarding the current argument and moving to the next one.
shift # This is an additional shift to move to the argument after the option value.
Expand All @@ -35,38 +62,35 @@ if [ -n "$KUBECONTEXT" ]; then
kubectl config use-context "$KUBECONTEXT"
fi

# Install Helm

# Check if Helm is already installed
if ! command -v helm &>/dev/null; then
echo "Helm not found. Installing Helm..."
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 # enhance without downloading the script
chmod 700 get_helm.sh
./get_helm.sh
else
echo "Helm is already installed."
if ! kubectl get namespace ${KUBE_NS} >/dev/null 2>/dev/null ; then
kubectl create namespace ${KUBE_NS}
fi

# Add Helm Jenkins Operator repository
echo "Adding Helm repository for Jenkins Operator..."
helm repo add jenkins https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/chart
helm repo add --namespace ${KUBE_NS} jenkins https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/chart

# Install Jenkins Operator using Helm
echo "Installing Jenkins Operator..."
helm upgrade --install jenkins-operator jenkins/jenkins-operator --set jenkins.enabled=false --set jenkins.backup.enabled=false --version 0.8.0-beta.2
helm upgrade --namespace ${KUBE_NS} --install jenkins-operator jenkins/jenkins-operator --set jenkins.enabled=false --set jenkins.backup.enabled=false --version 0.8.0-beta.2

echo "Jenkins Operator installed successfully!" # condition to check if above command was success

# deploy jenkins Instance TODO jenkins file parameter
kubectl apply -f jenkins-deployment.yaml
kubectl apply --namespace ${KUBE_NS} -f ${CASSANDRA_DIR}/.build/jenkins-deployment.yaml

# TODO wait for job pods
#kubectl rollout wait pod/ [--for=<condition>]
#kubectl rollout --namespace ${KUBE_NS} wait pod/ [--for=<condition>]

#sleep 120

# get job pod name - TODO parametrise the job name
#jobPodName=$(kubectl get po | grep k8sagent-e2e | cut -d " " -f1)
# get job pod name - TODO parameterise the job name
#jobPodName=$(kubectl --namespace ${KUBE_NS} get po | grep k8sagent-e2e | cut -d " " -f1)

# get the file - TODO parameterize the path to fetch path
#kubectl exec -n default $jobPodName -- tar cf - /home/jenkins/agent/workspace/k8s-e2e | tar xf - -C .
#kubectl exec --namespace ${KUBE_NS} $jobPodName -- tar cf - /home/jenkins/agent/workspace/k8s-e2e | tar xf - -C .

# teardown # TODO add option to skip teardown
#kubectl delete --namespace ${KUBE_NS} -f ${CASSANDRA_DIR}/.build/jenkins-deployment.yaml
#kubectl delete "$(kubectl api-resources --namespaced=true --verbs=delete -o name | tr "\n" "," | sed -e 's/,$//')" --all
#kubectl delete namespace ${KUBE_NS}

0 comments on commit d98613e

Please sign in to comment.