Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Improve Operator Reconciliation #1496

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 16 additions & 27 deletions .github/workflows/check-file-updates.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
name: Check config and readme updates
on:
pull_request_target:
pull_request:
jobs:
file-updates:
permissions:
pull-requests: write
name: Ensure generated files are included
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.2.2
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Generate files
id: generate-files
- name: Save the PR number for artifact upload
run: |
CMD="make generate manifests api-docs"
$CMD
echo "CMD=$CMD" >> $GITHUB_OUTPUT
echo ${{ github.event.number }} > pr_number.txt
- name: Upload the PR number as artifact
id: artifact-upload
uses: actions/upload-artifact@v4
with:
name: pr_number
path: ./pr_number.txt
retention-days: 1 # This will delete the generated artifacts every day.
- name: Generate files
run: make generate manifests api-docs
- name: Ensure generated files are up-to-date
id: check_generated_files
run : |
rm ./pr_number.txt # remove the pr_number.txt before checking "git status", to have correct assessment of the changed files.
if [[ -n $(git status -s) ]]
then
echo "Generated files have been missed in the PR"
git diff
echo "missing_generated_files=true" >> $GITHUB_OUTPUT
exit 1
else
echo "No new files to commit"
echo "missing_generated_files=false" >> $GITHUB_OUTPUT
fi
- name: Report issue in PR
if: ${{ steps.check_generated_files.outputs.missing_generated_files == 'true' }}
uses: thollander/actions-comment-pull-request@v2
with:
message: |
## This PR can't be merged just yet 😢

Please run `${{ steps.generate-files.outputs.CMD }}` and commit the changes.

For more info: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Print git status and fail pr
if: ${{ steps.check_generated_files.outputs.missing_generated_files == 'true' }}
run: |
git status
exit 1
fi
59 changes: 59 additions & 0 deletions .github/workflows/comment-on-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Comment on pr
on:
workflow_run:
workflows: ["Check config and readme updates"]
types:
- completed
jobs:
download-artifact-data:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.artifact-data.outputs.pr_number }}
steps:
- name: Download artifact
id: artifact-download
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});

let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];

let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
- name: Unzip artifact
run: unzip pr_number.zip
- name: Extract data
id: artifact-data
run: |
echo "pr_number=$(head -n 1 pr_number.txt)" >> $GITHUB_OUTPUT
comment-on-pr:
needs:
- download-artifact-data
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Report issue in PR
uses: thollander/actions-comment-pull-request@v3.0.1
with:
message: |
## This PR can't be merged just yet 😢

Please run `make generate manifests api-docs` and commit the changes.

For more info: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}
pr-number: ${{ needs.download-artifact-data.outputs.pr_number }}
12 changes: 7 additions & 5 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
- main
- incubation
pull_request:
permissions:
contents: read
pull-requests: read
checks: write
jobs:
golangci:
name: golangci-lint
Expand All @@ -15,8 +19,6 @@ jobs:
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60.2
args: --timeout 5m0s
- name: lint
run:
make lint
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Unit Tests
on:
on:
push:
branches:
- rhoai
Expand All @@ -21,6 +21,6 @@ jobs:
run: make unit-test

- name: Upload results to Codecov
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.1.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
23 changes: 20 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ linters-settings:
- stdlib
# also allow generics
- generic
- EventHandler # for ToOwner
- discovery.DiscoveryInterface
- dynamic.Interface
- predicate.Predicate
- client.Object
- common.PlatformObject
- types.AsyncAssertion
- kubernetes.Interface
revive:
rules:
- name: dot-imports
Expand All @@ -66,6 +74,12 @@ linters-settings:
perfsprint:
sprintf1: false
strconcat: false
# Enable gocritic for detecting bugs, performance, and style issues: https://golangci-lint.run/usage/linters/#gocritic
gocritic:
# https://go-critic.com/overview.html#checkers
enabled-checks:
- deferInLoop
- unnecessaryDefer

linters:
enable-all: true
Expand All @@ -75,7 +89,6 @@ linters:
- forbidigo
- gochecknoglobals # Prevents use of global vars.
- gofumpt
- gomnd # Doesnot allow hardcoded numbers
- gomoddirectives # Doesnot allow replace in go mod file
- mnd
- nestif
Expand All @@ -85,11 +98,12 @@ linters:
- varnamelen # doesnot allow shorter names like c,k etc. But golang prefers short named vars.
- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
- wrapcheck # check if this is required. Prevents direct return of err.
- exportloopref # Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.

# Need to check
- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
- err113 # [too strict] checks the errors handling expressions

# To be fixed
- gocognit # https://github.com/opendatahub-io/opendatahub-operator/issues/709
- cyclop # https://github.com/opendatahub-io/opendatahub-operator/issues/709
Expand All @@ -103,4 +117,7 @@ issues:
- path: tests/*/(.+)_test\.go
linters:
- typecheck
- dupl
- dupl
- path: pkg/utils/test/testf/(.+)\.go
linters:
- containedctx
1 change: 0 additions & 1 deletion Dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ RUN go mod download

# Copy the go source
COPY apis/ apis/
COPY components/ components/
COPY controllers/ controllers/
COPY main.go main.go
COPY pkg/ pkg/
Expand Down
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 2.16.0
VERSION ?= 2.17.0
# IMAGE_TAG_BASE defines the opendatahub.io namespace and part of the image name for remote images.
# This variable is used to construct full image tags for bundle and catalog images.
#
Expand Down Expand Up @@ -69,7 +69,7 @@ YQ ?= $(LOCALBIN)/yq
KUSTOMIZE_VERSION ?= v5.0.2
CONTROLLER_GEN_VERSION ?= v0.16.1
OPERATOR_SDK_VERSION ?= v1.31.0
GOLANGCI_LINT_VERSION ?= v1.61.0
GOLANGCI_LINT_VERSION ?= v1.63.4
YQ_VERSION ?= v4.12.2
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.31.0
Expand All @@ -89,7 +89,8 @@ SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# E2E tests additional flags
E2E_TEST_FLAGS = "--skip-deletion=false" -timeout 25m # See README.md, default go test timeout 10m
# See README.md, default go test timeout 10m
E2E_TEST_FLAGS = -timeout 40m

# Default image-build is to not use local odh-manifests folder
# set to "true" to use local instead
Expand Down Expand Up @@ -170,8 +171,13 @@ CLEANFILES += $(GOLANGCI_TMP_FILE)
vet: ## Run go vet against code.
go vet ./...

GOLANGCI_LINT_TIMEOUT ?= 5m0s
.PHONY: lint
lint: golangci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run --timeout=$(GOLANGCI_LINT_TIMEOUT) --sort-results

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run --fix --sort-results

.PHONY: get-manifests
Expand All @@ -198,7 +204,10 @@ run: manifests generate fmt vet ## Run a controller from your host.

.PHONY: run-nowebhook
run-nowebhook: GO_RUN_ARGS += -tags nowebhook
run-nowebhook: run ## Run a controller from your host without webhook enabled

run-nowebhook: manifests generate fmt vet ## Run a controller from your host without webhook enabled
$(GO_RUN_MAIN)


.PHONY: image-build
image-build: # unit-test ## Build image with the manager.
Expand Down
Loading
Loading