Skip to content

Commit

Permalink
add main ci test
Browse files Browse the repository at this point in the history
Signed-off-by: zhu733756 <[email protected]>
  • Loading branch information
zhu733756 committed Oct 21, 2021
1 parent 1a79f18 commit 1cbf0c2
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/kind/kind.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.21.2
extraMounts:
- hostPath: /etc/localtime
containerPath: /etc/localtime
# extraPortMappings:
# - containerPort: 19093
# hostPort: 19093
167 changes: 167 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
name: Main CI WorkFlow

on:
push:
branches:
- 'master'
- 'release-*'
tags:
- 'v*'
pull_request:
branches:
- 'master'
- 'release-*'
env:
OP_IMAGE: kubesphere/notification-manager-operator:latest
NM_IMAGE: kubesphere/notification-manager:latest

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Basic test and verify
env:
GO111MODULE: "on"
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install kubebuilder-2.3.2
run: |
curl -L "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_linux_amd64.tar.gz" | tar -xz -C /tmp/
sudo mv /tmp/kubebuilder_2.3.2_linux_amd64 /usr/local/kubebuilder
- name: Run basic test
run: make test

- name: Run verify crds test
run: make verify

build:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Binary build
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- run: make binary
name: Run build all binaries

docker_build:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Docker image build
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: build image
run: |
docker build . -t ${{ env.OP_IMAGE }} -f cmd/operator/Dockerfile --build-arg GOPROXY="https://proxy.golang.org"
docker build . -t ${{ env.NM_IMAGE }} -f cmd/notification-manager/Dockerfile --build-arg GOPROXY="https://proxy.golang.org"
helm_deployment:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Install and uninstall notification manager by helm
steps:
- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0

- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create kind cluster
uses: helm/[email protected]
with:
config: .github/workflows/kind/kind.yaml

- name: Setting up notification manager
run: |
kubectl create ns kubesphere-monitoring-system
helm install notification-manager ./helm -n kubesphere-monitoring-system
- name: Waiting for 30 seconds to keep the notification manager installed
uses: jakejarvis/wait-action@master
with:
time: '30s'

- name: Check the related resources
run: |
echo "list release:"
echo "-----"
helm list -n kubesphere-monitoring-system
echo "-----"
echo "list pods:"
echo "-----"
kubectl get pods -n kubesphere-monitoring-system
echo "-----"
- name: Deploy the default SlackConfig and global SlackReceiver
run: |
cat config/ci/slack-pr.yaml | sed -e 's/SLACK_SECRET/${{ secrets.SLACK_SECRET }}/g' | kubectl apply -f -
- name: Expose service port as nodeport
run: |
kubectl -n kubesphere-monitoring-system patch svc notification-manager-svc --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"},{"op":"replace","path":"/spec/ports/0/nodePort","value":30008}]'
- name: Send alerts
run: |
NODE_IP=$(kubectl get nodes -o jsonpath={.items[0].status.addresses[0].address})
curl -XPOST -d @./config/ci/alerts.json "http://$NODE_IP:30008/api/v2/alerts"
- name: Waiting for 2 seconds
uses: jakejarvis/wait-action@master
with:
time: '2s'

- name: Check the related logs
run: |
kubectl -n kubesphere-monitoring-system logs -l app=notification-manager
- name: Uninstall notification manager
run: |
helm uninstall notification-manager -n kubesphere-monitoring-system
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ all: manager
test: generate fmt vet manifests
go test ./... -coverprofile cover.out

# Build binary
binary:
go build -o bin/notification-manager-operator cmd/operator/main.go
go build -o bin/notification-manager cmd/notification-manager/main.go

# Verify CRDs
verify: verify-crds

verify-crds: generate
@if !(git diff --quiet HEAD config/crd); then \
echo "generated files located at config/crd are out of date, run make generate"; exit 1; \
fi
@if !(git diff --quiet HEAD helm/crds); then \
echo "generated files located at helm/crds are out of date, run make generate and copy it to there"; exit 1; \
fi

# Build manager binary
manager: generate fmt vet
go build -o bin/notification-manager-operator cmd/operator/main.go
Expand Down
4 changes: 3 additions & 1 deletion cmd/notification-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG GOPROXY="https://goproxy.io"
# Build the manager binary
FROM golang:1.13 as builder
ARG GOPROXY

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -8,7 +10,7 @@ COPY go.sum go.sum

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN GOPROXY="https://goproxy.io" go mod download
RUN GOPROXY=$GOPROXY go mod download

# Copy the go source
COPY cmd/notification-manager/main.go main.go
Expand Down
6 changes: 4 additions & 2 deletions cmd/operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG GOPROXY="https://goproxy.cn"
# Build the manager binary
FROM golang:1.13 as builder
ARG GOPROXY

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -8,14 +10,14 @@ COPY go.sum go.sum

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN GOPROXY="https://goproxy.io" go mod download
RUN GOPROXY=$GOPROXY go mod download

# Copy the go source
COPY cmd/operator/main.go main.go
COPY pkg/ pkg/

# Build
RUN GOPROXY="https://goproxy.io" CGO_ENABLED=0 GO111MODULE=on go build -a -o notification-manager-operator main.go
RUN GOPROXY=$GOPROXY CGO_ENABLED=0 GO111MODULE=on go build -a -o notification-manager-operator main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
39 changes: 39 additions & 0 deletions config/ci/alerts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"receiver": "Default",
"status": "firing",
"alerts": [
{
"status": "firing",
"labels": {
"alertname": "PullRequestNotification",
"container": "pull-request-notification",
"namespace": "kubsphere-monitoring-system",
"pod": "pull-request-notification-67f5689d7-sqg89",
"prometheus": "kubesphere-monitoring-system/k8s",
"severity": "warning"
},
"annotations": {
"message": "Congratulations! Pull request notification triggered, your pr has passed the helm deployment test.",
"runbook_url": ""
},
"startsAt": "2021-10-21T05:45:44.782098546Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "",
"fingerprint": "83fb3d34d52108b0"
}
],
"groupLabels": {
"alertname": "PullRequestTest",
"namespace": "kubesphere-monitoring-system"
},
"commonLabels": {
"alertname": "PullRequestTest",
"namespace": "kubesphere-monitoring-system",
"prometheus": "kubesphere-monitoring-system/k8s",
"severity": "warning"
},
"commonAnnotations": {
"runbook_url": ""
},
"externalURL": "http://alertmanager-main-1:9093"
}
38 changes: 38 additions & 0 deletions config/ci/slack-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: notification.kubesphere.io/v2beta2
kind: Config
metadata:
name: default-slack-config
labels:
app: notification-manager
type: default
spec:
slack:
slackTokenSecret:
valueFrom:
secretKeyRef:
namespace: kubesphere-monitoring-system
key: token
name: slack-token-secret
---
apiVersion: notification.kubesphere.io/v2beta2
kind: Receiver
metadata:
name: global-slack-receiver
labels:
app: notification-manager
type: global
spec:
slack:
channels:
- sig-observability
---
apiVersion: v1
data:
token: SLACK_SECRET
kind: Secret
metadata:
labels:
app: notification-manager
name: slack-token-secret
namespace: kubesphere-monitoring-system
type: Opaque
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ operator:
# value of notification-manager
notificationmanager:
image:
repo: kubesphere/notification-manager
tag: v1.3.0
pullPolicy: IfNotPresent
replicas: 1
Expand Down

0 comments on commit 1cbf0c2

Please sign in to comment.