Skip to content

Commit

Permalink
Create K8s deployment yaml to deploy ipfix-collector (#159)
Browse files Browse the repository at this point in the history
* add collector manifests templates
* add github job to check manifest is up-to-date


Co-authored-by: Anlan He <[email protected]>
  • Loading branch information
heanlan and Anlan He authored Apr 29, 2021
1 parent 3b4806b commit 4364413
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 7 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ jobs:
run: ./ci/check_codegen.sh


manifest:
name: Check manifest
runs-on: [ubuntu-latest]
steps:

- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.15

- name: Check-out code
uses: actions/checkout@v2

- name: Check manifest
run: ./ci/check_manifest.sh


golangci-lint:
name: Golangci-lint
runs-on: [ubuntu-18.04]
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/upload_release_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ jobs:
build:
runs-on: [ubuntu-latest]
steps:
- name: Build assets
uses: actions/checkout@v2
env:
TAG: ${{ github.ref }}
run: |
mkdir assets
VERSION="${TAG:10}" ./hack/release/prepare-assets.sh ./assets
- name: Checkout
uses: actions/checkout@v2
with:
Expand All @@ -17,15 +24,12 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build collector binary for Linux amd64
run: |
make collector
- name: Upload collector binary
- name: Upload ipfix-collector.yaml
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./bin/collector
asset_name: ipfix-collector-linux-x86_64
asset_path: ./assets/ipfix-collector.yaml
asset_name: ipfix-collector.yaml
asset_content_type: application/octet-stream
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ collector:
docker-collector:
@echo "===> Building antrea/ipfix-collector Docker image <==="
docker build --pull -t antrea/ipfix-collector -f build/images/Dockerfile.build.collector .

.PHONY: manifest
manifest:
@echo "===> Generating dev manifest for Go-ipfix <==="
$(CURDIR)/hack/generate-manifest-collector.sh --mode dev > build/yamls/ipfix-collector.yaml
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ go-ipfix is an IPFIX library that can be used to implement an IPFIX exporter, wh
## Try it out
This IPFIX library can be used to build an exporter. Please check out the [exporter tests](https://github.com/vmware/go-ipfix/blob/main/pkg/exporter/process_test.go) to get an idea on how to build exporter on top of TCP and UDP transport protocols given a IPFIX collector.

### Deploy stand alone IPFIX collector
To deploy a released version of the go-ipfix collector, which is used to collect, decode and log the IPFIX records, please choose one deployment manifest from the list of releases. For any given release <TAG> (e.g. v0.1.0), you can deploy the collector as follows:

```
kubectl apply -f https://github.com/vmware/go-ipfix/releases/download/<TAG>/ipfix-collector.yaml
```
To deploy the latest version of the go-ipfix collector (built from the main branch), use the command below:
```
cd <directory containing this README file>/build/yamls
kubectl apply -f ./ipfix-collector.yaml
```

While deploying the latest version of the go-ipfix collector, port and protocol can be configured by using the command:

```
cd <directory containing this README file>/hack
./generate-manifest-collector.sh --mode dev --port <port> --proto (tcp|udp) > ../build/yamls/ipfix-collector.yaml
```

Parameter ```--mode dev``` will build the collector from the docker image with the "latest" tag.
Use ```--port <port>``` to specify the port used by the collector. Default is 4739.
Use ```--proto (tcp|udp)``` to specify the protocol used by the collector. Default is tcp.
For example:

```
./generate-manifest-collector.sh --mode dev --port 4739 --proto tcp > ../build/yamls/ipfix-collector.yaml
```

## Build Registry
To build the registry from [IANA registry](https://www.iana.org/assignments/ipfix/ipfix.xhtml) or [Antrea registry](pkg/registry/registry_antrea.csv), run following commands:
```
Expand Down
2 changes: 1 addition & 1 deletion build/images/Dockerfile.build.collector
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ LABEL maintainer="go-ipfix"
LABEL description="A Docker image based on Ubuntu 18.04 which contains a IPFIX collector"

COPY --from=go-ipfix-build /go-ipfix/bin/collector /usr/local/bin/
ENTRYPOINT "collector"
ENTRYPOINT ["collector"]
3 changes: 3 additions & 0 deletions build/yamls/collector/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v2
name: ipfix-collector
version: 0.6.0
57 changes: 57 additions & 0 deletions build/yamls/collector/templates/ipfix-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: v1
kind: Namespace
metadata:
labels:
app: ipfix-collector
name: ipfix
---
apiVersion: v1
kind: Service
metadata:
labels:
app: ipfix-collector
name: ipfix-collector
namespace: ipfix
spec:
selector:
app: ipfix-collector
ports:
- name: ipfix-udp
port: 4739
protocol: UDP
targetPort: {{ .Values.port }}
- name: ipfix-tcp
port: 4739
protocol: TCP
targetPort: {{ .Values.port }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: ipfix-collector
name: ipfix-collector
namespace: ipfix
spec:
replicas: 1
selector:
matchLabels:
app: ipfix-collector
template:
metadata:
labels:
app: ipfix-collector
spec:
containers:
- args:
- --v=0
- --ipfix.port={{ .Values.port }}
- --ipfix.transport={{ .Values.protocol }}
image: projects.registry.vmware.com/antrea/ipfix-collector:{{ .Values.image_tag }}
imagePullPolicy: IfNotPresent
name: ipfix-collector
ports:
- containerPort: {{ .Values.port }}
nodeSelector:
kubernetes.io/os: linux
kubernetes.io/arch: amd64
3 changes: 3 additions & 0 deletions build/yamls/collector/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
protocol: tcp
port: 4739
image_tag: latest
61 changes: 61 additions & 0 deletions build/yamls/ipfix-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
# Source: ipfix-collector/templates/ipfix-collector.yaml
apiVersion: v1
kind: Namespace
metadata:
labels:
app: ipfix-collector
name: ipfix
---
# Source: ipfix-collector/templates/ipfix-collector.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: ipfix-collector
name: ipfix-collector
namespace: ipfix
spec:
selector:
app: ipfix-collector
ports:
- name: ipfix-udp
port: 4739
protocol: UDP
targetPort: 4739
- name: ipfix-tcp
port: 4739
protocol: TCP
targetPort: 4739
---
# Source: ipfix-collector/templates/ipfix-collector.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: ipfix-collector
name: ipfix-collector
namespace: ipfix
spec:
replicas: 1
selector:
matchLabels:
app: ipfix-collector
template:
metadata:
labels:
app: ipfix-collector
spec:
containers:
- args:
- --v=0
- --ipfix.port=4739
- --ipfix.transport=tcp
image: projects.registry.vmware.com/antrea/ipfix-collector:latest
imagePullPolicy: IfNotPresent
name: ipfix-collector
ports:
- containerPort: 4739
nodeSelector:
kubernetes.io/os: linux
kubernetes.io/arch: amd64
40 changes: 40 additions & 0 deletions ci/check_manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Copyright 2021 Go-ipfix Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script makes sure that the checked-in manifest YAML is up-to-date.

set -eo pipefail

function echoerr {
>&2 echo "$@"
}

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

YAMLS=(
"build/yamls/ipfix-collector.yaml"
)

rm "${YAMLS[@]}"
make manifest
diff="$(git status --porcelain ${YAMLS[@]})"

if [ ! -z "$diff" ]; then
echoerr "The generated manifest YAML is not up-to-date"
echoerr "You can regenerate them with 'make manifest' and commit the changes"
exit 1
fi
Loading

0 comments on commit 4364413

Please sign in to comment.