Skip to content

Commit 1b86d12

Browse files
ci: add maas-controller CI workflow and remove obsolete image build from maas-api (opendatahub-io#656)
## Summary Add a dedicated GitHub Actions CI workflow for maas-controller and remove obsolete image build/push steps from the maas-api CI workflow. Ref - https://redhat.atlassian.net/browse/RHOAIENG-52494 ## Description - Add `.github/workflows/maas-controller-ci.yml` with lint and test jobs triggered on PRs to `maas-controller/**`. - Go version and golangci-lint version are resolved dynamically from `go.mod` and `tools.mk`. - Coverage artifacts (`coverage.out`, `coverage.html`) are uploaded on every run. - Remove the `Build image` step and `push`-on-merge trigger from `maas-api-ci.yml` — container builds are now handled by Konflux. - Rename the maas-api `build` job to `test` to reflect its actual purpose. - Update maas-controller Makefile test target to produce coverage output (`-race -coverprofile`) consistent with maas-api. ## How it was tested - Ran `make lint` and `make test` locally for both maas-controller and maas-api — all tests pass. - Verified `coverage.out` and `coverage.html` are generated by the updated maas-controller test target. ## Merge criteria: <!--- This PR will be merged by any repository approver when it meets all the points in the checklist --> <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] The commits are squashed in a cohesive manner and have meaningful messages. - [x] Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious). - [x] The developer has manually tested the changes and verified that the changes work <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **CI/CD** * CI workflows updated: API workflow now runs tests only on pull requests; added a controller workflow with linting, testing, and coverage artifact uploads. Removed image build step and pinned action versions for reproducible runs. * **Tests** * Test helpers made safer to avoid panics; test target now produces coverage output and HTML. * **Bug Fixes** * Improved error wrapping/handling in parsing paths. * **Refactor** * Consistent data-structure usage and minor formatting improvements for maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Chaitanya Kulkarni <ckulkarn@redhat.com> Signed-off-by: Chaitanya Kulkarni <chkulkar@redhat.com>
1 parent 409b0a7 commit 1b86d12

File tree

14 files changed

+277
-148
lines changed

14 files changed

+277
-148
lines changed

.github/workflows/maas-api-ci.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: MaaS API
22

33
on:
4-
push:
5-
branches:
6-
- main
74
pull_request:
85
paths:
96
- 'maas-api/**'
@@ -24,31 +21,31 @@ jobs:
2421
lint:
2522
runs-on: ubuntu-latest
2623
steps:
27-
- uses: actions/checkout@v5
24+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
2825

2926
- name: Align golangci-lint version with Makefile
3027
id: golangci-version
3128
run: |
3229
VERSION=$(grep '^GOLANGCI_LINT_VERSION' tools.mk | cut -d'=' -f2 | tr -d ' ?')
3330
echo "version=$VERSION" >> $GITHUB_OUTPUT
3431
35-
- uses: actions/setup-go@v6
32+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
3633
with:
3734
go-version-file: maas-api/go.mod
3835
cache: true
3936
cache-dependency-path: maas-api/go.sum
4037

4138
- name: golangci-lint
42-
uses: golangci/golangci-lint-action@v9
39+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9
4340
with:
4441
version: ${{ steps.golangci-version.outputs.version }}
4542
working-directory: ${{ env.PROJECT_DIR }}
46-
build:
43+
test:
4744
runs-on: ubuntu-latest
4845
steps:
49-
- uses: actions/checkout@v5
46+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
5047

51-
- uses: actions/setup-go@v6
48+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
5249
with:
5350
go-version-file: ${{ env.PROJECT_DIR }}/go.mod
5451
cache: true
@@ -58,14 +55,11 @@ jobs:
5855
run: make test
5956

6057
- name: Upload coverage reports
61-
uses: actions/upload-artifact@v4
58+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
6259
if: always()
6360
with:
6461
name: coverage-reports
6562
path: |
6663
${{ env.PROJECT_DIR }}/coverage.out
6764
${{ env.PROJECT_DIR }}/coverage.html
6865
retention-days: 30
69-
70-
- name: Build image
71-
run: make build-image
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: MaaS Controller
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'maas-controller/**'
7+
8+
permissions:
9+
actions: read
10+
contents: read
11+
12+
env:
13+
PROJECT_DIR: maas-controller
14+
15+
defaults:
16+
17+
run:
18+
working-directory: maas-controller
19+
20+
jobs:
21+
lint:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
25+
26+
- name: Align golangci-lint version with Makefile
27+
id: golangci-version
28+
run: |
29+
VERSION=$(grep '^GOLANGCI_LINT_VERSION' tools.mk | cut -d'=' -f2 | tr -d ' ?')
30+
echo "version=$VERSION" >> $GITHUB_OUTPUT
31+
32+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
33+
with:
34+
go-version-file: maas-controller/go.mod
35+
cache: true
36+
cache-dependency-path: maas-controller/go.sum
37+
38+
- name: golangci-lint
39+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9
40+
with:
41+
version: ${{ steps.golangci-version.outputs.version }}
42+
working-directory: ${{ env.PROJECT_DIR }}
43+
44+
test:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
48+
49+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
50+
with:
51+
go-version-file: ${{ env.PROJECT_DIR }}/go.mod
52+
cache: true
53+
cache-dependency-path: ${{ env.PROJECT_DIR }}/go.sum
54+
55+
- name: Run tests
56+
run: make test
57+
58+
- name: Upload coverage reports
59+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
60+
if: always()
61+
with:
62+
name: maas-controller-coverage
63+
path: |
64+
${{ env.PROJECT_DIR }}/coverage.out
65+
${{ env.PROJECT_DIR }}/coverage.html
66+
retention-days: 30

maas-controller/.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ linters:
120120
- linters:
121121
- ireturn
122122
path: pkg/controller/maas/maassubscription_controller\.go
123+
- linters:
124+
- ireturn
125+
path: pkg/reconciler/externalmodel/reconciler\.go
123126
- linters:
124127
- modernize
125128
text: "(omitzero|mapsloop|rangeint):"

maas-controller/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ $(BUILD_DIR):
6464
run: build ## build and run manager locally
6565
$(BUILD_DIR)/$(BINARY_NAME)
6666

67+
TEST_FLAGS ?= -race -coverprofile=coverage.out
6768
.PHONY: test
68-
test: tidy ## run tests
69-
go test ./...
69+
test: tidy ## run tests with coverage
70+
go test $(TEST_FLAGS) ./...
71+
@go tool cover -html=coverage.out -o coverage.html
72+
@echo "Test coverage report generated: $(abspath coverage.html)"
7073

7174
.PHONY: tidy
7275
tidy:

maas-controller/cmd/manager/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ func main() {
218218
os.Exit(1)
219219
}
220220
if err := (&maas.MaaSAuthPolicyReconciler{
221-
Client: mgr.GetClient(),
222-
Scheme: mgr.GetScheme(),
223-
MaaSAPINamespace: maasAPINamespace,
224-
GatewayName: gatewayName,
225-
ClusterAudience: clusterAudience,
226-
MetadataCacheTTL: metadataCacheTTL,
227-
AuthzCacheTTL: authzCacheTTL,
221+
Client: mgr.GetClient(),
222+
Scheme: mgr.GetScheme(),
223+
MaaSAPINamespace: maasAPINamespace,
224+
GatewayName: gatewayName,
225+
ClusterAudience: clusterAudience,
226+
MetadataCacheTTL: metadataCacheTTL,
227+
AuthzCacheTTL: authzCacheTTL,
228228
}).SetupWithManager(mgr); err != nil {
229229
setupLog.Error(err, "unable to create controller", "controller", "MaaSAuthPolicy")
230230
os.Exit(1)

maas-controller/pkg/controller/maas/cross_namespace_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ func TestMaaSSubscriptionReconciler_CrossNamespace(t *testing.T) {
360360
WithObjects(modelA, routeA, modelB, routeB, maasSub).
361361
WithStatusSubresource(&maasv1alpha1.MaaSSubscription{}).
362362
WithIndex(&maasv1alpha1.MaaSSubscription{}, "spec.modelRef", func(obj client.Object) []string {
363-
sub := obj.(*maasv1alpha1.MaaSSubscription)
363+
sub, ok := obj.(*maasv1alpha1.MaaSSubscription)
364+
if !ok {
365+
return nil
366+
}
364367
var refs []string
365368
for _, modelRef := range sub.Spec.ModelRefs {
366369
refs = append(refs, modelRef.Namespace+"/"+modelRef.Name)

0 commit comments

Comments
 (0)