-
Notifications
You must be signed in to change notification settings - Fork 67
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 conditions as future replacement of requirements #519
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ release: ga | |
|
||
owner.github: "ruflin" | ||
|
||
conditions: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ph @michalpristas I initially was thinking about aligning the syntax with the constraints on the agent. But it only complicates things. The reason is that the available conditions here are very limited and have very specific checks. Adding additional "non yaml" syntax only complicates things. So here is what I'm proposing at the moment. As each One thing I think we should align is the naming. I landed on conditions as I think it fits best in all the places. WDYT about renaming it also in the agent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 on using "conditions" instead of constraints, which would align with dynamic input. Now, I am Okayish with using key values pair, for what you are proposing.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, using key/value also mean you don't have to have the parser in Kibana and we don't have to share code in the registry. So since everything is defined upfront I do not see a concern if the syntax arent the same, it's easier to start fixed and limited than to be dynamic all the way. |
||
kibana.version: "~7.x.x" | ||
|
||
requirement: | ||
kibana: | ||
versions: ">=7.0.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ type Package struct { | |
versionSemVer *semver.Version | ||
Categories []string `config:"categories" json:"categories"` | ||
Release string `config:"release,omitempty" json:"release,omitempty"` | ||
Conditions *Conditions `config:"conditions,omitempty" json:"conditions,omitempty" yaml:"conditions,omitempty"` | ||
Requirement Requirement `config:"requirement" json:"requirement"` | ||
Screenshots []Image `config:"screenshots,omitempty" json:"screenshots,omitempty" yaml:"screenshots,omitempty"` | ||
Assets []string `config:"assets,omitempty" json:"assets,omitempty" yaml:"assets,omitempty"` | ||
|
@@ -97,6 +98,11 @@ type Requirement struct { | |
Kibana ProductRequirement `config:"kibana" json:"kibana,omitempty" yaml:"kibana"` | ||
} | ||
|
||
type Conditions struct { | ||
KibanaVersion string `config:"kibana.version,omitempty" json:"kibana.version,omitempty" yaml:"kibana.version,omitempty"` | ||
kibanaConstraint *semver.Constraints | ||
} | ||
|
||
type ProductRequirement struct { | ||
Versions string `config:"versions,omitempty" json:"versions,omitempty" yaml:"versions,omitempty"` | ||
semVerRange *semver.Constraints | ||
|
@@ -150,7 +156,7 @@ func NewPackage(basePath string) (*Package, error) { | |
var p = &Package{ | ||
BasePath: basePath, | ||
} | ||
err = manifest.Unpack(p) | ||
err = manifest.Unpack(p, ucfg.PathSep(".")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -185,8 +191,18 @@ func NewPackage(basePath string) (*Package, error) { | |
|
||
p.Downloads = []Download{NewDownload(*p, "tar")} | ||
|
||
if p.Requirement.Kibana.Versions != "" { | ||
p.Requirement.Kibana.semVerRange, err = semver.NewConstraint(p.Requirement.Kibana.Versions) | ||
// If the new conditions are used, select them over the requirements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is duplicated code in this if-else to account for the new and legacy settings. Looks like the intent is to use the new setting,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ycombinator The legacy code should only be around for 24-48h, so I was sloppy. |
||
if p.Conditions != nil && p.Conditions.KibanaVersion != "" { | ||
p.Conditions.kibanaConstraint, err = semver.NewConstraint(p.Conditions.KibanaVersion) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "invalid Kibana versions range: %s", p.Conditions.KibanaVersion) | ||
} | ||
// TODO: remove legacy part | ||
} else if p.Requirement.Kibana.Versions != "" { | ||
p.Conditions = &Conditions{ | ||
KibanaVersion: p.Requirement.Kibana.Versions, | ||
} | ||
p.Conditions.kibanaConstraint, err = semver.NewConstraint(p.Requirement.Kibana.Versions) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "invalid Kibana versions range: %s", p.Requirement.Kibana.Versions) | ||
} | ||
|
@@ -253,16 +269,11 @@ func (p *Package) HasCategory(category string) bool { | |
func (p *Package) HasKibanaVersion(version *semver.Version) bool { | ||
|
||
// If the version is not specified, it is for all versions | ||
if p.Requirement.Kibana.Versions == "" { | ||
if p.Conditions == nil || version == nil { | ||
return true | ||
} | ||
|
||
if version != nil { | ||
if !p.Requirement.Kibana.semVerRange.Check(version) { | ||
return false | ||
} | ||
} | ||
return true | ||
return p.Conditions.kibanaConstraint.Check(version) | ||
} | ||
|
||
func (p *Package) IsNewerOrEqual(pp Package) bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should requirements be deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will be removed in a few hours ;-)