-
Notifications
You must be signed in to change notification settings - Fork 315
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(extensions): auto registration and repo subpaths #6371
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2c51f90
test for existing fake nesting behavior
avidal 1b8b432
introduce support for extension_repo.prefix
avidal f9b341c
implement repo-wide extension paths
avidal a848256
test for extension loading when a repo has a prefix and a subpath
avidal c245498
update path and prefix test to use subdirectories
avidal 870b19b
chore: make update-codegen
avidal f0ee888
wip: split up ensureExtension and write tests
avidal ff1d5f8
fixup: use correct json/protobuf field name casing
avidal 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
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 |
---|---|---|
|
@@ -23,8 +23,10 @@ import ( | |
"github.com/tilt-dev/tilt/pkg/logger" | ||
) | ||
|
||
const extensionPrefix = "ext://" | ||
const defaultRepoName = "default" | ||
const ( | ||
extensionPrefix = "ext://" | ||
defaultRepoName = "default" | ||
) | ||
|
||
type Plugin struct { | ||
repoReconciler ExtRepoReconciler | ||
|
@@ -129,6 +131,75 @@ func (e *Plugin) LocalPath(t *starlark.Thread, arg string) (localPath string, er | |
// Otherwise, infers an extension object that points to the default repo. | ||
func (e *Plugin) ensureExtension(t *starlark.Thread, objSet apiset.ObjectSet, moduleName string) *v1alpha1.Extension { | ||
extName := apis.SanitizeName(moduleName) | ||
|
||
extSet := objSet.GetOrCreateTypedSet(&v1alpha1.Extension{}) | ||
if existing, exists := extSet[extName]; exists { | ||
ext := existing.(*v1alpha1.Extension) | ||
metav1.SetMetaDataAnnotation(&ext.ObjectMeta, v1alpha1.AnnotationManagedBy, "tiltfile.loader") | ||
return ext | ||
} | ||
|
||
repoSet := objSet.GetOrCreateTypedSet(&v1alpha1.ExtensionRepo{}) | ||
|
||
return e.registerExtension(t, extSet, repoSet, extName, moduleName) | ||
} | ||
|
||
// In cases where an extension is not already registered, this function will search for an extension | ||
// repo that can satisfy the requested extension, with a fallback to an extension in the default | ||
// repository. | ||
func (e *Plugin) registerExtension(t *starlark.Thread, extSet, repoSet apiset.TypedObjectSet, extName, moduleName string) *v1alpha1.Extension { | ||
loadHost, extPath, tryRegister := strings.Cut(moduleName, "/") | ||
|
||
// Safety fallback (in case this is called without already previously calling ensureExtension) | ||
existing := extSet[extName] | ||
if existing != nil { | ||
return existing.(*v1alpha1.Extension) | ||
} | ||
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. This seems a bit off. In a fuller implementation this would also set the |
||
|
||
// If the supplied module name does not contain a / then there's no point looking for matching | ||
// extension repositories. We can just return an extension named extName in the default | ||
// repository | ||
if !tryRegister { | ||
return e.registerDefaultExtension(t, extSet, extName, moduleName) | ||
} | ||
|
||
// Otherwise, look for a repository that can satisfy this lookup | ||
for _, v := range repoSet { | ||
repo := v.(*v1alpha1.ExtensionRepo) | ||
if repo.Spec.LoadHost == "" || repo.Spec.LoadHost != loadHost { | ||
continue | ||
} | ||
|
||
// This repo load_host matches the first component of the module name | ||
// So we can register this as an extension on that repo | ||
ext := &v1alpha1.Extension{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: extName, | ||
Annotations: map[string]string{ | ||
v1alpha1.AnnotationManagedBy: "tiltfile.loader", | ||
}, | ||
}, | ||
Spec: v1alpha1.ExtensionSpec{ | ||
RepoName: repo.Name, | ||
RepoPath: extPath, | ||
}, | ||
} | ||
|
||
extSet[extName] = ext | ||
return ext | ||
} | ||
|
||
return e.registerDefaultExtension(t, extSet, extName, moduleName) | ||
} | ||
|
||
// Registers an extension named moduleName in the default extension repository. Used as a fallback. | ||
func (e *Plugin) registerDefaultExtension(t *starlark.Thread, extSet apiset.TypedObjectSet, extName, moduleName string) *v1alpha1.Extension { | ||
// Safety fallback | ||
existing := extSet[extName] | ||
if existing != nil { | ||
return existing.(*v1alpha1.Extension) | ||
} | ||
|
||
defaultExt := &v1alpha1.Extension{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: extName, | ||
|
@@ -142,15 +213,7 @@ func (e *Plugin) ensureExtension(t *starlark.Thread, objSet apiset.ObjectSet, mo | |
}, | ||
} | ||
|
||
typedSet := objSet.GetOrCreateTypedSet(defaultExt) | ||
existing, exists := typedSet[extName] | ||
if exists { | ||
ext := existing.(*v1alpha1.Extension) | ||
metav1.SetMetaDataAnnotation(&ext.ObjectMeta, v1alpha1.AnnotationManagedBy, "tiltfile.loader") | ||
return ext | ||
} | ||
|
||
typedSet[extName] = defaultExt | ||
extSet[extName] = defaultExt | ||
return defaultExt | ||
} | ||
|
||
|
@@ -179,8 +242,10 @@ func (e *Plugin) ensureRepo(t *starlark.Thread, objSet apiset.ObjectSet, repoNam | |
return defaultRepo | ||
} | ||
|
||
var _ starkit.LoadInterceptor = (*Plugin)(nil) | ||
var _ starkit.StatefulPlugin = (*Plugin)(nil) | ||
var ( | ||
_ starkit.LoadInterceptor = (*Plugin)(nil) | ||
_ starkit.StatefulPlugin = (*Plugin)(nil) | ||
) | ||
|
||
func MustState(model starkit.Model) State { | ||
state, err := GetState(model) | ||
|
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.
I vacillated quite a bit on what the sig should be for
registerExtension
andregisterDefaultExtension
. I wasn't sure if they should share the signature withensureExtension
and only takemoduleName
andobjSet
and reconstructextName
and the specific typed sets, or if they should take the already "prepared" variables from.ensureExtension
.Take a look @nicks, particularly at how these signatures manifest in the tests if you would.