Skip to content

🌱 Add test-operator with custom controller #2070

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

perdasilva
Copy link
Contributor

@perdasilva perdasilva commented Jul 3, 2025

Depends on #2080

Description

Adds the scaffolding for the test-operator in versions v1 and v2 using operator-sdk. The test-operator is a basic echo service.

The test-operator supports AllNamespaces, SingleNamespace, and OwnNamespace install modes.
v1.0.0: is just the crd and the existing configmap resource
v1.3.0: has the same crd as v1.0.0 and the updated configmap previously part of v2.0.0
v2.0.0: has validating, mutating and conversion webhooks

I've had to modify an e2e that expected v2.0.0 of the test operator to be installed since v2 now includes webhooks and support is not enabled by default (yet). I've added a v1.3.0 as a stand-in for the previous v2 and updated the catalogs accordingly.

Because the test-operator now has its own controller, I've also had to update testdata/push to handle the controller image building/pushing

As it is, the test-operator should make a good fixture for testing the Single/OwnNamespace and Webhook support features.

Thing we should feel confident in doing in the future

  • Producing different kinds of bundles: helm, registry+v2, etc.
  • Adding more bundles (though we probably want to keep the general number low)

Risks

  • Dependency (CRD) between v1 and v2, i.e. changes in v1 might need to be carried forward to v2

v1

A reconciled test-operator v1 resource would look like this:

apiVersion: testolm.operator-framework.io/v1
kind: TestOperator
metadata:
  name: test-operator
spec:
  message: "hello"
status:
  echo: "hello"

The v1 operator also includes a validating and mutating webhook. The validating webhook validates .spec.message against a keyword and rejects admission if its found. The mutating webhook is used as a "defaulting" webhook that sets .spec.message to the default message of Echo.

v2

A reconciled test-operator v2 resource would look like this:

apiVersion: testolm.operator-framework.io/v2
kind: TestOperator
metadata:
  name: test-operator
spec:
  echoMessage: "hello"
status:
  echo: "hello"

The same webhooks are available for v2 apis + a conversion webhook to support the CRD upgrade.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 3, 2025
Copy link

openshift-ci bot commented Jul 3, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign perdasilva for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

netlify bot commented Jul 3, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 2396e27
🔍 Latest deploy log https://app.netlify.com/projects/olmv1/deploys/686d46377b151d0008637606
😎 Deploy Preview https://deploy-preview-2070--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.38%. Comparing base (eb4b979) to head (2396e27).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2070      +/-   ##
==========================================
+ Coverage   73.33%   73.38%   +0.05%     
==========================================
  Files          77       77              
  Lines        7076     7076              
==========================================
+ Hits         5189     5193       +4     
+ Misses       1545     1542       -3     
+ Partials      342      341       -1     
Flag Coverage Δ
e2e 44.87% <ø> (-0.04%) ⬇️
experimental-e2e 51.12% <ø> (-0.04%) ⬇️
unit 58.38% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@perdasilva perdasilva changed the title In-tree test operator 🌱 In-tree test operator Jul 3, 2025
@perdasilva perdasilva force-pushed the test-operator branch 23 times, most recently from 3fb8ef7 to 693a355 Compare July 8, 2025 16:09
Per Goncalves da Silva added 2 commits July 8, 2025 18:23
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
Per Goncalves da Silva added 2 commits July 8, 2025 18:23
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
@perdasilva perdasilva changed the title 🌱 In-tree test operator 🌱 Add test-operator with custom controller Jul 8, 2025
@perdasilva perdasilva marked this pull request as ready for review July 8, 2025 16:25
@perdasilva perdasilva requested a review from a team as a code owner July 8, 2025 16:25
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2025
@openshift-ci openshift-ci bot requested review from gavinmbell and OchiengEd July 8, 2025 16:25
@@ -246,11 +246,18 @@ test-unit: $(SETUP_ENVTEST) envtest-k8s-bins #HELP Run the unit tests
$(UNIT_TEST_DIRS) \
-test.gocoverdir=$(COVERAGE_UNIT_DIR)

TEST_OPERATOR_CONTROLLERS_HOME=./testdata/images/controllers
TEST_OPERATOR_CONTROLLERS=v1.0.0 v2.0.0
Copy link
Contributor

@tmshort tmshort Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing v1.3.0? Or is it not needed because it's not actually built?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tests even run?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tests even run?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Are these tests even run?

Comment on lines +211 to +213
if _, err := w.Write(fileBytes); err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we concerned about filesize here? In that we only read/write once per file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants