Skip to content

Commit

Permalink
feat: support excluding some packages from the target of aqua update (
Browse files Browse the repository at this point in the history
#2752)

* feat: support excluding some packages from the target of `aqua update`

* docs: update JSON Schema
  • Loading branch information
suzuki-shunsuke committed Mar 17, 2024
1 parent 775ddcf commit 3f367c2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aqua/imports/cosign.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
packages:
- name: sigstore/cosign@v1.13.2
update:
enabled: false
12 changes: 12 additions & 0 deletions json-schema/aqua-yaml.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
},
"link": {
"type": "string"
},
"update": {
"$ref": "#/$defs/Update"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -130,6 +133,15 @@
]
},
"type": "array"
},
"Update": {
"properties": {
"enabled": {
"type": "boolean"
}
},
"additionalProperties": false,
"type": "object"
}
}
}
21 changes: 21 additions & 0 deletions pkg/config/aqua/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,30 @@ type Package struct {
Tags []string `yaml:",omitempty" json:"tags,omitempty"`
Description string `yaml:",omitempty" json:"description,omitempty"`
Link string `yaml:",omitempty" json:"link,omitempty"`
Update *Update `yaml:",omitempty" json:"update,omitempty"`
FilePath string `json:"-" yaml:"-"`
}

type Update struct {
// # If enabled is false, aqua up command ignores the package.
// If the package name is passed to aqua up command explicitly, enabled is ignored.
// By default, enabled is true.
Enabled *bool `yaml:",omitempty" json:"enabled,omitempty"`
// The condition of allowed version.
// expr https://github.com/expr-lang/expr is used.
// By default, all versions are allowed.
// The version must meet both allowed_version and types.
AllowedVersion string `yaml:"allowed_version,omitempty" json:"allowed_version,omitempty"`
// The list of allowed update types
// By default, all types are allowed.
// major, minor, patch, other
Types []string `yaml:",omitempty" json:"types,omitempty"`
}

func (u *Update) GetEnabled() bool {
return u == nil || u.Enabled == nil || *u.Enabled
}

func (p *Package) UnmarshalYAML(unmarshal func(interface{}) error) error {
type alias Package
a := alias(*p)
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/update/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func (c *Controller) updatePackagesInFile(ctx context.Context, logE *logrus.Entr
return nil
}
for _, pkg := range pkgs {
if len(param.Args) == 0 && !param.Insert {
if !pkg.Package.Update.GetEnabled() {
// If the update is disabled, the package is ignored
continue
}
}
logE := logE.WithFields(logrus.Fields{
"package_name": pkg.Package.Name,
"package_version": pkg.Package.Version,
Expand Down

0 comments on commit 3f367c2

Please sign in to comment.