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

create a scaler controller to watch and trigger the events on CR creation #529

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

iamniting
Copy link
Member

Signed-off-by: Nitin Goyal [email protected]

Copy link
Contributor

openshift-ci bot commented Feb 13, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: iamniting

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 13, 2025
@iamniting iamniting force-pushed the watch-crds branch 10 times, most recently from c89fa74 to 1f10e0b Compare February 26, 2025 10:41
Copy link
Contributor

@leelavg leelavg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will review again after some of the comments are addressed.

}

//nolint:unused
kindList = []metav1.PartialObjectMetadata{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove unused code? not sure where it is planned, storing pointers would be good if used at a later point.

Comment on lines +94 to +105
csvCephcsiOperator = "cephcsi-operator" //nolint:unused
csvMcgOperator = "mcg-operator"
csvOcsClientOperator = "ocs-client-operator" //nolint:unused
csvOcsOperator = "ocs-operator"
csvOdfCsiAddonsOperator = "odf-csi-addons-operator" //nolint:unused
csvOdfDependencies = "odf-dependencies" //nolint:unused
csvOdfOperator = "odf-operator" //nolint:unused
csvOdfPrometheusOperator = "odf-prometheus-operator" //nolint:unused
csvRecipe = "recipe" //nolint:unused
csvRookCephOperator = "rook-ceph-operator"

csvIbmStorageOdfOperator = "ibm-storage-odf-operator"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't these name of packages rather than CSV?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i Just named as CSV as we refer to csv mostly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean these represent pkg and should be named accordingly.


var csvLabelKey = "operators.coreos.com/%s.%s"

var (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separation is already being followed w/ new lines and so why to use var at multiple places again?

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 am doing that to keep different logical variables separate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't helping anything I believe, a single var w/ a comment around each segment would inform the intent more appropriately.

In current state, reviewers (future & current) should ensure ntg in b/n should be written.

Comment on lines +80 to +90
crdStorageCluster = "storageclusters.ocs.openshift.io"
crdCephCluster = "cephclusters.ceph.rook.io"
crdNoobaa = "noobaas.noobaa.io"
crdFlashSystemCluster = "flashsystemclusters.odf.ibm.com"

crdList = []string{
crdStorageCluster,
crdCephCluster,
crdNoobaa,
crdFlashSystemCluster,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are names of CRDs and crdXXName, crdNamesList would be more apt?

)

var (
crdToKindMapping = map[string]metav1.PartialObjectMetadata{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the value is copied into map which has two issues

  1. only shallow copy is being performed which makes the nested structures being shared
  2. map size increases without any clear benefits

Either

  1. do a deep copy if you want exclusive ownership of the obj (or)
  2. store pointers as values

I prefer 2 as I don't see why map needs exclusive ownership of these.

replicas = 0
}

for _, csvName := range csvNames {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's better to run this in parallel or let the loop go over all CSVs trying to update CSV as a failure in one stops everything else now, why do want to put a break if all operators can be run in parallel in the cluster?

for kind, csvNames := range kindToCsvsMapping {

var replicas int32 = 1
objects := &metav1.PartialObjectMetadataList{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to give a more concrete name here? these are CRs, isn't it? crList?


var replicas int32 = 1
objects := &metav1.PartialObjectMetadataList{}
objects.TypeMeta = kind.TypeMeta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work 🤔? isn't List and individual resource distinct? this line here seems like assigning Pod typeMeta to PodList typeMeta.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does work

Comment on lines +173 to +176
if err != nil {
if meta.IsNoMatchError(err) {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is client.IgnoreNotFound(err) != nil different than IsNoMatchError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they are different IsNoMatchError is when there is no CRD.

},
predicate.GenerationChangedPredicate{},
),
).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm just thinking, do we want to add a watch for CSV as we are effectively managing it's replicas?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently i dont want to because if we do that we don't leave any room for user to make the change to the replicas of the CSV also they wont be able to scale down the odf-operator because of the webhook.

@iamniting
Copy link
Member Author

/test odf-operator-e2e-aws

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants