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

Add numerical policy to API docs #106

Merged
merged 1 commit into from
Feb 11, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/v1alpha1/imagepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ type ImagePolicyChoice struct {
Numerical *NumericalPolicy `json:"numerical,omitempty"`
}

// SemVerPolicy specifices a semantic version policy.
// SemVerPolicy specifies a semantic version policy.
type SemVerPolicy struct {
// Range gives a semver range for the image tag; the highest
// version within the range that's a tag yields the latest image.
// +required
Range string `json:"range"`
}

// AlphabeticalPolicy specifices a alphabetical ordering policy.
// AlphabeticalPolicy specifies a alphabetical ordering policy.
type AlphabeticalPolicy struct {
// Order specifies the sorting order of the tags. Given the letters of the
// alphabet as tags, ascending order would select Z, and descending order
Expand All @@ -76,7 +76,7 @@ type AlphabeticalPolicy struct {
Order string `json:"order,omitempty"`
}

// NumericalPolicy specifices a numerical ordering policy.
// NumericalPolicy specifies a numerical ordering policy.
type NumericalPolicy struct {
// Order specifies the sorting order of the tags. Given the integer values
// from 0 to 9 as tags, ascending order would select 9, and descending order
Expand Down
40 changes: 28 additions & 12 deletions docs/spec/v1alpha1/imagepolicies.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,56 @@ object that provides the scanned image metadata for the policy to use in selecti
The ImagePolicy field specifies how to choose a latest image given the image metadata. The choice is
between

- **SemVer**: interpreting all tags as semver versions, and choosing the highest version available
- **SemVer**: interpreting all tags as semver versions, and choosing the highest version available
that fits the given [semver constraints][semver-range]; or,
- **Alphabetical**: choosing the _last_ tag when all the tags are sorted alphabetically (in either
ascending or descending order).
- **Alphabetical**: choosing the _last_ tag when all the tags are sorted alphabetically (in either
ascending or descending order); or,
- **Numerical**: choosing the _last_ tag when all the tags are sorted numerically (in either
ascending or descending order).

```go
// ImagePolicyChoice is a union of all the types of policy that can be
// supplied.
// ImagePolicyChoice is a union of all the types of policy that can be supplied.
type ImagePolicyChoice struct {
// SemVer gives a semantic version range to check against the tags
// available.
// SemVer gives a semantic version range to check against the tags available.
// +optional
SemVer *SemVerPolicy `json:"semver,omitempty"`

// Alphabetical set of rules to use for alphabetical ordering of the tags.
// +optional
Alphabetical *AlphabeticalPolicy `json:"alphabetical,omitempty"`

// Numerical set of rules to use for numerical ordering of the tags.
// +optional
Numerical *NumericalPolicy `json:"numerical,omitempty"`
}

// SemVerPolicy specifices a semantic version policy.
// SemVerPolicy specifies a semantic version policy.
type SemVerPolicy struct {
// Range gives a semver range for the image tag; the highest
// version within the range that's a tag yields the latest image.
// +required
Range string `json:"range"`
}

// AlphabeticalPolicy specifices a alphabetical ordering policy.
// AlphabeticalPolicy specifies a alphabetical ordering policy.
type AlphabeticalPolicy struct {
// Order specifies the sorting order of the tags. Given the letters of the
// alphabet as tags, ascending order would select Z, and descending order
// would select A.
// +kubebuilder:default:="asc"
// +kubebuilder:validation:Enum=asc;desc
// +optional
Order string `json:"order,omitempty"`
}

// NumericalPolicy specifies a numerical ordering policy.
type NumericalPolicy struct {
// Order specifies the sorting order of the tags. Given the integer values
// from 0 to 9 as tags, ascending order would select 9, and descending order
// would select 0.
// +kubebuilder:default:="asc"
// +kubebuilder:validation:Enum=asc;desc
// +optional
Order string `json:"order,omitempty"`
}
```
Expand Down Expand Up @@ -117,7 +133,7 @@ type ImagePolicyStatus struct {
}
```

The `LatestImage` field contains the image selected by the policy rule, when it has run sucessfully.
The `LatestImage` field contains the image selected by the policy rule, when it has run successfully.

### Conditions

Expand All @@ -126,7 +142,7 @@ be marked as true when the policy rule has selected an image.

## Examples

Select the latest `main` branch build tagged as `${GIT_BRANCH}-${GIT_SHA:0:7}-$(date +%s)` (alphabetical):
Select the latest `main` branch build tagged as `${GIT_BRANCH}-${GIT_SHA:0:7}-$(date +%s)` (numerical):

```yaml
kind: ImagePolicy
Expand All @@ -135,7 +151,7 @@ spec:
pattern: '^main-[a-fA-F0-9]+-(?P<ts>.*)'
extract: '$ts'
policy:
alphabetical:
numerical:
order: asc
```
Expand Down