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

WIP Viewer framework for resource status #825

Closed
wants to merge 3 commits into from

Conversation

njhale
Copy link
Member

@njhale njhale commented Apr 26, 2019

Currently, this PR represents an experiment in caching alternate views of resources.

Goal

Provide a framework that makes it easy to:

  • Cache alternate views of resources
  • Quickly lookup views for dependent resources
  • Inform dependent resources when views change
  • Separate state collection from state action

Test Case

The first test case for the framework is to provide SubscriptionCatalogStatus updates to dependent Subscriptions.

Implementation

The experimental code is located in pkg/controller/operators/catalog/scratch.go.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 26, 2019
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: njhale

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-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 26, 2019
Copy link
Member

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

This is looking good! excited to start using this

I wrote this out for myself when reviewing to remind myself of a desired state at a high level. sharing here for reference (but it doesn't map 1-1 with the abstractions here)

func (o *Operator) syncSubscription(sub *v1alpha1.Subscription) error {
	sub.SetCatalogStatus(o.views["catalogstatus"].ByIndex("namespacePlusGlobal").Get(sub.GetNamespace()))
}

func (o *Operator) syncCatalogSource(catsrc *v1alpha1.CatalogSource) {

	// check health, etc
	healthy := true
	catstatuskey := catsrc.GetNamespace() + "/" + catsrc.GetName()

	// set value in the view
	o.views["catalogstatus"].ByIndex("catatalogsource").Set(catstatuskey, NewCatSrcStatusView(catsrc, healthy))

	// update indexes
	if catsrc.IsGlobal() {
		for namespace := range o.lister.CoreV1().NamespaceLister().List(metav1.ListOptions{}) {
			o.views["catalogstatus"].ByIndex("namespacePlusGlobal").SetKey(namespace, catsrckey)
		}
	} else {
		o.views["catalogstatus"].ByIndex("namespacePlusGlobal").SetKey(catsrc.GetNamespace(), catsrckey)
	}
}

func (o *Operator) syncCatSrcStatusView(viewkey CatSrcStatusViewKey) {
	for subkey := range o.views["catalogstatus"].ByReverseIndex("subscriptions").List(viewkey) {
		o.requeue("subscriptions", subkey)
	}
}


// RemoveSubscriptionCatalogStatus removes the SubscriptionCatalogStatus matching the given ObjectReference from a SubscriptionStatus
// and returns true if the status was removed; false otherwise.
func (status *SubscriptionStatus) RemoveSubscriptionCatalogStatus(target *corev1.ObjectReference) bool {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't used yet, but ideally we don't have Add/Remove (just Set)

}

// Views are a set of ViewFuncs keyed by their resource type
type Views map[reflect.Type]View
Copy link
Member

Choose a reason for hiding this comment

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

on the fence, but it might make sense to have this be a string key instead. avoids reflection and would mean we could register multiple views per type.

Copy link
Member Author

Choose a reason for hiding this comment

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

The key of this map is intended to be the view type, not the resource type. So this should still let us register multiple views per resource type.

Copy link
Member

Choose a reason for hiding this comment

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

// Views are a set of ViewFuncs keyed by their resource type

I think this comment got me :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally understand - I think the interface itself is ambiguous too.

return nil, err
}

key, err := view.Key(value)
Copy link
Member

Choose a reason for hiding this comment

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

why not just view.Value(key)?

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 was thinking that we want to get the value of what's stored in the cache rather than a fresh view.

Copy link
Member

Choose a reason for hiding this comment

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

My last comment was wrong, sorry.

What I meant was:

Why not have an interface for getting a key directly from an object?

i.e.

type View interface {
	Key(obj interface{}) (key string, err error)
	Value(obj interface{}) (value interface{}, err error)
}

vs

type View interface {
	Key(value interface{}) (key string, err error)
	Value(obj interface{}) (value interface{}, err error)
}

so that here, you would just write view.Key(obj) and not need to get the value at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, got it - makes sense. We probably want to add another function for getting the key from the "view" itself (to satisfy some internal requirements of the underlying cache implementation).

reconcilerFactory reconciler.RegistryReconcilerFactory
}

func NewSubCatalogView(configmapRegistryImage string, options ...viewOption) *subCatalogView {
Copy link
Member

Choose a reason for hiding this comment

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

nit, but maybe we want to call these ViewBuilders or Viewers and call the output of .Value() be the View object?

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely want better names with less overlap.

@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 29, 2019
@njhale njhale force-pushed the viewer-framework branch 9 times, most recently from 8f9fb3d to c0472bf Compare May 3, 2019 02:58
@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 3, 2019
@njhale njhale force-pushed the viewer-framework branch 4 times, most recently from bb56f32 to 7f08c5d Compare May 3, 2019 19:41
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 11, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 11, 2019
@openshift-ci-robot
Copy link
Collaborator

@njhale: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws-console-olm 6931ef8 link /test e2e-aws-console-olm
ci/prow/e2e-aws 6931ef8 link /test e2e-aws
ci/prow/e2e-aws-olm 6931ef8 link /test e2e-aws-olm

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-ci-robot
Copy link
Collaborator

@njhale: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 24, 2019
@njhale
Copy link
Member Author

njhale commented Jun 13, 2019

superseded by #881.

@njhale njhale closed this Jun 13, 2019
@njhale njhale deleted the viewer-framework branch September 30, 2019 21:36
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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants