Skip to content

Commit 87689ed

Browse files
authored
Merge pull request #1 from pengzhouml/release/1.0.0-ea1
Release/1.0.0 ea1
2 parents 398066a + 26fecce commit 87689ed

File tree

97 files changed

+30800
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+30800
-1
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin/*
9+
Dockerfile.cross
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Go workspace file
18+
go.work
19+
20+
# Kubernetes Generated files - skip generated files, except for vendored files
21+
!vendor/**/zz_generated.*
22+
23+
# editor and IDE paraphernalia
24+
.idea
25+
.vscode
26+
*.swp
27+
*.swo
28+
*~

.golangci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
run:
2+
deadline: 5m
3+
allow-parallel-runners: true
4+
5+
issues:
6+
# don't skip warning about doc comments
7+
# don't exclude the default set of lint
8+
exclude-use-default: false
9+
# restore some of the defaults
10+
# (fill in the rest as needed)
11+
exclude-rules:
12+
- path: "api/*"
13+
linters:
14+
- lll
15+
- path: "internal/*"
16+
linters:
17+
- dupl
18+
- lll
19+
linters:
20+
disable-all: true
21+
enable:
22+
- dupl
23+
- errcheck
24+
- exportloopref
25+
- goconst
26+
- gocyclo
27+
- gofmt
28+
- goimports
29+
- gosimple
30+
- govet
31+
- ineffassign
32+
- lll
33+
- misspell
34+
- nakedret
35+
- prealloc
36+
- staticcheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- unused

CONTRIBUTING.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Contributing to MarkLogic-kubernetes-operator
2+
3+
Thank you for your interest in contributing to this project! We welcome contributions from the community to make this project better.
4+
5+
- [Found an Issue](#found-an-issue)
6+
- [Want a Feature](#want-a-feature)
7+
- [Getting Started](#getting-started)
8+
- [PR management](#pr-management)
9+
10+
## Found an Issue?
11+
12+
If you find a bug in the source code or a mistake in the documentation, you can help us by submitting an issue
13+
to our [GitHub Issue Tracker][Issue Tracker]. If you'd like to submit a feature enhancement, please first create an
14+
issue with your proposed idea so that we can start a discussion about the problem you want to solve and what the best
15+
solution would be.
16+
17+
## Want a Feature?
18+
19+
You can request a new feature by submitting an issue to our [GitHub Issue Tracker][Issue Tracker]. If you
20+
would like to implement a new feature then first create a new issue and discuss it with one of our
21+
project maintainers.
22+
23+
## Getting Started
24+
25+
To get started with contributing, please follow these steps:
26+
27+
1. Fork the repository and clone it to your local machine.
28+
2. Install the necessary dependencies.
29+
3. Create a new branch for your changes.
30+
4. Make your desired changes to the codebase.
31+
5. Test your changes thoroughly.
32+
6. Tests can be done using the test framework. See [test folder](./test/) and [Makefile](makefile)
33+
34+
## PR management
35+
36+
Created PR will not be merge as is.
37+
The MarkLogic kubernetes operator team will use the PRs for "inspiration" but not merge the changes in directly. They may rewrite the code as they like, incorporating the submitted changes into their own code.
38+
39+
**Important:** Please open an issue in the [Issue Tracker][] and get your proposed changes pre-approved by at least one of the project maintainers before you start coding. Nothing is more frustrating than seeing your hard work go to waste because your vision does not align with that of the project maintainers.
40+
41+
[Issue Tracker]: https://github.com/marklogic/marklogic-kubernetes-operator/issues

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Build the manager binary
2+
FROM golang:1.22 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY cmd/main.go cmd/main.go
16+
COPY api/ api/
17+
COPY internal/controller/ internal/controller/
18+
COPY pkg/ pkg/
19+
20+
# Build
21+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
22+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
23+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
24+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
26+
27+
# Use distroless as minimal base image to package the manager binary
28+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
29+
FROM gcr.io/distroless/static:nonroot
30+
WORKDIR /
31+
COPY --from=builder /workspace/manager .
32+
USER 65532:65532
33+
34+
ENTRYPOINT ["/manager"]

Jenkinsfile

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/* groovylint-disable CompileStatic, LineLength, VariableTypeRequired */
2+
// This Jenkinsfile defines internal MarkLogic build pipeline.
3+
4+
//Shared library definitions: https://github.com/marklogic/MarkLogic-Build-Libs/tree/1.0-declarative/vars
5+
@Library('[email protected]')
6+
import groovy.json.JsonSlurperClassic
7+
8+
9+
10+
gitCredID = 'marklogic-builder-github'
11+
JIRA_ID = ''
12+
JIRA_ID_PATTERN = /(?i)(MLE)-\d{3,6}/
13+
14+
// Define local funtions
15+
void preBuildCheck() {
16+
// Initialize parameters as env variables as workaround for https://issues.jenkins-ci.org/browse/JENKINS-41929
17+
evaluate """${ def script = ''; params.each { k, v -> script += "env.${k } = '''${v}'''\n" }; return script}"""
18+
19+
JIRA_ID = extractJiraID()
20+
echo 'Jira ticket number: ' + JIRA_ID
21+
22+
if (env.GIT_URL) {
23+
githubAPIUrl = GIT_URL.replace('.git', '').replace('github.com', 'api.github.com/repos')
24+
echo 'githubAPIUrl: ' + githubAPIUrl
25+
} else {
26+
echo 'Warning: GIT_URL is not defined'
27+
}
28+
29+
if (env.CHANGE_ID) {
30+
if (prDraftCheck()) { sh 'exit 1' }
31+
if (getReviewState().equalsIgnoreCase('CHANGES_REQUESTED')) {
32+
echo 'PR changes requested. (' + reviewState + ') Aborting.'
33+
sh 'exit 1'
34+
}
35+
}
36+
37+
// our VMs sometimes disable bridge traffic. this should help to restore it.
38+
sh 'sudo sh -c "echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables"'
39+
}
40+
41+
@NonCPS
42+
def extractJiraID() {
43+
// Extract Jira ID from one of the environment variables
44+
def match
45+
if (env.CHANGE_TITLE) {
46+
match = env.CHANGE_TITLE =~ JIRA_ID_PATTERN
47+
}
48+
else if (env.BRANCH_NAME) {
49+
match = env.BRANCH_NAME =~ JIRA_ID_PATTERN
50+
}
51+
else if (env.GIT_BRANCH) {
52+
match = env.GIT_BRANCH =~ JIRA_ID_PATTERN
53+
}
54+
else {
55+
echo 'Warning: No Git title or branch available.'
56+
return ''
57+
}
58+
try {
59+
return match[0][0]
60+
} catch (any) {
61+
echo 'Warning: Jira ticket number not detected.'
62+
return ''
63+
}
64+
}
65+
66+
def prDraftCheck() {
67+
withCredentials([usernameColonPassword(credentialsId: gitCredID, variable: 'Credentials')]) {
68+
PrObj = sh(returnStdout: true, script:'''
69+
curl -s -u $Credentials -X GET ''' + githubAPIUrl + '''/pulls/$CHANGE_ID
70+
''')
71+
}
72+
def jsonObj = new JsonSlurperClassic().parseText(PrObj.toString().trim())
73+
return jsonObj.draft
74+
}
75+
76+
def getReviewState() {
77+
def reviewResponse
78+
def commitHash
79+
withCredentials([usernameColonPassword(credentialsId: gitCredID, variable: 'Credentials')]) {
80+
reviewResponse = sh(returnStdout: true, script:'''
81+
curl -s -u $Credentials -X GET ''' + githubAPIUrl + '''/pulls/$CHANGE_ID/reviews
82+
''')
83+
commitHash = sh(returnStdout: true, script:'''
84+
curl -s -u $Credentials -X GET ''' + githubAPIUrl + '''/pulls/$CHANGE_ID
85+
''')
86+
}
87+
def jsonObj = new JsonSlurperClassic().parseText(commitHash.toString().trim())
88+
def commitId = jsonObj.head.sha
89+
println(commitId)
90+
def reviewState = getReviewStateOfPR reviewResponse, 2, commitId
91+
echo reviewState
92+
return reviewState
93+
}
94+
95+
void resultNotification(message) {
96+
def author, authorEmail, emailList
97+
//add author of a PR to email list if available
98+
if (env.CHANGE_AUTHOR) {
99+
author = env.CHANGE_AUTHOR.toString().trim().toLowerCase()
100+
authorEmail = getEmailFromGITUser author
101+
emailList = params.emailList + ',' + authorEmail
102+
} else {
103+
emailList = params.emailList
104+
}
105+
jira_link = "https://progresssoftware.atlassian.net/browse/${JIRA_ID}"
106+
email_body = "<b>Jenkins pipeline for</b> ${env.JOB_NAME} <br><b>Build Number: </b>${env.BUILD_NUMBER} <br><br><b>Build URL: </b><br><a href='${env.BUILD_URL}'>${env.BUILD_URL}</a>"
107+
jira_email_body = "${email_body} <br><br><b>Jira URL: </b><br><a href='${jira_link}'>${jira_link}</a>"
108+
109+
if (JIRA_ID) {
110+
def comment = [ body: "Jenkins pipeline build result: ${message}" ]
111+
jiraAddComment site: 'JIRA', idOrKey: JIRA_ID, failOnError: false, input: comment
112+
mail charset: 'UTF-8', mimeType: 'text/html', to: "${emailList}", body: "${jira_email_body}", subject: "${message}: ${env.JOB_NAME} #${env.BUILD_NUMBER} - ${JIRA_ID}"
113+
} else {
114+
mail charset: 'UTF-8', mimeType: 'text/html', to: "${emailList}", body: "${email_body}", subject: "${message}: ${env.JOB_NAME} #${env.BUILD_NUMBER}"
115+
}
116+
}
117+
118+
void publishTestResults() {
119+
junit allowEmptyResults:true, testResults: '**/test/test_results/*.xml'
120+
archiveArtifacts artifacts: '**/test/test_results/*.xml', allowEmptyArchive: true
121+
}
122+
123+
void runTests() {
124+
sh "make test"
125+
}
126+
127+
void runE2eTests() {
128+
//TODO: this is just a place holder as kuttl needs a proper environment
129+
sh "echo make e2e-tests dockerImage=${params.dockerImage}"
130+
}
131+
132+
pipeline {
133+
agent {
134+
label {
135+
label 'cld-kubernetes'
136+
}
137+
}
138+
options {
139+
checkoutToSubdirectory '.'
140+
buildDiscarder logRotator(artifactDaysToKeepStr: '20', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '')
141+
skipStagesAfterUnstable()
142+
}
143+
// triggers {
144+
// //TODO: add scheduled runs
145+
// }
146+
// environment {
147+
// //TODO
148+
// }
149+
150+
parameters {
151+
string(name: 'dockerImage', defaultValue: 'ml-docker-db-dev-tierpoint.bed-artifactory.bedford.progress.com/marklogic/marklogic-server-ubi:latest-11', description: 'Docker image to use for tests.', trim: true)
152+
string(name: 'emailList', defaultValue: emailList, description: 'List of email for build notification', trim: true)
153+
}
154+
155+
stages {
156+
stage('Pre-Build-Check') {
157+
steps {
158+
preBuildCheck()
159+
}
160+
}
161+
162+
stage('Run-tests') {
163+
steps {
164+
runTests()
165+
}
166+
}
167+
168+
stage('Run-e2e-tests') {
169+
steps {
170+
runE2eTests()
171+
}
172+
}
173+
174+
}
175+
176+
post {
177+
always {
178+
publishTestResults()
179+
}
180+
success {
181+
resultNotification('BUILD SUCCESS ✅')
182+
}
183+
failure {
184+
resultNotification('BUILD ERROR ❌')
185+
}
186+
unstable {
187+
resultNotification('BUILD UNSTABLE 🉑')
188+
}
189+
}
190+
}

0 commit comments

Comments
 (0)