Skip to content

Conversation

nerdeveloper
Copy link
Contributor

@nerdeveloper nerdeveloper commented Oct 5, 2025

Summary

This PR refactors the sampleexternalplugin from outdated mock scaffolding into a realistic, working reference implementation that demonstrates best practices for external plugin development.

Problem

The current sampleexternalplugin (issue #4824) had several issues:

  • ❌ Mock scaffolding that created useless text files (initFile.txt, apiFile.txt)
  • ❌ Didn't use PROJECT config or align with internal plugin architecture
  • ❌ Used release module instead of local source for testing
  • ❌ Not a realistic example for plugin developers

Solution

Transformed the plugin into a Prometheus Monitoring Generator that:

  • ✅ Uses edit subcommand to add optional Prometheus monitoring features
  • ✅ Reads PROJECT config for domain and project metadata
  • ✅ Generates real ServiceMonitor YAML manifests
  • ✅ Uses local Kubebuilder source via replace directive
  • ✅ Follows internal plugin architecture patterns

Changes

Plugin Functionality

  • Removed: Mock init, create api, create webhook subcommands
  • Added: Realistic edit subcommand that scaffolds Prometheus monitoring
  • Implements: PROJECT config reading (domain, projectName, repo)
  • Generates:
    • config/prometheus/monitor.yaml - ServiceMonitor resource
    • config/prometheus/kustomization.yaml - Kustomize config
    • config/default/kustomization_prometheus_patch.yaml - Integration instructions

Code Quality

  • Uses config.Config APIs like internal plugins
  • Proper Universe pattern for file scaffolding
  • Local source replace directive: replace sigs.k8s.io/kubebuilder/v4 => ../../../../../../../

Documentation

  • Updated external-plugins.md with realistic edit command examples
  • Changed examples from mock init/api/webhook to real Prometheus monitoring use case

Usage Example

# Add Prometheus monitoring to your operator project
kubebuilder edit --plugins sampleexternalplugin/v1

This will scaffold:

  • Prometheus ServiceMonitor configuration
  • Kustomize resources for monitoring
  • Integration instructions

Testing

  • ✅ Plugin builds successfully with local source
  • ✅ All mock files removed, real templates in place
  • ✅ Documentation reflects new usage

Impact

This PR makes the sample plugin a proper reference that:

  • Shows how to read PROJECT config in external plugins
  • Demonstrates real-world use case (optional monitoring features)
  • Allows contributors to test against local Kubebuilder source
  • Aligns with internal plugin architecture patterns

Fixes #4824

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @nerdeveloper. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 5, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: nerdeveloper
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 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

@nerdeveloper nerdeveloper force-pushed the refactor-sampleexternalplugin-issue-4824 branch from 63b82e0 to edc4046 Compare October 5, 2025 14:51
@nerdeveloper nerdeveloper changed the title ✨ Refactor sampleexternalplugin to be a Valid Reference Implementation Refactor sampleexternalplugin to be a Valid Reference Implementation Oct 5, 2025
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 5, 2025
Transform the sample external plugin from mock scaffolding to a realistic
working example that demonstrates best practices for external plugin development.

Changes:
- Replace mock init/create api/webhook commands with meaningful edit command
- Add Prometheus ServiceMonitor scaffolding for operator monitoring
- Implement PROJECT config reading to align with internal plugin patterns
- Add local source replace directive for contributor testing
- Update documentation to reflect realistic plugin usage

The plugin now serves as a proper reference for:
- Reading PROJECT config in external plugins
- Scaffolding real, production-ready configurations
- Testing plugins against local Kubebuilder source
- Adding optional features via the edit subcommand
- Change ProjectConfig tags from json to yaml for correct unmarshaling
- Unmarshal directly into ProjectConfig struct instead of config.Config interface
- Fix fmt.Sprintf template to pass domain twice for both Service and ServiceMonitor labels
- Remove unused config import
- Tested plugin successfully generates correct Prometheus monitoring files
…ustomization, update PROJECT file handling, and improve test script
@nerdeveloper nerdeveloper force-pushed the refactor-sampleexternalplugin-issue-4824 branch from d42c0be to 5395def Compare October 5, 2025 16:48
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Oct 5, 2025
@vitorfloriano
Copy link
Contributor

Hi @nerdeveloper thanks for the PR! This is a large one and will take some time to review. While you wait for the review, could you please adjust the title so it follows the guidelines for PR titles? Also, could you squash the four commits into one just so we keep the rule of a single commit per PR? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sampleexternalplugin a Valid Reference Implementation
3 participants