-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5876177
commit 75909d4
Showing
10 changed files
with
393 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:feature | ||
`feat` - Add calver Rule Semantic. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
hide: | ||
- toc | ||
--- | ||
|
||
# Semantic Versioning (calver) | ||
|
||
The `calver` rule allows you to define a rule that will be executed when the image is updated with a new calver version. | ||
It follows the [Semantic Versioning](https://calver.org/) specification. | ||
A lot of options are available to match the version you want to update. | ||
|
||
* `calver-major`: Update the image with the latest major version. | ||
* `calver-minor`: Update the image with the latest minor version. | ||
* `calver-patch`: Update the image with the latest patch version. | ||
|
||
**`calver-major`** is the most restrictive and will only update the image when the major version is updated [calver documentation](https://calver.org/). | ||
``` { .yaml .no-copy title="calver rule" } | ||
version: 2024.0.0 | ||
Match: >=2024.*.* # (1) | ||
``` | ||
|
||
1. :man_raising_hand: For more information about the calver range, you can check the [calver documentation](https://calver.org/). | ||
|
||
**`calver-minor`** is less restrictive and will update the image when the minor version is updated. | ||
``` { .yaml .no-copy title="calver rule" } | ||
version: 2024.0.0 | ||
Match: >=2024.1.* <2 # (1) | ||
``` | ||
|
||
1. :man_raising_hand: For more information about the calver range, you can check the [calver documentation](https://calver.org/). | ||
|
||
**`calver-patch`** is the least restrictive and will update the image when the patch version is updated. | ||
``` { .yaml .no-copy title="calver rule" } | ||
version: 2024.0.0 | ||
Match: >=2024.0.1 <2024.1.0 # (1) | ||
``` | ||
|
||
1. :man_raising_hand: For more information about the calver range, you can check the [calver documentation](https://calver.org/#spec-item-6). | ||
|
||
## Who to use | ||
|
||
Create an `Image` resource with the `calver` rule. | ||
|
||
```yaml hl_lines="15 16 17 20 21 22 24 25 26" | ||
apiVersion: kimup.cloudavenue.io/v1alpha1 | ||
kind: Image | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: kube-image-updater | ||
app.kubernetes.io/managed-by: kustomize | ||
name: image-sample-with-auth | ||
spec: | ||
image: registry.127.0.0.1.nip.io/demo | ||
baseTag: v2024.0.4 | ||
triggers: | ||
- [...] | ||
rules: | ||
- name: Notify when calver major is detected | ||
type: calver-major | ||
actions: | ||
- type: alert-xxx | ||
[...] | ||
- name: Automatic update calver minor | ||
type: calver-minor | ||
actions: | ||
- type: apply | ||
- name: Automatic update calver patch | ||
type: calver-patch | ||
actions: | ||
- type: apply | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package rules | ||
|
||
import ( | ||
"github.com/shipengqi/vc" | ||
|
||
"github.com/orange-cloudavenue/kube-image-updater/internal/log" | ||
) | ||
|
||
type ( | ||
// calverMajor - The first number in the version. | ||
calverMajor struct { | ||
rule | ||
} | ||
|
||
// calverMinor - The second number in the version. | ||
calverMinor struct { | ||
rule | ||
} | ||
|
||
// calverPatch - The third and usually final number in the version. Sometimes referred to as the "micro" segment. | ||
calverPatch struct { | ||
rule | ||
} | ||
) | ||
|
||
func init() { | ||
register(CalverMajor, &calverMajor{}) | ||
register(CalverMinor, &calverMinor{}) | ||
register(CalverPatch, &calverPatch{}) | ||
} | ||
|
||
func (c *calverMajor) Evaluate() (matchWithRule bool, newTag string, err error) { | ||
actualCV, err := vc.NewCalVerStr(c.actualTag) | ||
if err != nil { | ||
log.WithError(err).WithField("tag", c.actualTag).Error("Error parsing actual tag") | ||
return false, "", err | ||
} | ||
|
||
for _, t := range c.tags { | ||
cv, err := vc.NewCalVerStr(t) | ||
if err != nil { | ||
log.WithError(err).WithField("tag", t).Error("Error parsing tag") | ||
continue | ||
} | ||
|
||
if cv.Major() > actualCV.Major() { | ||
return true, t, nil | ||
} | ||
} | ||
|
||
return false, "", nil | ||
} | ||
|
||
func (c *calverMinor) Evaluate() (matchWithRule bool, newTag string, err error) { | ||
actualCV, err := vc.NewCalVerStr(c.actualTag) | ||
if err != nil { | ||
log.WithError(err).WithField("tag", c.actualTag).Error("Error parsing actual tag") | ||
return false, "", err | ||
} | ||
|
||
for _, t := range c.tags { | ||
cv, err := vc.NewCalVerStr(t) | ||
if err != nil { | ||
log.WithError(err).WithField("tag", t).Error("Error parsing tag") | ||
continue | ||
} | ||
|
||
if cv.Minor() > actualCV.Minor() && cv.Major() == actualCV.Major() { | ||
return true, t, nil | ||
} | ||
} | ||
|
||
return false, "", nil | ||
} | ||
|
||
func (c *calverPatch) Evaluate() (matchWithRule bool, newTag string, err error) { | ||
actualCV, err := vc.NewCalVerStr(c.actualTag) | ||
if err != nil { | ||
log.WithError(err).WithField("tag", c.actualTag).Error("Error parsing actual tag") | ||
return false, "", err | ||
} | ||
|
||
for _, t := range c.tags { | ||
cv, err := vc.NewCalVerStr(t) | ||
if err != nil { | ||
log.WithError(err).WithField("tag", t).Error("Error parsing tag") | ||
continue | ||
} | ||
|
||
if cv.Patch() > actualCV.Patch() && cv.Minor() == actualCV.Minor() && cv.Major() == actualCV.Major() { | ||
return true, t, nil | ||
} | ||
} | ||
|
||
return false, "", nil | ||
} |
Oops, something went wrong.