-
Notifications
You must be signed in to change notification settings - Fork 545
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] feat(resolver): add namespace and channel awareness #402
Merged
njhale
merged 4 commits into
operator-framework:master
from
njhale:namespace-aware-resolution
Aug 8, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1cc9fe2
feat(resolver): add namespace and channel awareness
njhale 5a16990
chore(dep): re-vendor with dep stable
njhale 201181e
refactor(catalog): remove map-based subscription caching
njhale 4c80d1b
style(resolver): remove nesting from owner CSV selection logic
njhale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,19 +13,19 @@ import ( | |
// DependencyResolver defines how a something that resolves dependencies (CSVs, CRDs, etc...) | ||
// should behave | ||
type DependencyResolver interface { | ||
ResolveInstallPlan(sourceRefs []registry.SourceRef, catalogLabelKey string, plan *v1alpha1.InstallPlan) ([]v1alpha1.Step, []registry.SourceKey, error) | ||
ResolveInstallPlan(sourceRefs []registry.SourceRef, existingCRDOwners map[string][]string, catalogLabelKey string, plan *v1alpha1.InstallPlan) ([]v1alpha1.Step, []registry.ResourceKey, error) | ||
} | ||
|
||
// MultiSourceResolver resolves resolves dependencies from multiple CatalogSources | ||
type MultiSourceResolver struct{} | ||
|
||
// ResolveInstallPlan resolves the given InstallPlan with all available sources | ||
func (resolver *MultiSourceResolver) ResolveInstallPlan(sourceRefs []registry.SourceRef, catalogLabelKey string, plan *v1alpha1.InstallPlan) ([]v1alpha1.Step, []registry.SourceKey, error) { | ||
func (resolver *MultiSourceResolver) ResolveInstallPlan(sourceRefs []registry.SourceRef, existingCRDOwners map[string][]string, catalogLabelKey string, plan *v1alpha1.InstallPlan) ([]v1alpha1.Step, []registry.ResourceKey, error) { | ||
srm := make(stepResourceMap) | ||
var usedSourceKeys []registry.SourceKey | ||
var usedSourceKeys []registry.ResourceKey | ||
|
||
for _, csvName := range plan.Spec.ClusterServiceVersionNames { | ||
csvSRM, used, err := resolver.resolveCSV(sourceRefs, catalogLabelKey, plan.Namespace, csvName) | ||
csvSRM, used, err := resolver.resolveCSV(sourceRefs, existingCRDOwners, catalogLabelKey, plan.Namespace, csvName) | ||
if err != nil { | ||
// Could not resolve CSV in any source | ||
return nil, nil, err | ||
|
@@ -38,12 +38,12 @@ func (resolver *MultiSourceResolver) ResolveInstallPlan(sourceRefs []registry.So | |
return srm.Plan(), usedSourceKeys, nil | ||
} | ||
|
||
func (resolver *MultiSourceResolver) resolveCSV(sourceRefs []registry.SourceRef, catalogLabelKey, planNamespace, csvName string) (stepResourceMap, []registry.SourceKey, error) { | ||
func (resolver *MultiSourceResolver) resolveCSV(sourceRefs []registry.SourceRef, existingCRDOwners map[string][]string, catalogLabelKey, planNamespace, csvName string) (stepResourceMap, []registry.ResourceKey, error) { | ||
log.Debugf("resolving CSV with name: %s", csvName) | ||
|
||
steps := make(stepResourceMap) | ||
csvNamesToBeResolved := []string{csvName} | ||
var usedSourceKeys []registry.SourceKey | ||
var usedSourceKeys []registry.ResourceKey | ||
|
||
for len(csvNamesToBeResolved) != 0 { | ||
// Pop off a CSV name. | ||
|
@@ -55,7 +55,7 @@ func (resolver *MultiSourceResolver) resolveCSV(sourceRefs []registry.SourceRef, | |
continue | ||
} | ||
|
||
var csvSourceKey registry.SourceKey | ||
var csvSourceKey registry.ResourceKey | ||
var csv *v1alpha1.ClusterServiceVersion | ||
var err error | ||
|
||
|
@@ -82,7 +82,7 @@ func (resolver *MultiSourceResolver) resolveCSV(sourceRefs []registry.SourceRef, | |
// Resolve each owned or required CRD for the CSV. | ||
for _, crdDesc := range csv.GetAllCRDDescriptions() { | ||
// Attempt to get CRD from same catalog source CSV was found in | ||
step, owner, err := resolver.resolveCRDDescription(sourceRefs, catalogLabelKey, crdDesc, csv.OwnsCRD(crdDesc.Name)) | ||
step, owner, err := resolver.resolveCRDDescription(sourceRefs, existingCRDOwners, catalogLabelKey, planNamespace, crdDesc, csv.OwnsCRD(crdDesc.Name)) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
@@ -126,15 +126,16 @@ func (resolver *MultiSourceResolver) resolveCSV(sourceRefs []registry.SourceRef, | |
return steps, usedSourceKeys, nil | ||
} | ||
|
||
func (resolver *MultiSourceResolver) resolveCRDDescription(sourceRefs []registry.SourceRef, catalogLabelKey string, crdDesc v1alpha1.CRDDescription, owned bool) (v1alpha1.StepResource, string, error) { | ||
logger := log.WithFields(log.Fields{"kind": crdDesc.Kind, "name": crdDesc.Name, "version": crdDesc.Version}) | ||
func (resolver *MultiSourceResolver) resolveCRDDescription(sourceRefs []registry.SourceRef, existingCRDOwners map[string][]string, catalogLabelKey, planNamespace string, crdDesc v1alpha1.CRDDescription, owned bool) (v1alpha1.StepResource, string, error) { | ||
log.Debugf("resolving %#v", crdDesc) | ||
|
||
crdKey := registry.CRDKey{ | ||
Kind: crdDesc.Kind, | ||
Name: crdDesc.Name, | ||
Version: crdDesc.Version, | ||
} | ||
logger.Debug("resolving") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for cleaning up logs! |
||
var crdSourceKey registry.SourceKey | ||
|
||
var crdSourceKey registry.ResourceKey | ||
var crd *v1beta1.CustomResourceDefinition | ||
var source registry.Source | ||
var err error | ||
|
@@ -155,8 +156,6 @@ func (resolver *MultiSourceResolver) resolveCRDDescription(sourceRefs []registry | |
return v1alpha1.StepResource{}, "", err | ||
} | ||
|
||
logger.Debugf("found") | ||
|
||
if owned { | ||
// Label CRD with catalog source | ||
labels := crd.GetLabels() | ||
|
@@ -184,9 +183,32 @@ func (resolver *MultiSourceResolver) resolveCRDDescription(sourceRefs []registry | |
return v1alpha1.StepResource{}, "", fmt.Errorf("Unknown CRD %s", crdKey) | ||
} | ||
|
||
// TODO: Change to lookup the CSV from the preferred or default channel. | ||
logger.WithField("owner", csvs[0].CSV.Name).Info("found owner") | ||
return v1alpha1.StepResource{}, csvs[0].CSV.Name, nil | ||
var ownerName string | ||
owners := existingCRDOwners[crdKey.Name] | ||
switch len(owners) { | ||
case 0: | ||
// No pre-existing owner found | ||
for _, csv := range csvs { | ||
// Check for the default channel | ||
if csv.IsDefaultChannel { | ||
ownerName = csv.CSV.Name | ||
break | ||
} | ||
} | ||
case 1: | ||
ownerName = owners[0] | ||
default: | ||
return v1alpha1.StepResource{}, "", fmt.Errorf("More than one existing owner for CRD %s in namespace %s found: %v", crdKey.Name, planNamespace, owners) | ||
} | ||
|
||
// Check empty name | ||
if ownerName == "" { | ||
log.Infof("No preexisting CSV or default channel found for owners of CRD %v", crdKey) | ||
ownerName = csvs[0].CSV.Name | ||
} | ||
|
||
log.Infof("Found %v owner %s", crdKey, ownerName) | ||
return v1alpha1.StepResource{}, ownerName, nil | ||
|
||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 a bigger wrench than I intended to throw when I started looking at this PR...
But it strikes me that this type of tracking (for both "sources" and "subscriptions") is exactly what the cache and indexers are supposed to do for you in client-go.
We already have SharedIndexInformers for all of this available to the operator, so we can probably just use the index provided there.
Take a look at the cache tooling and see if you agree: https://github.com/kubernetes/client-go/tree/master/tools/cache
I would guess that it's as simple as keeping track of the SharedIndexInformers by namespace and then querying those.
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 think this makes a lot of sense when dealing with subscriptions since we don't need to do any additional work to pull it from the indexer's cache/store. Sources however, need an InMem instance constructed from the catalog source object and its config map before they are useful.
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.
Good point!
A future optimization to consider would be to disallow "internal" catalogsources (replacing them with pods that expose an API over the network), which would let us do the same caching for sources and remove the need to parse and keep all the contents in memory.
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!
Also, it's questionable at this point whether knowing about subscriptions at resolution time matters as much as knowing what's in the target namespace.
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.
Tracked in ALM-679, ignore this for this PR