diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..e0871f93 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..629fcada --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,24 @@ +## Description + + + +## Dependencies + + +n/a + +## Checklist + +If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that. + +* [ ] Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix _(in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes)._ +* [ ] Does this PR require product documentation? + * [ ] If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs. +* [ ] Does this PR require a product release notes entry? + * [ ] If so, fill in "Release Note Text" in the JIRA. +* [ ] Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc. + * [ ] If so, make sure it is described in the JIRA ticket. +* QE requirements (check 1 from the list): + * [ ] Standard QE validation, with pre-merge tests unless stated otherwise. + * [ ] Regression tests only (e.g. refactoring with no user-facing change). + * [ ] No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team). diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 00000000..9a3e3923 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,8 @@ +changelog: + categories: + - title: Breaking changes 🛠 + labels: + - breaking-change + - title: Non-breaking changes + labels: + - "*" diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 00000000..5b5bef23 --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,15 @@ +name: greetings + +on: [issues] + +jobs: + greeting: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/first-interaction@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: 'Congratulations for contributing your first netobserv-cli issue' diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..11b3b9c5 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,34 @@ +name: pull request checks + +on: + pull_request: + branches: ['*'] + +jobs: + build-test: + name: Build, lint, test + runs-on: ubuntu-latest + strategy: + matrix: + go: ['1.21'] + + steps: + - name: install make + run: sudo apt-get install make + - name: set up go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - name: checkout + uses: actions/checkout@v3 + - name: run build + run: make build && git diff --exit-code + - name: run unit tests + run: make test + - name: Report coverage + uses: codecov/codecov-action@v2.1.0 + with: + files: ./cover.out + flags: unittests + fail_ci_if_error: false + args: --timeout 5m0s diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml new file mode 100644 index 00000000..a0004fe1 --- /dev/null +++ b/.github/workflows/push_image.yml @@ -0,0 +1,66 @@ +name: Build and push to quay.io +on: + push: + branches: [ main, release-*, workflow-test ] + +env: + WF_REGISTRY_USER: netobserv+github_ci + WF_ORG: netobserv + WF_MULTIARCH_TARGETS: amd64 arm64 ppc64le s390x + WF_VERSION: ${{ github.ref_name }} + +jobs: + push-image: + name: push image + runs-on: ubuntu-latest + strategy: + matrix: + go: ['1.21'] + steps: + - name: install make + run: sudo apt-get install make + - name: set up go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - name: checkout + uses: actions/checkout@v3 + - name: docker login to quay.io + uses: docker/login-action@v2 + with: + username: ${{ env.WF_REGISTRY_USER }} + password: ${{ secrets.QUAY_SECRET }} + registry: quay.io + - name: get short sha + run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + - name: build and push manifest with images + run: | + MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.WF_VERSION }} make images + MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.short_sha }} OCI_BUILD_OPTS="--label quay.expires-after=2w" make images + if [[ "main" == "$WF_VERSION" ]]; then + MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=latest make images + fi + + codecov: + name: Codecov upload + runs-on: ubuntu-latest + strategy: + matrix: + go: ['1.21'] + steps: + - name: install make + run: sudo apt-get install make + - name: set up go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - name: checkout + uses: actions/checkout@v3 + - name: Test + run: make test + - name: Report coverage + uses: codecov/codecov-action@v2.1.0 + with: + files: ./cover.out + flags: unittests + fail_ci_if_error: false diff --git a/.github/workflows/push_image_pr.yml b/.github/workflows/push_image_pr.yml new file mode 100644 index 00000000..c898cb0e --- /dev/null +++ b/.github/workflows/push_image_pr.yml @@ -0,0 +1,60 @@ +name: Build and push PR image to quay.io +on: + pull_request_target: + types: [labeled] + +env: + WF_REGISTRY_USER: netobserv+github_ci + WF_REGISTRY: quay.io/netobserv + WF_IMAGE: network-observability-cli + WF_ORG: netobserv + +jobs: + push-pr-image: + if: ${{ github.event.label.name == 'ok-to-test' }} + name: push PR image + runs-on: ubuntu-latest + strategy: + matrix: + go: ['1.21'] + steps: + - name: install make + run: sudo apt-get install make + - name: set up go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - name: checkout + uses: actions/checkout@v3 + with: + ref: "refs/pull/${{ github.event.number }}/merge" + - name: docker login to quay.io + uses: docker/login-action@v2 + with: + username: ${{ env.WF_REGISTRY_USER }} + password: ${{ secrets.QUAY_SECRET }} + registry: quay.io + - name: get short sha + run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + - name: build and push manifest with images + run: OCI_BUILD_OPTS="--label quay.expires-after=2w" IMAGE_ORG=${{ env.WF_ORG }} IMAGE=${{ env.WF_REGISTRY }}/${{ env.WF_IMAGE }}:${{ env.short_sha }} make images + - uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `New image: + ${{ env.WF_REGISTRY }}/${{ env.WF_IMAGE }}:${{ env.short_sha }} + + It will expire after two weeks. + + To deploy this build, update the CLI images in the corresponding YAML files under res folder. + Then run: + \`\`\`bash + USER=netobserv VERSION=${{ env.short_sha }} make oc-commands + \`\`\` + ` + }) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..129b55db --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: release to quay.io +on: + push: + tags: [v*] + +env: + WF_REGISTRY_USER: netobserv+github_ci + WF_ORG: netobserv + WF_MULTIARCH_TARGETS: amd64 arm64 ppc64le s390x + +jobs: + push-image: + name: push image + runs-on: ubuntu-latest + strategy: + matrix: + go: ['1.21'] + steps: + - name: checkout + uses: actions/checkout@v3 + - name: validate tag + run: | + tag=`git describe --exact-match --tags 2> /dev/null` + if [[ $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then + echo "$tag is a valid release tag" + set -e + echo "tag=$tag" >> $GITHUB_ENV + else + echo "$tag is NOT a valid release tag" + exit 1 + fi + - name: install make + run: sudo apt-get install make + - name: set up go 1.x + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + - name: docker login to quay.io + uses: docker/login-action@v2 + with: + username: ${{ env.WF_REGISTRY_USER }} + password: ${{ secrets.QUAY_SECRET }} + registry: quay.io + - name: build and push manifest with images + run: MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.tag }} make images diff --git a/.github/workflows/rm-ok-to-test.yaml b/.github/workflows/rm-ok-to-test.yaml new file mode 100644 index 00000000..2688d0c6 --- /dev/null +++ b/.github/workflows/rm-ok-to-test.yaml @@ -0,0 +1,15 @@ +name: Remove ok-to-test +on: + pull_request_target: + types: [synchronize,reopened] + +jobs: + rm-ok-to-test: + if: contains(github.event.pull_request.labels.*.name, 'ok-to-test') + runs-on: ubuntu-latest + name: Remove ok-to-test + steps: + - uses: actions-ecosystem/action-remove-labels@v1 + with: + labels: ok-to-test + fail_on_error: true diff --git a/Makefile b/Makefile index 9ed1d030..bb12cdbe 100644 --- a/Makefile +++ b/Makefile @@ -79,10 +79,17 @@ prereqs: ## Test if prerequisites are met, and installing missing dependencies ##@ Develop .PHONY: compile -compile: +compile: ## Compile project @echo "### Compiling project" GOARCH=${GOARCH} go build -ldflags "-X main.version=${VERSION} -X 'main.buildVersion=${BUILD_VERSION}' -X 'main.buildDate=${BUILD_DATE}'" -mod vendor -a -o $(OUTPUT) +.PHONY: build +build: fmt lint compile ## Build project (fmt + lint + compile) + +.PHONY: test +test: ## Unit test + @echo "### TODO, unit tests not yet implemented" + .PHONY: fmt fmt: ## Run go fmt against code. @echo "### Formatting code" @@ -100,7 +107,7 @@ clean: .PHONY: oc-commands oc-commands: ## Generate oc plugins and add them to /usr/bin/ @echo "### Generating oc-commands" - ./scripts/inject.sh $(DIST_DIR) + ./scripts/inject.sh $(DIST_DIR) $(IMAGE) sudo cp -a ./build/. /usr/bin/ ##@ Images diff --git a/scripts/inject.sh b/scripts/inject.sh index ae06f4f0..c3e66a65 100755 --- a/scripts/inject.sh +++ b/scripts/inject.sh @@ -9,6 +9,13 @@ sed -i -e '/flowAgentYAMLContent/{r ./res/flow-capture.yml' -e 'd}' ./tmp/functi sed -i -e '/packetAgentYAMLContent/{r ./res/packet-capture.yml' -e 'd}' ./tmp/functions.sh sed -i -e '/collectorServiceYAMLContent/{r ./res/collector-service.yml' -e 'd}' ./tmp/functions.sh +if [ -z "$2" ]; then + echo "image not provided, keeping current ones" +else + echo "updating CLI images to $2" + sed -i "/ image:/c\ image: $2" ./tmp/functions.sh +fi + # inject updated functions to oc commands sed -i -e '/source.*/{r ./tmp/functions.sh' -e 'd}' ./tmp/oc-netobserv-flows sed -i -e '/source.*/{r ./tmp/functions.sh' -e 'd}' ./tmp/oc-netobserv-packets