-
Notifications
You must be signed in to change notification settings - Fork 53
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
Adds linting CI workflow #264
Conversation
e3d5805
to
33e4b83
Compare
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.
There are a lot of small changes to address linting issues. Hopefully these comments will help with reviews.
// | ||
// Today we always return ctrl.Result{} and an error. | ||
// But in the future we might update this function | ||
// to return different results (e.g. requeue). | ||
// | ||
//nolint:unparam |
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.
Same as in rukpak (see this thread).
// made accessible on-cluster by https://github.com/operator-framework/catalogd. | ||
// It is an implementation of deppy defined input.EntitySource | ||
type catalogdEntitySource struct { | ||
type CatalogdEntitySource struct { |
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.
NewCatalogdEntitySource
was returning unexported struct.
@@ -1,4 +1,4 @@ | |||
package crd_constraints |
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'm a bit on the fence with this one. Lookign for opinions. I can revert and we can disable this check.
While valid and compiles this considered to not be idiomatic in Go.
Same goes for bundles_and_dependencies
and required_package
.
See:
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'm +1 on these changes. I don't know of any packages in any dependencies I've used that have underscores in their paths or names.
This may be an indication that we don't have the right package organization in the first place.
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 would say it's fine to make the change as-is for now, but I would personally like to see a bit of a change in the directory structure to make it a bit easier to make changes and add new features. For example, in the current structure to add a new k8s version constraint we would probably end up creating a new package/directory called k8sversionconstraint
.
Instead, I think we should follow a pattern more like constraints/crd
. Following the above example, it is intuitive where a new constraint package should be added and would be constraints/kubeversion
(or something like that). IMO the same should go for bundles_and_dependencies
(what do they represent? can they be broken into separate packages?) and required_packages
(how should we add new required_*?)
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.
Or even just package constraints
with types CRD
and KubernetesVersion
. Or maybe even more combined, package olm
with CRDConstraint
, KubernetesVersionConstraint
, BundleVariable
, etc.
Do we need all of the package sprawl?
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.
@joelanford @everettraven I'm in in favour of starting with just one constraints
package and splitting it into more once we see the need and/or once/if we decide to make this stuff exportable.
But I think it should be done outside of this PR (which is already fairly big).
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.
But I think it should be done outside of this PR (which is already fairly big).
Yeah, definitely +1
items, err := meta.ExtractList(list) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
names := make([]string, 0, len(items)) |
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.
Preallocation of the slice. There are few other places like this
type RequiredPackageVariable struct { | ||
type Variable struct { |
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.
Linter complained about name stuttering: when exported requiredpackage.RequiredPackageVariable
vs requiredpackage.Variable
.
Same for RequiredPackageOption
vs Option
and RequiredPackageVariableSource
vs VariableSource
if filter(&entity) { | ||
resultSet = append(resultSet, entity) | ||
for i := range entities { | ||
if filter(&entities[i]) { |
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.
gosec: G601: Implicit memory aliasing in for loop.
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.
+1 on this fix. However it makes me wonder... is it necessary or important that input.Predicate
takes a pointer to an input.Entity
? Could we take a input.Entity
rather than an *input.Entity
?
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
Rebased on top of master to fix conflicts with #263 which just merged. |
@@ -17,5 +18,5 @@ var operatorControllerFeatureGates = map[featuregate.Feature]featuregate.Feature | |||
var OperatorControllerFeatureGate featuregate.MutableFeatureGate = featuregate.NewFeatureGate() | |||
|
|||
func init() { | |||
OperatorControllerFeatureGate.Add(operatorControllerFeatureGates) | |||
utilruntime.Must(OperatorControllerFeatureGate.Add(operatorControllerFeatureGates)) |
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.
@everettraven is it fair? Or do we need better error handling here?
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 think that is fair. Good catch - I totally missed that it returned an error. Would probably be good to fix this in catalogd as well (and add linting there :))
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.
@everettraven here is the PR for catalogd - operator-framework/catalogd#98
// verifyBDStatus reads the various possibilities of status in bundle deployment and translates | ||
// into corresponding operator condition status and message. | ||
func verifyBDStatus(dep *rukpakv1alpha1.BundleDeployment) (metav1.ConditionStatus, string) { | ||
isValidBundleCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle) | ||
isInstalledCond := apimeta.FindStatusCondition(dep.Status.Conditions, rukpakv1alpha1.TypeInstalled) | ||
|
||
if isValidBundleCond != nil && isValidBundleCond.Status == metav1.ConditionFalse { | ||
return metav1.ConditionFalse, isValidBundleCond.Message | ||
} | ||
|
||
if isInstalledCond != nil && isInstalledCond.Status == metav1.ConditionFalse { | ||
return metav1.ConditionFalse, isInstalledCond.Message | ||
} | ||
|
||
if isInstalledCond != nil && isInstalledCond.Status == metav1.ConditionTrue { | ||
return metav1.ConditionTrue, "install was successful" | ||
} | ||
return metav1.ConditionUnknown, fmt.Sprintf("could not determine the state of BundleDeployment %s", dep.Name) | ||
} | ||
|
||
// isBundleDepStale returns true if conditions are out of date. | ||
func isBundleDepStale(bd *rukpakv1alpha1.BundleDeployment) bool { | ||
return bd != nil && bd.Status.ObservedGeneration != bd.GetGeneration() | ||
} | ||
|
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.
Was all this unused code?
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.
Yep
@@ -1,4 +1,4 @@ | |||
package crd_constraints |
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 would say it's fine to make the change as-is for now, but I would personally like to see a bit of a change in the directory structure to make it a bit easier to make changes and add new features. For example, in the current structure to add a new k8s version constraint we would probably end up creating a new package/directory called k8sversionconstraint
.
Instead, I think we should follow a pattern more like constraints/crd
. Following the above example, it is intuitive where a new constraint package should be added and would be constraints/kubeversion
(or something like that). IMO the same should go for bundles_and_dependencies
(what do they represent? can they be broken into separate packages?) and required_packages
(how should we add new required_*?)
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.
This looks really good, I have a few comments but nothing blocking
err := c.Get(ctx, key, op) | ||
Expect(err).To(BeNil()) | ||
Expect(c.Get(ctx, key, op)).To(Succeed()) |
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 see a few other places where we're using Expect(err).NotTo(HaveOccurred())
. Are we looking to standardize this throughout the test suite?
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.
As far as I understand Expect(funcCall()).To(Succeed())
and Expect(err).NotTo(HaveOccurred())
do the same thing, but the first one is supposed to be used with functions which only return one error
. I personally not too concerned about using one style over another. Important one is to use one of these styles overExpect(err).To(BeNil())
because they give better failure messages.
In general, I'm not a big fan of Ginkgo & Gomega because there are usually 10 ways to do the same.
bundleVariables = append(bundleVariables, v) | ||
} | ||
} | ||
Expect(len(bundleVariables)).To(Equal(12)) | ||
Expect(bundleVariables).To(HaveLen(12)) | ||
Expect(bundleVariables).To(WithTransform(CollectBundleVariableIDs, Equal([]string{"bundle-2", "bundle-1", "bundle-15", "bundle-16", "bundle-17", "bundle-9", "bundle-8", "bundle-7", "bundle-5", "bundle-4", "bundle-11", "bundle-10"}))) |
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.
nit: do we need to have the length check if we're already checking equality?
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.
Good point. I wasn't paying too much attention to the surrounding lines only validated that ginkgolinter --fix ./...
gave me reasonable fixes.
I'll submit a follow up request to delete this line & update to use ConsistOf
as you suggested in another comment.
crdConstraintVariables = append(crdConstraintVariables, v) | ||
} | ||
} | ||
Expect(len(crdConstraintVariables)).To(Equal(11)) | ||
Expect(crdConstraintVariables).To(HaveLen(11)) | ||
Expect(crdConstraintVariables).To(WithTransform(CollectGlobalConstraintVariableIDs, ContainElements([]string{ |
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.
ConsistOf should help avoid the length check here
@@ -1,4 +1,4 @@ | |||
package bundles_and_dependencies |
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.
nit: can we rename this package at all? bundlesanddependencies
seems unnecessarily long, bundleentity
or bundlesource
might do the job just as well
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.
There is a relevant discussion on this here: #264 (comment)
I'll look into better structure and names in a separate PR as this one is quite large already.
Description
This PR adds linting CI workflow which is based on the one from rukpak
Reviewer Checklist