Skip to content

Commit

Permalink
Add basic Strimzi pom.xml file with the usual plugins, checkstyle, et…
Browse files Browse the repository at this point in the history
…c. (#10)

Signed-off-by: Jakub Scholz <[email protected]>
  • Loading branch information
scholzj authored Feb 6, 2024
1 parent d7cb8ad commit 9b8756d
Show file tree
Hide file tree
Showing 15 changed files with 674 additions and 53 deletions.
63 changes: 63 additions & 0 deletions .azure/build-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Triggers
trigger:
branches:
include:
- 'main'
- 'release-*'
tags:
include:
- '*'
pr:
autoCancel: true
branches:
include:
- '*'
# Jobs
jobs:
- job: 'build_and_test'
displayName: 'Build & Test'
# Strategy for the job
strategy:
matrix:
'java-11':
jdk_version: '11'
'java-17':
jdk_version: '17'
# Set timeout for jobs
timeoutInMinutes: 60
# Base system
pool:
vmImage: Ubuntu-22.04
# Variables
variables:
MVN_CACHE_FOLDER: $(HOME)/.m2/repository
MVN_ARGS: '-e -V -B'
# Pipeline steps
steps:
- task: Cache@2
inputs:
key: 'maven-cache | $(System.JobName) | **/pom.xml'
restoreKeys: |
maven-cache | $(System.JobName)
maven-cache
path: $(HOME)/.m2/repository
displayName: Maven cache
- template: 'templates/setup_java.yaml'
parameters:
JDK_VERSION: $(jdk_version)
- template: 'templates/setup_minikube.yaml'
- bash: ".azure/scripts/build.sh"
env:
BUILD_REASON: $(Build.Reason)
BRANCH: $(Build.SourceBranch)
GPG_PASSPHRASE: $(GPG_PASSPHRASE)
GPG_SIGNING_KEY: $(GPG_SIGNING_KEY)
NEXUS_USERNAME: $(NEXUS_USERNAME)
NEXUS_PASSWORD: $(NEXUS_PASSWORD)
displayName: "Build and test"
- task: PublishTestResults@2
inputs:
testResultsFormat: JUnit
testResultsFiles: '**/TEST-*.xml'
testRunTitle: "Unit & Integration tests"
condition: always()
31 changes: 31 additions & 0 deletions .azure/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -e

echo "Build reason: ${BUILD_REASON}"
echo "Source branch: ${BRANCH}"

# The first segment of the version number is '1' for releases < 9; then '9', '10', '11', ...
JAVA_MAJOR_VERSION=$(java -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
if [ "${JAVA_MAJOR_VERSION}" -eq "11" ] ; then
# some parts of the workflow should be done only one on the main build which is currently Java 11
export MAIN_BUILD="TRUE"
echo "Running main build"
fi

# Build with Maven
# shellcheck disable=SC2086
mvn $MVN_ARGS install
# shellcheck disable=SC2086
mvn $MVN_ARGS spotbugs:check

# Push to Nexus
if [ "$BUILD_REASON" == "PullRequest" ] ; then
echo "Building Pull Request - nothing to push"
elif [[ "$BRANCH" != "refs/tags/"* ]] && [ "$BRANCH" != "refs/heads/main" ]; then
echo "Not in main branch or in release tag - nothing to push"
else
if [ "${MAIN_BUILD}" = "TRUE" ] ; then
echo "In main branch or in release tag - pushing to nexus"
./.azure/scripts/push-to-nexus.sh
fi
fi
12 changes: 12 additions & 0 deletions .azure/scripts/push-to-nexus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

export GPG_TTY=$(tty)

echo $GPG_SIGNING_KEY | base64 -d > signing.gpg
gpg --batch --import signing.gpg

GPG_EXECUTABLE=gpg mvn $MVN_ARGS -DskipTests -s ./.azure/scripts/settings.xml -P ossrh verify deploy

rm -rf signing.gpg
gpg --delete-keys
gpg --delete-secret-keys
9 changes: 9 additions & 0 deletions .azure/scripts/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
<servers>
<server>
<id>ossrh</id>
<username>${env.NEXUS_USERNAME}</username>
<password>${env.NEXUS_PASSWORD}</password>
</server>
</servers>
</settings>
104 changes: 104 additions & 0 deletions .azure/scripts/setup-kubernetes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
set -xe

rm -rf ~/.kube

KUBE_VERSION=${KUBE_VERSION:-1.16.0}
COPY_DOCKER_LOGIN=${COPY_DOCKER_LOGIN:-"false"}

DEFAULT_MINIKUBE_MEMORY=$(free -m | grep "Mem" | awk '{print $2}')
DEFAULT_MINIKUBE_CPU=$(awk '$1~/cpu[0-9]/{usage=($2+$4)*100/($2+$4+$5); print $1": "usage"%"}' /proc/stat | wc -l)

MINIKUBE_MEMORY=${MINIKUBE_MEMORY:-$DEFAULT_MINIKUBE_MEMORY}
MINIKUBE_CPU=${MINIKUBE_CPU:-$DEFAULT_MINIKUBE_CPU}

echo "[INFO] MINIKUBE_MEMORY: ${MINIKUBE_MEMORY}"
echo "[INFO] MINIKUBE_CPU: ${MINIKUBE_CPU}"

function install_kubectl {
if [ "${KUBECTL_VERSION:-latest}" = "latest" ]; then
KUBECTL_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
fi
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl && chmod +x kubectl
sudo cp kubectl /usr/local/bin
}

function install_nsenter {
# Pre-req for helm
curl https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v${NSENTER_VERSION}/util-linux-${NSENTER_VERSION}.tar.gz -k | tar -zxf-
cd util-linux-${NSENTER_VERSION}
./configure --without-ncurses
make nsenter
sudo cp nsenter /usr/bin
}

function label_node {
# It should work for all clusters
for nodeName in $(kubectl get nodes -o custom-columns=:.metadata.name --no-headers);
do
echo ${nodeName};
kubectl label node ${nodeName} rack-key=zone;
done
}

if [ "$KUBE_CLUSTER" = "minikube" ]; then
install_kubectl
if [ "${MINIKUBE_VERSION:-latest}" = "latest" ]; then
MINIKUBE_URL=https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
else
MINIKUBE_URL=https://github.com/kubernetes/minikube/releases/download/${MINIKUBE_VERSION}/minikube-linux-amd64
fi

if [ "$KUBE_VERSION" != "latest" ] && [ "$KUBE_VERSION" != "stable" ]; then
KUBE_VERSION="v${KUBE_VERSION}"
fi

curl -Lo minikube ${MINIKUBE_URL} && chmod +x minikube
sudo cp minikube /usr/bin

export MINIKUBE_WANTUPDATENOTIFICATION=false
export MINIKUBE_WANTREPORTERRORPROMPT=false
export MINIKUBE_HOME=$HOME
export CHANGE_MINIKUBE_NONE_USER=true

mkdir $HOME/.kube || true
touch $HOME/.kube/config

docker run -d -p 5000:5000 registry

export KUBECONFIG=$HOME/.kube/config
# We can turn on network polices support by adding the following options --network-plugin=cni --cni=calico
# We have to allow trafic for ITS when NPs are turned on
# We can allow NP after Strimzi#4092 which should fix some issues on STs side
minikube start --vm-driver=docker --kubernetes-version=${KUBE_VERSION} \
--insecure-registry=localhost:5000 --extra-config=apiserver.authorization-mode=Node,RBAC \
--cpus=${MINIKUBE_CPU} --memory=${MINIKUBE_MEMORY}

if [ $? -ne 0 ]
then
echo "Minikube failed to start or RBAC could not be properly set up"
exit 1
fi

minikube addons enable default-storageclass

# Add Docker hub credentials to Minikube
if [ "$COPY_DOCKER_LOGIN" = "true" ]
then
set +ex

docker exec "minikube" bash -c "echo '$(cat $HOME/.docker/config.json)'| sudo tee -a /var/lib/kubelet/config.json > /dev/null && sudo systemctl restart kubelet"

set -ex
fi

minikube addons enable registry
minikube addons enable registry-aliases

kubectl create clusterrolebinding add-on-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
else
echo "Unsupported KUBE_CLUSTER '$KUBE_CLUSTER'"
exit 1
fi

label_node
11 changes: 11 additions & 0 deletions .azure/templates/setup_java.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Step to configure JAVA on the agent
parameters:
- name: JDK_VERSION
default: '17'
steps:
- task: JavaToolInstaller@0
inputs:
versionSpec: $(JDK_VERSION)
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
displayName: 'Configure Java'
15 changes: 15 additions & 0 deletions .azure/templates/setup_minikube.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Steps needed for local Minikube instance
steps:
- task: DockerInstaller@0
displayName: Docker Installer
inputs:
dockerVersion: 19.03.9
releaseType: stable
- bash: ".azure/scripts/setup-kubernetes.sh"
displayName: "Setup Minikube cluster"
env:
KUBE_CLUSTER: 'minikube'
KUBE_VERSION: 'latest'
KUBECTL_VERSION: 'latest'
MINIKUBE_VERSION: 'latest'
NSENTER_VERSION: '2.32'
144 changes: 144 additions & 0 deletions .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">

<module name="Checker">

<property name="localeLanguage" value="en"/>

<module name="FileTabCharacter"/>

<!-- header -->
<module name="RegexpHeader">
<!--
/*
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
-->
<property name="header" value="^\/\*$\n^\s\*\sCopyright\sStrimzi\sauthors\.$\n^\s\*\sLicense:\sApache\sLicense\s2\.0\s\(see\sthe\sfile\sLICENSE\sor\shttp:\/\/apache\.org\/licenses\/LICENSE-2\.0\.html\)\.$\n^\s\*\/$"/>
<property name="fileExtensions" value="java"/>
</module>

<module name="SuppressWarningsFilter" />
<module name="TreeWalker">
<!-- code cleanup -->
<module name="UnusedImports">
<property name="processJavadoc" value="true" />
</module>
<module name="RedundantImport"/>
<module name="IllegalImport" />
<module name="EqualsHashCode"/>
<module name="SimplifyBooleanExpression"/>
<module name="OneStatementPerLine"/>
<module name="UnnecessaryParentheses" />
<module name="SimplifyBooleanReturn"/>

<!-- Import order -->
<module name="CustomImportOrder">
<property name="customImportOrderRules"
value="THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/>
<property name="specialImportsRegExp" value="^javax\."/>
<property name="standardPackageRegExp" value="^java\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="false"/>
</module>

<!-- style -->
<module name="DefaultComesLast"/>
<module name="EmptyStatement"/>
<module name="ArrayTypeStyle"/>
<module name="UpperEll"/>
<module name="LeftCurly"/>
<module name="RightCurly"/>
<module name="EmptyStatement"/>
<module name="ConstantName">
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)|(^log$)"/>
</module>
<module name="LocalVariableName"/>
<module name="LocalFinalVariableName"/>
<module name="MemberName"/>
<module name="ClassTypeParameterName">
<property name="format" value="^[A-Z][a-zA-Z0-9]*$$"/>
</module>
<module name="MethodTypeParameterName">
<property name="format" value="^[A-Z][a-zA-Z0-9]*$$"/>
</module>
<module name="InterfaceTypeParameterName">
<property name="format" value="^[A-Z][a-zA-Z0-9]*$$"/>
</module>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="AvoidStarImport"/>

<!-- whitespace -->
<module name="GenericWhitespace"/>
<module name="NoWhitespaceBefore"/>
<module name="WhitespaceAfter" />
<module name="NoWhitespaceAfter"/>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyMethods" value="true"/>
</module>
<module name="Indentation"/>
<module name="MethodParamPad"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>

<!-- locale-sensitive methods should specify locale -->
<module name="Regexp">
<property name="format" value="\.to(Lower|Upper)Case\(\)"/>
<property name="illegalPattern" value="true"/>
<property name="ignoreComments" value="true"/>
</module>

<!-- code quality -->
<module name="MethodLength"/>
<module name="ParameterNumber">
<!-- default is 8 -->
<property name="max" value="8"/>
</module>
<module name="ClassDataAbstractionCoupling">
<!-- default is 7 -->
<property name="max" value="20"/>
</module>
<module name="BooleanExpressionComplexity">
<!-- default is 3 -->
<property name="max" value="3"/>
</module>

<module name="ClassFanOutComplexity">
<!-- default is 20 -->
<property name="max" value="20"/>
</module>
<module name="CyclomaticComplexity">
<!-- default is 10-->
<property name="max" value="10"/>
</module>
<module name="JavaNCSS">
<!-- default is 50 -->
<property name="methodMaximum" value="50"/>
</module>
<module name="NPathComplexity">
<!-- default is 200 -->
<property name="max" value="200"/>
</module>

<module name="IllegalToken">
<property name="tokens" value="LITERAL_ASSERT"/>
</module>

<!-- Make the @SuppressWarnings annotations available to Checkstyle -->
<module name="SuppressWarningsHolder" />
</module>

<module name="SuppressionFilter">
<property name="file" value="${checkstyle.suppressions.file}"/>
</module>

<!-- Filter out Checkstyle warnings that have been suppressed with the @SuppressWarnings annotation -->
<module name="SuppressWarningsFilter" />
</module>
Loading

0 comments on commit 9b8756d

Please sign in to comment.