-
Notifications
You must be signed in to change notification settings - Fork 140
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
feat: add predicates on deployment #1172
feat: add predicates on deployment #1172
Conversation
@@ -376,7 +395,8 @@ var configMapPredicates = predicate.Funcs{ | |||
// a workaround for 2.5 due to odh-model-controller serivceaccount keeps updates with label. | |||
var saPredicates = predicate.Funcs{ | |||
UpdateFunc: func(e event.UpdateEvent) bool { | |||
if e.ObjectNew.GetName() == "odh-model-controller" && (e.ObjectNew.GetNamespace() == "redhat-ods-applications" || e.ObjectNew.GetNamespace() == "opendatahub") { | |||
namespace := e.ObjectNew.GetNamespace() | |||
if e.ObjectNew.GetName() == "odh-model-controller" && (namespace == cluster.RHOAIApplicationNamespace || namespace == cluster.ODHApplicationNamespace) { |
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.
Wonder if we can just use the operator namespace env var which is set on the deployment, that woudl avoid having to reference a specific list of possible namespace and rely on the namespace where the operator runs instead.
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.
sorry, after a second review, I think my comment was incorrect in the assumption that the namespace were the one where the operator runs. However, I think it would be better to take the namespace from the DSCI instead of having some hardcoded values.
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.
yeah, i have reverted the change and can have another PR to work on the namespace part
pkg/deploy/deploy.go
Outdated
// all other cases, whiltelistedfields will be skipped by ODH operator | ||
if managed, exists := found.GetAnnotations()[annotations.ManagedByODHOperator]; !exists || managed != "true" { | ||
// handl allowlisted fields with annoation | ||
switch managed, exists := found.GetAnnotations()[annotations.ManagedByODHOperator]; { |
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.
found.GetAnnotations()
may return nil
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.
in this case( when no annotation set at all) , it falls into case !exists
as managed == "" and exists is false, right?
which is the same: users can config these fields
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.
yeah sorry, I was thinking in could panic but in fact, you can dereference a map value even on nil ptr.
So wonder if you can just skip the check on exists
, since in fact what matter is only managed != "true"
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.
the logic from "before" is correct: ( !exists || managed != "true" )
=> call skipUpdateOnAllowlistedFields
if this is easier to understand i can put it back than changing to "switch" ?
but we cannot only check on managed != "true"
case
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 refactoring (changes without amending functionality) and changing the predicate are different things. Does it make sense to move the condition to own function?
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 we cannot only check on managed != "true" case
but if the annotation does not exist, it will return an empty string which actually satisfies the managed != "true"
condition, isn't it ?
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 what you mean now. yes, then it is either managed == true or the rest (covers no annotation, this annotation not exist, this annotation is set to non-true)
pkg/deploy/deploy.go
Outdated
// Create resource if it doesn't exist OR reconcile component if exists | ||
return CreateOrUpdateResource(ctx, cli, res, found, owner) | ||
} | ||
// Component id removed: delete resource if it exists or do nothing if not found |
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 is not easy to understand as there is a found
object but also a check on the IsNotFound
error, so the do nothing if not found is a little bit misleading. IMHO, the getResource
function should honor the ErrNotFound
and there should be no need to check if found != nil
@@ -366,7 +367,25 @@ var configMapPredicates = predicate.Funcs{ | |||
return false | |||
} | |||
// Do not reconcile on kserver's inferenceservice-config CM updates, for rawdeployment | |||
if e.ObjectNew.GetName() == "inferenceservice-config" && (e.ObjectNew.GetNamespace() == "redhat-ods-applications" || e.ObjectNew.GetNamespace() == "opendatahub") { | |||
namespace := e.ObjectNew.GetNamespace() | |||
if e.ObjectNew.GetName() == "inferenceservice-config" && (namespace == cluster.RHOAIApplicationNamespace || namespace == cluster.ODHApplicationNamespace) { |
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 it use namespace from DSCI?
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.
yeah these are not directly for the predicates part.
i ran into some lint warning saying the name have been used multiple times, thats why i create const for these,
but i think you are right, it should be break out into a different PR and get them from dsci somehow
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.
What the point of this file changes? For me they make it less readable. And at the first glance I do not see they are related to the rest so we can discuss them in a separate PR.
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 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 did some rework on the deploy part
pkg/deploy/deploy.go
Outdated
@@ -202,31 +202,31 @@ func manageResource(ctx context.Context, cli client.Client, res *resource.Resour | |||
} | |||
|
|||
found, err := getResource(ctx, cli, res) | |||
if !k8serr.IsNotFound(err) { |
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.
Will it be triggered by nil?
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.
thanks! missed this
- rename updateResoruce() to CreateOrUpdateResource() - use annoataion RHOAIApplicationNamespace and ODHApplicationNamespace than hardcode - add predicate.Funcs for deployments to reduce reconciles on all components - use switch for better readiness in CreateOrUpdateResource for annoataion handling Signed-off-by: Wen Zhou <[email protected]>
Signed-off-by: Wen Zhou <[email protected]>
- need to deal with this with another PR to get appliation namespace Signed-off-by: Wen Zhou <[email protected]>
Signed-off-by: Wen Zhou <[email protected]>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ykaliuta 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 |
6f82d01
into
opendatahub-io:incubation
* update: logic for manage resource with skip unnecessary reconcile - rename updateResoruce() to CreateOrUpdateResource() - use annoataion RHOAIApplicationNamespace and ODHApplicationNamespace than hardcode - add predicate.Funcs for deployments to reduce reconciles on all components - use switch for better readiness in CreateOrUpdateResource for annoataion handling Signed-off-by: Wen Zhou <[email protected]> * revert: back out annotation for application namespace Signed-off-by: Wen Zhou <[email protected]> * lint: skip lint on const with multiple hardcode value - need to deal with this with another PR to get appliation namespace Signed-off-by: Wen Zhou <[email protected]> * refactor: deploy with manage resource part Signed-off-by: Wen Zhou <[email protected]> --------- Signed-off-by: Wen Zhou <[email protected]> (cherry picked from commit 6f82d01)
* update: logic for manage resource with skip unnecessary reconcile - add predicate.Funcs for deployments to reduce reconciles on all components Signed-off-by: Wen Zhou <[email protected]> --------- Signed-off-by: Wen Zhou <[email protected]> (cherry picked from commit 6f82d01) Signed-off-by: Wen Zhou <[email protected]>
* update: logic for manage resource with skip unnecessary reconcile - add predicate.Funcs for deployments to reduce reconciles on all components --------- (cherry picked from commit 6f82d01) Signed-off-by: Wen Zhou <[email protected]>
Description
rename updateResoruce() to CreateOrUpdateResource()use annoataion RHOAIApplicationNamespace and ODHApplicationNamespace than hardcodeuse switch for better readiness in CreateOrUpdateResource for annotation handlingHow Has This Been Tested?
local build: quay.io/wenzhou/opendatahub-operator-catalog:v2.13.11024-1
Screenshot or short clip
Merge criteria