Skip to content

Commit

Permalink
Jenkins CI integration (#22)
Browse files Browse the repository at this point in the history
Jenkins CI integration and test fixes
  • Loading branch information
ashishshinde authored Nov 28, 2020
1 parent 2375a07 commit a288b93
Show file tree
Hide file tree
Showing 22 changed files with 394 additions and 154 deletions.
53 changes: 53 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pipeline {
agent any
tools {
go 'go-1.13.5'
}

environment {
GOPATH="/var/lib/jenkins/go"
GO_REPO_ROOT="${env.GOPATH}/src/github.com"
GO_REPO="${env.GO_REPO_ROOT}/aerospike-kubernetes-operator"
DOCKER_REGISTRY=""
OPERATOR_NAME = "aerospike-kubernetes-operator"
OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME = "${env.DOCKER_REGISTRY}aerospike/${env.OPERATOR_NAME}:candidate-${env.BRANCH_NAME}"
}

stages {
stage('Build') {
options {
lock('gopath-k8s-operator')
}

steps {
sh 'mkdir -p $GO_REPO_ROOT'
sh 'ln -sf ${WORKSPACE} ${GO_REPO}'

dir("${env.GO_REPO}") {
sh "rsync -aK ${env.WORKSPACE}/../../aerospike-kubernetes-operator-resources/secrets/ deploy/secrets"
// Changing directory again otherwise operator generates binary with the symlink name.
sh "cd ${GO_REPO} && operator-sdk build ${OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME}"
sh "docker push ${OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME}"
}
}
}

stage('Test') {
options {
lock('gke-k8s-cluster')
}

steps {
dir("${env.GO_REPO}") {
sh "./test/e2e/test.sh ${OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME}"
}
}
}
}

post {
always {
junit testResults: '**/build/test-results/**/*.xml', keepLongStdio: true
}
}
}
3 changes: 2 additions & 1 deletion build/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
_output/
_output/
test-results/
7 changes: 4 additions & 3 deletions deploy/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ metadata:
name: aerospike-cluster
namespace: aerospike

# # Uncomment below service accounts for deploying clusters in additional namespaces
# # Uncomment below service accounts for deploying clusters in additional namespaces
# ---
# # Service account used by the cluster pods to obtain pod metadata.
# apiVersion: v1
Expand Down Expand Up @@ -144,6 +144,7 @@ rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- services
verbs:
Expand All @@ -170,7 +171,7 @@ subjects:
- kind: ServiceAccount
name: aerospike-cluster
namespace: aerospike
# # Uncomment below subject entries for deploying clusters in additional namespaces
# # Uncomment below subject entries for deploying clusters in additional namespaces
# - kind: ServiceAccount
# name: aerospike-cluster
# namespace: aerospike1
Expand Down Expand Up @@ -224,4 +225,4 @@ subjects:
# subjects:
# - kind: ServiceAccount
# name: cass-operator
# namespace: aerospike2
# namespace: aerospike2
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ require (
github.com/go-openapi/spec v0.19.0
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/operator-framework/operator-sdk v0.12.1-0.20191113210304-dc4b52186933
github.com/stretchr/testify v1.3.0
github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef // indirect
github.com/travelaudience/aerospike-operator v0.0.0-20191002090530-354c1a4e7e2a
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/client-go v11.0.0+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jteeuwen/go-bindata v0.0.0-20151023091102-a0ff2567cfb7/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/aerospikecluster/controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ func (r *ReconcileAerospikeCluster) createStatefulSet(aeroCluster *aerospikev1al
newEnvVar("MY_HOST_IP", "status.hostIP"),
newEnvVarStatic("MY_POD_TLS_NAME", getServiceTLSName(aeroCluster)),
newEnvVarStatic("MY_POD_CLUSTER_NAME", aeroCluster.Name),
newEnvVarStatic("MY_POD_IMAGE", aeroCluster.Spec.Image),
}

if rackState.Rack.ID != utils.DefaultRackID {
envVarList = append(envVarList, newEnvVarStatic("MY_POD_RACK_ID", string(rackState.Rack.ID)))
envVarList = append(envVarList, newEnvVarStatic("MY_POD_RACK_ID", strconv.Itoa(rackState.Rack.ID)))
}

if name := getServiceTLSName(aeroCluster); name != "" {
Expand Down
8 changes: 7 additions & 1 deletion pkg/controller/configmap/configdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ fi
# Update pod status in the k8s aerospike cluster object
# ------------------------------------------------------------------------------
# Get pod image
POD_JSON="$(curl -f --cacert $CA_CERT -H "Authorization: Bearer $TOKEN" "$KUBE_API_SERVER/api/v1/namespaces/$NAMESPACE/pods/$MY_POD_NAME")"
export POD_IMAGE="$(echo $POD_JSON | python3 -c "import sys, json
data = json.load(sys.stdin)
print(data['spec']['containers'][0]['image'])")"
# Parse out cluster name, formatted as: petset_name-rackid-index
IFS='-' read -ra ADDR <<< "$(hostname)"
AERO_CLUSTER_NAME="${ADDR[0]}"
Expand Down Expand Up @@ -380,7 +386,7 @@ if 'MY_POD_TLS_ENABLED' in os.environ and "true" == os.environ['MY_POD_TLS_ENABL
servicePort = os.environ['MAPPED_TLSPORT']
value = {
'image': os.environ.get('MY_POD_IMAGE',''),
'image': os.environ.get('POD_IMAGE',''),
'podIP': os.environ.get('PODIP',''),
'hostInternalIP': os.environ.get('INTERNALIP',''),
'hostExternalIP': os.environ.get('EXTERNALIP',''),
Expand Down
32 changes: 22 additions & 10 deletions test/e2e/cleanup-test-namespace.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
#!/bin/bash

################################################
# Should be run from reposiroty root
#
# Cleans up all resources created by test runs.
#
################################################

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Delete Aeropsike clusters
kubectl -n test delete aerospikecluster --all
kubectl -n test1 delete aerospikecluster --all
kubectl -n test2 delete aerospikecluster --all
kubectl -n test3 delete aerospikecluster --all

# Delete Stateful Sets
kubectl -n test delete statefulset --selector 'app=aerospike-cluster'
kubectl delete -f test/e2e/setup_operator_test.yaml

# Delete PVCs
kubectl -n test delete pvc --selector 'app=aerospike-cluster'

# Delete the secrets
kubectl -n test delete secret --selector 'app=aerospike-cluster'
kubectl -n test delete secret --selector 'app=aerospike-cluster' || true

# Delete rbac accounts and auth
kubectl delete clusterrolebinding aerospike-cluster
kubectl delete clusterrole aerospike-cluster
kubectl -n test delete serviceaccount aerospike-cluster
kubectl -n test1 delete serviceaccount aerospike-cluster
kubectl -n test2 delete serviceaccount aerospike-cluster
kubectl delete clusterrolebinding aerospike-cluster || true
kubectl delete clusterrole aerospike-cluster || true
kubectl -n test delete serviceaccount aerospike-cluster || true
kubectl -n test1 delete serviceaccount aerospike-cluster || true
kubectl -n test2 delete serviceaccount aerospike-cluster || true

# Delete the operator deployment
kubectl -n test delete -f $DIR/setup_operator_test.yaml || true

# Delete namespaces
kubectl delete namespace test1
kubectl delete namespace test2
kubectl delete namespace test1 || true
kubectl delete namespace test2 || true
kubectl delete namespace test || true
Loading

0 comments on commit a288b93

Please sign in to comment.