Skip to content

Commit cb761d6

Browse files
committed
Merge branch 'develop' to master for 0.1.0 release
2 parents 1be429a + 78b6874 commit cb761d6

File tree

109 files changed

+50288
-2526
lines changed

Some content is hidden

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

109 files changed

+50288
-2526
lines changed

.circleci/config.yml

Lines changed: 177 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,181 @@
1-
version: 2
2-
jobs:
3-
compile-binary:
1+
# See https://circleci.com/blog/using-circleci-workflows-to-replicate-docker-hub-automated-builds/
2+
version: 2.1
3+
workflows:
4+
version: 2
5+
build-and-push:
6+
jobs:
7+
- build-image
8+
- unit-tests
9+
- vulnerability-scan:
10+
requires:
11+
- build-image
12+
- push-latest:
13+
requires:
14+
- build-image
15+
- unit-tests
16+
- vulnerability-scan
17+
filters:
18+
branches:
19+
only:
20+
- master
21+
- push-edge:
22+
requires:
23+
- build-image
24+
- unit-tests
25+
- vulnerability-scan
26+
filters:
27+
branches:
28+
only:
29+
- develop
30+
- push-release:
31+
requires:
32+
- build-image
33+
- unit-tests
34+
- vulnerability-scan
35+
filters:
36+
tags:
37+
only: /^\d+\.\d+\.\d+/
38+
branches:
39+
ignore: /.*/
40+
executors:
41+
golang-builder:
42+
environment:
43+
IMAGE_NAME: splunk/splunk-operator
44+
IMAGE_FILENAME: splunk-operator
45+
working_directory: /opt/app-root/src/splunk-operator
446
docker:
5-
- image: splunk/splunk-operator-builder:master
47+
- image: splunk/splunk-operator-builder:develop
48+
docker-publisher:
49+
environment:
50+
IMAGE_NAME: splunk/splunk-operator
51+
IMAGE_FILENAME: splunk-operator
52+
docker:
53+
- image: circleci/buildpack-deps:buster
54+
classic-machine:
55+
environment:
56+
IMAGE_NAME: splunk/splunk-operator
57+
IMAGE_FILENAME: splunk-operator
58+
machine:
59+
image: circleci/classic:latest
60+
commands:
61+
save_image:
62+
description: "Save image"
63+
steps:
64+
- run:
65+
name: "Save image"
66+
command: |
67+
mkdir -p /tmp/images
68+
docker image save -o /tmp/images/${IMAGE_FILENAME}-${CIRCLE_SHA1}.tar ${IMAGE_NAME}:${CIRCLE_SHA1}
69+
load_image:
70+
description: "Load image"
71+
steps:
72+
- run:
73+
name: "Load image"
74+
command: docker load -i /tmp/images/${IMAGE_FILENAME}-${CIRCLE_SHA1}.tar
75+
push_image:
76+
description: "Load, tag and push an image"
77+
parameters:
78+
tag:
79+
type: string
80+
steps:
81+
- load_image
82+
- run:
83+
name: Tag image
84+
command: |
85+
docker tag ${IMAGE_NAME}:${CIRCLE_SHA1} ${IMAGE_NAME}:<< parameters.tag >>
86+
- run:
87+
name: Push latest image to DockerHub
88+
command: |
89+
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
90+
docker push ${IMAGE_NAME}:<< parameters.tag >>
91+
jobs:
92+
build-image:
93+
executor: golang-builder
94+
steps:
95+
- checkout
96+
- setup_remote_docker:
97+
docker_layer_caching: true
98+
- run:
99+
name: Pull base image updates
100+
command: docker pull registry.access.redhat.com/ubi8/ubi-minimal:latest
101+
- run:
102+
name: Build splunk/splunk-operator image
103+
command: operator-sdk build --verbose ${IMAGE_NAME}:${CIRCLE_SHA1}
104+
- save_image
105+
- persist_to_workspace:
106+
name: Persist images to workspace
107+
root: /tmp
108+
paths:
109+
- images
110+
- store_artifacts:
111+
name: Save images as artifacts
112+
path: /tmp/images
113+
unit-tests:
114+
executor: golang-builder
6115
steps:
7116
- checkout
117+
- run:
118+
name: Check source formatting
119+
command: X=`make fmt` && if [[ "x$X" != "x" ]]; then echo $X && false; fi
120+
- run:
121+
name: Lint source code
122+
command: X=`make lint` && if [[ "x$X" != "x" ]]; then echo $X && false; fi
8123
- run:
9-
name: Build splunk-operator binary
10-
command: go build -v -o ./build/_output/bin/splunk-operator ./cmd/manager
11-
workflows:
12-
version: 2
13-
build:
14-
jobs:
15-
- compile-binary
16-
124+
name: Run package tests
125+
command: make test
126+
- run:
127+
name: Upload coverage.out
128+
command: goveralls -coverprofile=coverage.out -service=circle-ci -repotoken $COVERALLS_TOKEN
129+
- store_artifacts:
130+
name: Save coverage.out as artifact
131+
path: coverage.out
132+
vulnerability-scan:
133+
executor: classic-machine
134+
steps:
135+
- checkout
136+
- attach_workspace:
137+
name: Restore workspace
138+
at: /tmp
139+
- load_image
140+
- run:
141+
name: Setup clair scanner
142+
command: make setup_clair_scanner
143+
- run:
144+
name: Scan container image
145+
command: make run_clair_scan
146+
- run:
147+
name: Stop clair scanner
148+
command: make stop_clair_scanner
149+
- store_artifacts:
150+
name: Save scan results as artifacts
151+
path: clair-scanner-logs
152+
push-latest:
153+
executor: docker-publisher
154+
steps:
155+
- setup_remote_docker:
156+
docker_layer_caching: false
157+
- attach_workspace:
158+
name: Restore workspace
159+
at: /tmp
160+
- push_image:
161+
tag: "latest"
162+
push-edge:
163+
executor: docker-publisher
164+
steps:
165+
- setup_remote_docker:
166+
docker_layer_caching: false
167+
- attach_workspace:
168+
name: Restore workspace
169+
at: /tmp
170+
- push_image:
171+
tag: "edge"
172+
push-release:
173+
executor: docker-publisher
174+
steps:
175+
- setup_remote_docker:
176+
docker_layer_caching: false
177+
- attach_workspace:
178+
name: Restore workspace
179+
at: /tmp
180+
- push_image:
181+
tag: "${CIRCLE_TAG}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ push_targets
8484
splunk-enterprise.lic
8585
splunk-operator-*.yaml
8686
splunk-operator-*.tar.gz
87+
clair-scanner
88+
clair-scanner-logs

Makefile

Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,106 @@
11
# Makefile for Splunk Operator
22

3-
.PHONY: all image package local clean run fmt lint
3+
.PHONY: all builder builder-image image package local clean run fmt lint
4+
5+
# Security Scanner Variables
6+
SCANNER_DATE := `date +%Y-%m-%d`
7+
SCANNER_DATE_YEST := `TZ=GMT+24 +%Y:%m:%d`
8+
SCANNER_VERSION := v8
9+
SCANNER_LOCALIP := $(shell ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | awk '{print $1}' | head -n 1)
10+
ifeq ($(shell uname), Linux)
11+
SCANNER_FILE = clair-scanner_linux_amd64
12+
else ifeq ($(shell uname), Darwin)
13+
SCANNER_FILE = clair-scanner_darwin_amd64
14+
else
15+
SCANNER_FILE = clair-scanner_windows_amd64.exe
16+
endif
417

518
all: image
619

7-
builder-image:
20+
builder:
821
@echo Creating container image to build splunk-operator
922
@docker build -f ./build/Dockerfile.builder -t splunk/splunk-operator-builder .
1023

11-
builder: deploy/all-in-one-scoped.yaml deploy/all-in-one-cluster.yaml
12-
@echo Using container to build splunk-operator
24+
builder-image:
25+
@echo Using builder container to build splunk-operator
1326
@mkdir -p ./build/_output/bin
14-
@docker run -v ${PWD}:/opt/app-root/src/splunk-operator -u root -it splunk/splunk-operator-builder bash -c "cd /opt/app-root/src/splunk-operator && go build -v -o ./build/_output/bin/splunk-operator ./cmd/manager"
27+
@docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/opt/app-root/src/splunk-operator -w /opt/app-root/src/splunk-operator -u root -it splunk/splunk-operator-builder bash -c "operator-sdk build --verbose splunk/splunk-operator"
1528

16-
image: deploy/all-in-one-scoped.yaml deploy/all-in-one-cluster.yaml
17-
@echo Building splunk-operator image
18-
@operator-sdk build splunk/splunk-operator
29+
builder-test:
30+
@echo Running unit tests for splunk-operator inside of builder container
31+
@docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${PWD}:/opt/app-root/src/splunk-operator -w /opt/app-root/src/splunk-operator -u root -it splunk/splunk-operator-builder bash -c "go test -v -covermode=count -coverprofile=coverage.out --timeout=300s github.com/splunk/splunk-operator/pkg/splunk/resources github.com/splunk/splunk-operator/pkg/splunk/spark github.com/splunk/splunk-operator/pkg/splunk/enterprise github.com/splunk/splunk-operator/pkg/splunk/reconcile github.com/splunk/splunk-operator/pkg/splunk/client"
1932

20-
package: deploy/all-in-one-scoped.yaml deploy/all-in-one-cluster.yaml
21-
@build/package.sh
33+
image:
34+
@echo Building splunk-operator image
35+
@operator-sdk build --verbose splunk/splunk-operator
2236

23-
local: deploy/all-in-one-scoped.yaml deploy/all-in-one-cluster.yaml
37+
local:
38+
@echo Building splunk-operator-local binary only
2439
@mkdir -p ./build/_output/bin
2540
@go build -v -o ./build/_output/bin/splunk-operator-local ./cmd/manager
2641

27-
clean:
42+
test:
43+
@echo Running unit tests for splunk-operator
44+
@go test -v -covermode=count -coverprofile=coverage.out --timeout=300s github.com/splunk/splunk-operator/pkg/splunk/resources github.com/splunk/splunk-operator/pkg/splunk/spark github.com/splunk/splunk-operator/pkg/splunk/enterprise github.com/splunk/splunk-operator/pkg/splunk/reconcile github.com/splunk/splunk-operator/pkg/splunk/client
45+
46+
stop_clair_scanner:
47+
@docker stop clair_db || true
48+
@docker rm clair_db || true
49+
@docker stop clair || true
50+
@docker rm clair || true
51+
52+
setup_clair_scanner: stop_clair_scanner
53+
@mkdir -p clair-scanner-logs
54+
@docker pull arminc/clair-db:${SCANNER_DATE} || docker pull arminc/clair-db:${SCANNER_DATE_YEST} || echo "WARNING: Failed to pull daily image, defaulting to latest" >> clair-scanner-logs/clair_setup_errors.log ; docker pull arminc/clair-db:latest
55+
@docker run -d --name clair_db arminc/clair-db:${SCANNER_DATE} || docker run -d --name clair_db arminc/clair-db:${SCANNER_DATE_YEST} || docker run -d --name clair_db arminc/clair-db:latest
56+
@docker run -p 6060:6060 --link clair_db:postgres -d --name clair --restart on-failure arminc/clair-local-scan:v2.0.6
57+
@wget https://github.com/arminc/clair-scanner/releases/download/${SCANNER_VERSION}/${SCANNER_FILE}
58+
@mv ${SCANNER_FILE} clair-scanner
59+
@chmod +x clair-scanner
60+
@echo "Waiting for clair daemon to start"
61+
@retries=0 ; while( ! wget -T 10 -q -O /dev/null http://0.0.0.0:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $$retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$$(($$retries+1)) ; done
62+
@echo "Clair daemon started."
63+
64+
run_clair_scan:
65+
@./clair-scanner -c http://0.0.0.0:6060 --ip ${SCANNER_LOCALIP} -r clair-scanner-logs/results.json -l clair-scanner-logs/results.log splunk/splunk-operator
66+
67+
generate:
68+
@echo Running operator-sdk generate k8s
69+
@operator-sdk generate k8s
70+
@echo Running operator-sdk generate crds
71+
@cp deploy/rbac.yaml deploy/role.yaml
72+
@operator-sdk generate crds
73+
@rm -f deploy/role.yaml deploy/crds/*_cr.yaml
74+
@echo Rebuilding deploy/crds/combined.yaml
75+
@echo "---" > deploy/crds/combined.yaml
76+
@cat deploy/crds/enterprise.splunk.com_standalones_crd.yaml >> deploy/crds/combined.yaml
77+
@echo "---" >> deploy/crds/combined.yaml
78+
@cat deploy/crds/enterprise.splunk.com_licensemasters_crd.yaml >> deploy/crds/combined.yaml
79+
@echo "---" >> deploy/crds/combined.yaml
80+
@cat deploy/crds/enterprise.splunk.com_searchheadclusters_crd.yaml >> deploy/crds/combined.yaml
81+
@echo "---" >> deploy/crds/combined.yaml
82+
@cat deploy/crds/enterprise.splunk.com_indexerclusters_crd.yaml >> deploy/crds/combined.yaml
83+
@echo "---" >> deploy/crds/combined.yaml
84+
@cat deploy/crds/enterprise.splunk.com_sparks_crd.yaml >> deploy/crds/combined.yaml
85+
@echo Rebuilding deploy/all-in-one-scoped.yaml
86+
@cat deploy/crds/combined.yaml deploy/rbac.yaml deploy/operator.yaml > deploy/all-in-one-scoped.yaml
87+
@echo Rebuilding deploy/all-in-one-cluster.yaml
88+
@cat deploy/crds/combined.yaml deploy/rbac.yaml deploy/cluster_operator.yaml > deploy/all-in-one-cluster.yaml
89+
90+
package: lint fmt generate
91+
@build/package.sh
92+
93+
clean: stop_clair_scanner
2894
@rm -rf ./build/_output
2995
@docker rmi splunk/splunk-operator || true
96+
@rm -f clair-scanner
97+
@rm -rf clair-scanner-logs
3098

3199
run:
32-
@OPERATOR_NAME=splunk-operator operator-sdk up local
100+
@OPERATOR_NAME=splunk-operator operator-sdk run --local
33101

34102
fmt:
35103
@gofmt -l -w `find ./ -name "*.go"`
36104

37105
lint:
38106
@golint ./...
39-
40-
deploy/all-in-one-scoped.yaml: deploy/crds/enterprise_v1alpha1_splunkenterprise_crd.yaml deploy/rbac.yaml deploy/operator.yaml
41-
@echo Rebuilding deploy/all-in-one-scoped.yaml
42-
@cat deploy/crds/enterprise_v1alpha1_splunkenterprise_crd.yaml deploy/rbac.yaml deploy/operator.yaml > deploy/all-in-one-scoped.yaml
43-
44-
deploy/all-in-one-cluster.yaml: deploy/crds/enterprise_v1alpha1_splunkenterprise_crd.yaml deploy/rbac.yaml deploy/cluster_operator.yaml
45-
@echo Rebuilding deploy/all-in-one-cluster.yaml
46-
@cat deploy/crds/enterprise_v1alpha1_splunkenterprise_crd.yaml deploy/rbac.yaml deploy/cluster_operator.yaml > deploy/all-in-one-cluster.yaml

0 commit comments

Comments
 (0)