application

package
v0.8.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

This file owns BackendSelector — the routing layer that maps a resolved BuildSpec to the correct build provider (Buildah, Kaniko, or Buildpacks).

Selection is driven by the StrategyName field using substring matching so variant strategy names ("buildah-rootless", "kaniko-insecure") route correctly without an exhaustive switch. Buildah is the fallback for unrecognised names.

BackendSelector sits in the application layer — it is called by the build application service after resolution and before provider dispatch.

This file owns the Mapper — the translation layer between the resolved Build contract and the domain BuildSpec consumed by the provider layer.

The Mapper is declarative: it carries over what the contract declares and adds nothing. Fields resolution guarantees (Source.URL, Strategy.Name, Strategy.StrategyKind) are checked again and reported as errors, never as a panic, so a caller that bypasses resolution gets a failed build rather than a crashed controller.

Optional fields (ServiceAccount, CloneSecret) are passed through verbatim.

This file owns BuildService — the application service that orchestrates the build reconciliation pipeline.

BuildService is the single entry point called by the build domain after resolution. It sequences four steps in order:

  1. Map the resolved Build contract to a domain BuildSpec (Mapper).
  2. Select the correct build provider for the strategy (BackendSelector).
  3. Dispatch execution via the provider (Provider.Run).
  4. Write the outcome back to the Build CR status (StatusWriter).

BuildService does not own retry logic, trigger evaluation, or condition management — those belong to the domain and observer layers respectively.

Copyright 2026 The BlanketOps Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This file owns the StatusWriter — the persistence boundary between the Build domain's in-memory conditions and the CR status subresource. The StatusWriter is deliberately dumb: it does not derive conditions, manage contract state, or preserve domain flags. Condition semantics belong to the domain; this writer only merges what it is handed and persists it. The one concern it does own is write safety under concurrency — the Build status has two writers (the build reconciler and the buildrun-observer, per the CQRS split), so every persist is conflict-retried against a fresh read.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendSelector

type BackendSelector struct {
	Buildah    api.Provider
	Kaniko     api.Provider
	Buildpacks api.Provider
}

BackendSelector routes a BuildSpec to the correct Provider implementation based on the strategy name. All three providers must be non-nil at construction time.

func NewBackendSelector

func NewBackendSelector(buildah api.Provider, kaniko api.Provider, buildpacks api.Provider) *BackendSelector

NewBackendSelector constructs a BackendSelector with the three registered build providers.

func (*BackendSelector) ForSpec

func (b *BackendSelector) ForSpec(spec domain.BuildSpec) api.Provider

ForSpec returns the Provider that should execute the given BuildSpec. The first substring match against StrategyName wins. Buildah is returned for any unrecognised strategy name.

type BuildService

type BuildService struct {
	// contains filtered or unexported fields
}

BuildService orchestrates the build reconciliation pipeline. It is stateless beyond its collaborators and safe for concurrent use.

func NewBuildService

func NewBuildService(mapper *Mapper, status *StatusWriter, backend *BackendSelector) *BuildService

NewBuildService constructs a BuildService with the required collaborators.

func (*BuildService) Reconcile

func (s *BuildService) Reconcile(ctx context.Context, resolved *bldResolution.ResolvedBuild) error

Reconcile executes the full build pipeline for a resolved Build CR. It maps, selects, executes, and writes status in sequence. An error from any stage is forwarded to StatusWriter so the Build CR always reflects the latest outcome, even on failure.

func (*BuildService) Teardown

func (s *BuildService) Teardown(ctx context.Context, resolved *bldResolution.ResolvedBuild) error

Teardown reverses Reconcile — maps the resolved Build, selects the same backend provider strategy would have used, and dispatches Teardown to delete the owned BuildRun(s) and Build.

type Mapper

type Mapper struct{}

Mapper translates a ResolvedBuild into a domain.BuildSpec.

func NewMapper

func NewMapper() *Mapper

NewMapper constructs a Mapper.

func (Mapper) MapResolvedToDomain

func (Mapper) MapResolvedToDomain(rb *bldResolution.ResolvedBuild) (domain.BuildSpec, error)

MapResolvedToDomain converts a fully resolved Build into a domain BuildSpec for consumption by the provider layer.

It returns an error wrapping domain.ErrInvalidBuild when the resolved Build is missing something resolution should have required. All other fields are mapped verbatim.

StrategyKind is translated from the contract's spelling to the Shipwright kind the providers write: a namespaced strategy is a Shipwright "BuildStrategy".

type StatusWriter

type StatusWriter struct {
	// Client is the Kubernetes client used for status reads and writes.
	Client client.Client
	// Log is the logger instance for this writer.
	Log logr.Logger
}

StatusWriter persists Build conditions to the CR status. It does NOT derive conditions, manage contract state, or preserve domain flags. Callers pass the Build CR with conditions already set; this writer merges and persists.

func NewStatusWriter

func NewStatusWriter(c client.Client, log logr.Logger) *StatusWriter

NewStatusWriter constructs a StatusWriter.

func (*StatusWriter) Write

func (w *StatusWriter) Write(ctx context.Context, build *buildv1.Build, conditions ...metav1.Condition) error

Write merges the provided conditions into the Build CR status and persists. Uses RetryOnConflict + re-fetch on each attempt — the buildrun-observer writes BuildSuccess concurrently which bumps resourceVersion between the reconciler's initial fetch and this write, causing conflicts. Re-fetching on every retry attempt guarantees we always write to the latest version.

The caller's Build object is used only as a lookup key for its conditions — its local status is NOT refreshed from the re-fetched latest version. The one exception is Status.Contract: if the caller has populated it (buildrun-observer does, to carry ExecutionRef/BuildHash/Success/Triggered for build-observer's applyRetry to read back), it is persisted verbatim alongside the conditions. Callers that leave Contract empty (the primary BuildService.Reconcile path today) see no change in behavior.

func (*StatusWriter) WriteReplacing

func (w *StatusWriter) WriteReplacing(ctx context.Context, build *buildv1.Build, superseded []string, conditions ...metav1.Condition) error

WriteReplacing behaves like Write and, in the same update, removes the condition types listed in superseded. Use it when the conditions being written make earlier ones false: a succeeded run supersedes BuildFailed, a failed run supersedes BuildSuccess. Merging alone would leave both on the Build. A type that is also in conditions is written, not removed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL