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

🌱Add watch for ClusterResourceSet resources #3410

Merged
merged 1 commit into from
Jul 31, 2020

Conversation

sedefsavas
Copy link

@sedefsavas sedefsavas commented Jul 28, 2020

What this PR does / why we need it:
This PR adds watch on ClusterResourceSet resources (ConfigMaps/Secrets), so that for the resources that is missing during Apply will be reconciled on creation or update of resources.

One down side of this is everytime a resource is created/updated, all CRS objects in the same namespace will be reconciled. Although CRS is added as owner of the resources during CRS creation since newly created resources were not there, they will not have owner refs and we cannot use owner references to get only the CRSs that has the created resource.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #3397

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 28, 2020
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 28, 2020
@sedefsavas
Copy link
Author

Although there is no creation/update of Secrets, resourceToClusterResourceSet() is contantly getting triggered. There should be something I am missing in predicates.
@vincepri any ideas?

@vincepri
Copy link
Member

/assign
/milestone v0.3.8

@k8s-ci-robot k8s-ci-robot added this to the v0.3.8 milestone Jul 28, 2020

for _, crs := range crsList.Items {
for _, resource := range crs.Spec.Resources {
if resource.Kind == o.Object.GetObjectKind().GroupVersionKind().Kind && crs.Name == o.Meta.GetName() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically we should be checking on both Group and Kind, as someone could create a foo.io/v123 Secret or ConfigMap.

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to worry about core vs empty group equivalency here when comparing the group, though? I think core types are probably the one exception where it might be ok to avoid checking group.

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 suggesting we worry about ensuring group="",Kind="Secret" and not matching on group="foo.io",Kind="Secret" - wouldn't that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to worry about also testing for group == "core" in addition to group == "" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

No - despite being known as the core group, the only valid value for that group is ""

Copy link
Member

@vincepri vincepri Jul 30, 2020

Choose a reason for hiding this comment

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

If we store the runtime.Scheme on r (ClusterResourceSetReconciler), you should be able to use apiutil.GVKForObject

Copy link
Contributor

Choose a reason for hiding this comment

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

It was originally there but I had Sedef remove it because we weren't using it 😄. Would it make more sense to do the func-that-returns-a-func approach so we don't have to do a lookup every time?

Copy link
Author

@sedefsavas sedefsavas Jul 30, 2020

Choose a reason for hiding this comment

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

This is the mapping function's parameter:

func (r *ClusterResourceSetReconciler) resourceToClusterResourceSet(o handler.MapObject) []ctrl.Request {

Cannot reach o's Kind.

Edit: page refreshed late. Ignore this, it was before the suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, func createMapFunc(kind schema.GroupKind) func(o handler.MapObject) []ctrl.Request { return func(...) ....}

Copy link
Author

Choose a reason for hiding this comment

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

We removed the Scheme in the Binding controller, we still have it here, so used that one.

@sedefsavas
Copy link
Author

I will change the predicates to watch only creation because I see continues ConfigMap updates coming for ConfigMaps like: capi-kubeadm-bootstrap-system, cert-manager-cainjector-leader-election, capv-controller-manager-runtime etc.

I need to make sure this is specific to updates, because earlier I was observing constant Secret creations but now can't observe that anymore.

cc @vincepri @ncdc @detiber

@ncdc
Copy link
Contributor

ncdc commented Jul 29, 2020

I would either

  • Skip the predicates for now, as the map function will still do what we need (it may get called more than necessary), or
  • Keep them and just return true for create + update

@ncdc
Copy link
Contributor

ncdc commented Jul 29, 2020

I would not expect the leader election configmap updates to put an overwhelming burden on the system

@ncdc
Copy link
Contributor

ncdc commented Jul 30, 2020

Correction, our default leaderelection updates are every 2 seconds, and we have multiple leaderelection configmaps, so we should try to mitigate this amount of updates:

  • Switch from configmap to lease record (separate type)
  • Reduce the update frequency
  • ?

@vincepri
Copy link
Member

Reduce the update frequency

We provide flags today to change the frequency, we could change those defaults. Should we do this in a separate PR/issue? Do you prefer having this in v0.3.8 or wait for later?

@ncdc
Copy link
Contributor

ncdc commented Jul 30, 2020

Definitely a separate PR. Maybe an issue too so we can discuss?

As for 0.3.8, if we don't make any changes to the lease update frequency, do you have any concerns about watching ConfigMaps?

@sedefsavas
Copy link
Author

/retest

@sedefsavas
Copy link
Author

Please note:

Removed watching for Updates until we fix frequent ConfigMap updates related to leader election.
Only watching Create events.

@sedefsavas sedefsavas changed the title [WIP] 🌱Add watch for ClusterResourceSet resources 🌱Add watch for ClusterResourceSet resources Jul 30, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 30, 2020
@sedefsavas
Copy link
Author

/retest

@sedefsavas
Copy link
Author

/retest

util/predicates/configmap_predicates.go Outdated Show resolved Hide resolved
util/predicates/secret_predicates.go Outdated Show resolved Hide resolved
util/predicates/secret_predicates.go Outdated Show resolved Hide resolved
@sedefsavas
Copy link
Author

/restest

1 similar comment
@sedefsavas
Copy link
Author

/restest

@sedefsavas
Copy link
Author

/retest

@sedefsavas
Copy link
Author

I think this PR is good to go.
cc @vincepri

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/assign @CecileRobertMichon @detiber
for final lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 31, 2020
@detiber
Copy link
Member

detiber commented Jul 31, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 31, 2020
@k8s-ci-robot k8s-ci-robot merged commit 9e4e82a into kubernetes-sigs:master Jul 31, 2020
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CRS] Watch ConfigMap/Secret creation/update for retrying to apply failed ones
6 participants