Skip to content

refactor: extract business logic to service package#144

Merged
arielsepton merged 7 commits intocrossplane-contrib:mainfrom
arielsepton:refactor/extract-business-logic-to-service-package
Nov 17, 2025
Merged

refactor: extract business logic to service package#144
arielsepton merged 7 commits intocrossplane-contrib:mainfrom
arielsepton:refactor/extract-business-logic-to-service-package

Conversation

@arielsepton
Copy link
Member

Description

This PR refactors the HTTP provider to extract business logic from controllers into a dedicated service layer. This architectural change prepares the codebase to support namespace-scoped resources in Crossplane v2 by making the core HTTP request/response logic reusable across both cluster-scoped and namespace-scoped resource controllers.

Related to #141

Changes

Core Refactoring

  • Extracted business logic to service layer: Moved HTTP request processing, observation, and action deployment logic from internal/controller to internal/service
  • Introduced common interfaces: Created apis/interfaces/spec_accessors.go with interfaces (HTTPRequestSpec, SimpleHTTPRequestSpec, MappedHTTPRequestSpec) that abstract differences between Request and DisposableRequest types
  • Spec accessor implementations: Added spec accessor methods for all resource versions (v1alpha1, v1alpha2) for both Request and DisposableRequest types

Service Package Structure

New internal/service package with resource-specific subdirectories:

  • internal/service/request/ - Request resource business logic
    • deployaction.go - Action deployment (create/update/delete)
    • observe.go - Observation and up-to-date checking
    • Moved observation helpers: observe/, requestgen/, requestmapping/, statushandler/
  • internal/service/disposablerequest/ - DisposableRequest resource business logic
    • deployaction.go - Action deployment
    • observe.go - Observation logic
    • validation.go - Validation logic

Controller Simplification

Controllers now delegate to service layer functions:

  • internal/controller/request/request.go - Reduced from ~750 to ~40 lines of business logic
  • internal/controller/disposablerequest/disposablerequest.go - Simplified significantly
  • Removed observe.go, responseconverter/ from controllers (moved to service layer)

Testing

  • Existing unit tests updated to use new service layer functions
  • All tests pass with refactored code

Signed-off-by: arielsepton <arielsepton1@gmail.com>
Resolved conflicts in disposablerequest controller by keeping refactored
service layer implementation. All business logic has been moved to
internal/service/disposablerequest package.

Signed-off-by: arielsepton <arielsepton1@gmail.com>
@arielsepton arielsepton force-pushed the refactor/extract-business-logic-to-service-package branch from 76ff3e2 to adaf4ff Compare November 14, 2025 13:31
arielsepton and others added 2 commits November 14, 2025 18:49
…vices

Signed-off-by: Ariel Septon <64063409+arielsepton@users.noreply.github.com>
…, headers, body, and error

Signed-off-by: arielsepton <arielsepton1@gmail.com>
@arielsepton arielsepton force-pushed the refactor/extract-business-logic-to-service-package branch 3 times, most recently from 5ff806a to 127fd45 Compare November 14, 2025 21:08
…idation

Signed-off-by: arielsepton <arielsepton1@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the HTTP provider to extract business logic from controllers into a dedicated service layer. The refactoring introduces common interfaces to abstract differences between Request and DisposableRequest types, enabling code reuse and preparing the codebase for Crossplane v2 namespace-scoped resources support.

Key Changes:

  • Introduced interface-based abstraction layer in apis/interfaces/spec_accessors.go with implementations across all API versions
  • Extracted business logic from controllers to new internal/service package with resource-specific subdirectories
  • Simplified controllers to delegate to service layer functions, reducing code duplication

Reviewed Changes

Copilot reviewed 43 out of 45 changed files in this pull request and generated no comments.

Show a summary per file
File Description
apis/interfaces/spec_accessors.go Defines common interfaces for HTTP request specs, responses, and status management
apis/*/spec_accessors.go Implements interface methods for all API versions (v1alpha1, v1alpha2)
apis/common/constants.go Centralizes action and response check type constants
internal/service/request/*.go Request resource business logic (observe, deploy, status handling)
internal/service/disposablerequest/*.go DisposableRequest resource business logic (observe, deploy, validation)
internal/controller/*/*.go Simplified controllers delegating to service layer
internal/utils/set_status.go Updated to use new interfaces instead of local types
internal/data-patcher/patch.go Updated to work with interface types
internal/clients/http/client.go Added HTTPResponse interface implementation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@ricCap ricCap left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes

Signed-off-by: arielsepton <arielsepton1@gmail.com>
Signed-off-by: arielsepton <arielsepton1@gmail.com>
@arielsepton arielsepton force-pushed the refactor/extract-business-logic-to-service-package branch from 830a7a0 to 6add0b4 Compare November 15, 2025 13:11
@arielsepton arielsepton merged commit 2cf5fc8 into crossplane-contrib:main Nov 17, 2025
7 checks passed
barunavo pushed a commit to barunavo/provider-http that referenced this pull request Nov 17, 2025
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.

3 participants