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

Adds linting CI workflow #264

Merged
merged 4 commits into from
Jun 22, 2023
Merged

Conversation

m1kola
Copy link
Member

@m1kola m1kola commented Jun 15, 2023

Description

This PR adds linting CI workflow which is based on the one from rukpak

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 15, 2023
@m1kola m1kola force-pushed the add_linters branch 2 times, most recently from e3d5805 to 33e4b83 Compare June 16, 2023 08:46
Copy link
Member Author

@m1kola m1kola left a 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.

Comment on lines +110 to +115
//
// 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
Copy link
Member Author

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 {
Copy link
Member Author

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
Copy link
Member Author

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:

Copy link
Member

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.

Copy link
Contributor

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_*?)

Copy link
Member

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?

Copy link
Member Author

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).

Copy link
Member

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))
Copy link
Member Author

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

https://golangci-lint.run/usage/linters/#prealloc

type RequiredPackageVariable struct {
type Variable struct {
Copy link
Member Author

@m1kola m1kola Jun 16, 2023

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

@m1kola m1kola marked this pull request as ready for review June 16, 2023 12:51
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 16, 2023
if filter(&entity) {
resultSet = append(resultSet, entity)
for i := range entities {
if filter(&entities[i]) {
Copy link
Member Author

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.

Copy link
Member

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>
@m1kola
Copy link
Member Author

m1kola commented Jun 20, 2023

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))
Copy link
Member Author

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?

Copy link
Contributor

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 :))

Copy link
Member Author

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

Comment on lines -351 to -375
// 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()
}

Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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_*?)

Copy link
Contributor

@ankitathomas ankitathomas left a 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())
Copy link
Contributor

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?

Copy link
Member Author

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"})))
Copy link
Contributor

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?

Copy link
Member Author

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{
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Member Author

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.

@m1kola m1kola merged commit a946081 into operator-framework:main Jun 22, 2023
@m1kola m1kola deleted the add_linters branch June 22, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants