Skip to content
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

Refactor Build Status fields #536

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions deploy/crds/build.dev_builds_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,13 @@ spec:
status:
description: BuildStatus defines the observed state of Build
properties:
message:
description: The message of the registered Build, either an error
or succeed message
type: string
reason:
description: The reason of the registered Build, either an error or
succeed message
description: The reason of the registered Build, it's an one-word
camelcase
type: string
registered:
description: The Register status of the Build
Expand Down
17 changes: 17 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SPDX-License-Identifier: Apache-2.0

- [Overview](#overview)
- [Build Controller](#build-controller)
- [Build Validations](#build-validations)
- [Configuring a Build](#configuring-a-build)
- [Defining the Source](#defining-the-source)
- [Defining the Strategy](#defining-the-strategy)
Expand Down Expand Up @@ -40,6 +41,22 @@ When the controller reconciles it:
- Validates if the container `registry` output secret exists.
- Validates if the referenced `spec.source.url` endpoint exists.

## Build Validations

In order to prevent users from triggering `BuildRuns` (_execution of a Build_) that will eventually fail because of wrong or missing dependencies or configuration settings, the Build controller will validate them in advance. If all validations are successful, users can expect a `Succeeded` `Status.Reason`, however if any of the validations failed, users can rely on the `Status.Reason` and `Status.Message` fields, in order to understand the root cause.

| Status.Reason | Description |
| --- | --- |
| BuildStrategyNotFound | The referenced namespace-scope strategy doesn´t exist. |
| ClusterBuildStrategyNotFound | The referenced cluster-scope strategy doesn´t exist. |
| SetOwnerReferenceFailed | Setting ownerreferences between a Build and a BuildRun failed. This is triggered when making use of the `build.build.dev/build-run-deletion` annotation in a Build. |
| SpecSourceSecretNotFound | The secret used to authenticate to git doesn´t exist. |
| SpecOutputSecretRefNotFound | The secret used to authenticate to the container registry doesn´t exist. |
| SpecRuntimeSecretRefNotFound | The secret used to authenticate to the container registry doesn´t exist.|
| MultipleSecretRefNotFound | More than one secret is missing. At the moment, only three paths on a Build can specify a secret. |
| RuntimePathsCanNotBeEmpty | The Runtime feature is used, but the runtime path was not defined. This is mandatory. |
| RemoteRepositoryUnreachable | The defined `spec.source.url` was not found. This validation only take place for http/https protocols. |

## Configuring a Build

The `Build` definition supports the following fields:
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
github.com/operator-framework/operator-sdk v0.18.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.8.0
github.com/prometheus/client_model v0.2.0
github.com/spf13/pflag v1.0.5
Expand Down
37 changes: 35 additions & 2 deletions pkg/apis/build/v1alpha1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// BuildReason is a type used for populating the
// Build Status.Reason field
type BuildReason string

const (
// SucceedStatus indicates that all validations Succeeded
Copy link
Member

Choose a reason for hiding this comment

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

A nit comment, we should add a new line after each attribute, following the other attributes described in the same package.

SucceedStatus BuildReason = "Succeeded"
// BuildStrategyNotFound indicates that a namespaced-scope strategy was not found in the namespace
BuildStrategyNotFound BuildReason = "BuildStrategyNotFound"
// ClusterBuildStrategyNotFound indicates that a cluster-scope strategy was not found
ClusterBuildStrategyNotFound BuildReason = "ClusterBuildStrategyNotFound"
// SetOwnerReferenceFailed indicates that setting ownerReferences between a Build and a BuildRun failed
SetOwnerReferenceFailed BuildReason = "SetOwnerReferenceFailed"
// SpecSourceSecretRefNotFound indicates the referenced secret in source is missing
SpecSourceSecretRefNotFound BuildReason = "SpecSourceSecretRefNotFound"
// SpecOutputSecretRefNotFound indicates the referenced secret in output is missing
SpecOutputSecretRefNotFound BuildReason = "SpecOutputSecretRefNotFound"
// SpecRuntimeSecretRefNotFound indicates the referenced secret in runtime is missing
SpecRuntimeSecretRefNotFound BuildReason = "SpecRuntimeSecretRefNotFound"
// MultipleSecretRefNotFound indicates that multiple secrets are missing
MultipleSecretRefNotFound BuildReason = "MultipleSecretRefNotFound"
// RuntimePathsCanNotBeEmpty indicates that the spec.runtime feature is used but the paths were not specified
RuntimePathsCanNotBeEmpty BuildReason = "RuntimePathsCanNotBeEmpty"
// RemoteRepositoryUnreachable indicates the referenced repository is unreachable
RemoteRepositoryUnreachable BuildReason = "RemoteRepositoryUnreachable"
// AllValidationsSucceeded indicates a Build was successfully validated
AllValidationsSucceeded = "all validations succeeded"
)

const (
// BuildDomain is the domain used for all labels and annotations for this resource
BuildDomain = "build.build.dev"
Expand Down Expand Up @@ -135,9 +164,13 @@ type BuildStatus struct {
// +optional
Registered corev1.ConditionStatus `json:"registered,omitempty"`

// The reason of the registered Build, either an error or succeed message
// The reason of the registered Build, it's an one-word camelcase
// +optional
Reason BuildReason `json:"reason,omitempty"`

// The message of the registered Build, either an error or succeed message
// +optional
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
}

// +genclient
Expand Down