From 51d4443cc5388c98500d5b1520ed2457b3682da9 Mon Sep 17 00:00:00 2001 From: Arvind Patel Date: Tue, 19 May 2020 17:45:17 +0530 Subject: [PATCH] VerifyPods and verifyk8scluster file commited Change-Id: I6b671a6f585ab9c92c1c5db68c4144325ea21a17 --- ci/daily build/csit/verifyPods.sh | 53 +++++++++++++++++++++++++++++++++ ci/daily build/csit/verifyk8Cluster.sh | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 ci/daily build/csit/verifyPods.sh create mode 100644 ci/daily build/csit/verifyk8Cluster.sh diff --git a/ci/daily build/csit/verifyPods.sh b/ci/daily build/csit/verifyPods.sh new file mode 100644 index 0000000..788e729 --- /dev/null +++ b/ci/daily build/csit/verifyPods.sh @@ -0,0 +1,53 @@ +#!/bin/bash -ex +############################################################################## +# Copyright (c) 2019 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +KUBERNETES=~/testk8s-kubernetes.yaml + +cat < "${KUBERNETES}" +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: kubernets-deployment + labels: + app: nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.15.12 + ports: + - containerPort: 80 + hostPort: 80 +EOF + +#check if kubernetes is already running +if ! kubectl cluster-info ; then + kubectl create -f ~/testk8s-kubernetes.yaml +fi + +#To check the pods which is not running +if kubectl get pods | grep -c -e STATUS -e Running > 0; then +PODS_NOT_RUNNING=$(kubectl get pods --field-selector=status.phase!=Running) +fi + +echo "-------------------------------------------------------------------" +echo +echo $PODS_NOT_RUNNING > /dev/null 2>&1 +echo +echo "-------------------------------------------------------------------" diff --git a/ci/daily build/csit/verifyk8Cluster.sh b/ci/daily build/csit/verifyk8Cluster.sh new file mode 100644 index 0000000..b8bd3d2 --- /dev/null +++ b/ci/daily build/csit/verifyk8Cluster.sh @@ -0,0 +1,54 @@ +#!/bin/bash -ex +############################################################################## +# Copyright (c) 2019 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +KUBERNETES=~/testk8s-kubernetes.yaml + +cat < "${KUBERNETES}" +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: kubernets-deployment + labels: + app: nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.15.12 + ports: + - containerPort: 80 + hostPort: 80 +EOF + +#check if kubernetes is already running +if ! kubectl cluster-info ; then + kubectl create -f ~/testk8s-kubernetes.yaml +fi + +#To check whether the kubernetes has started successfully +retry=10 +while [ $retry -gt 0 ] +do + if [ 2 == "$(kubectl get pods | grep -c -e STATUS -e Running)" ]; then + break + fi + ((retry-=1)) + sleep 10 +done +[ $retry -gt 0 ] || exit 1 -- 2.16.6