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

engine: don't parallelize uncategorized yaml with other yaml. Fixes https://github.com/tilt-dev/tilt/issues/3421 #3567

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions internal/engine/buildcontrol/build_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ func NextTargetToBuild(state store.EngineState) *store.ManifestTarget {
targets = RemoveLocalTargets(targets)
}

// Uncategorized YAML might contain namespaces or volumes that
// we don't want to parallelize.
//
// TODO(nick): Long-term, we should try to infer dependencies between Kuberentes
// resources. A general library might make sense.
if IsBuildingUncategorizedYAML(state) {
targets = RemoveK8sTargets(targets)
}

targets = RemoveTargetsWithBuildingComponents(targets)
targets = RemoveTargetsWaitingOnDependencies(state, targets)

Expand Down Expand Up @@ -201,6 +210,16 @@ func RemoveLocalTargets(targets []*store.ManifestTarget) []*store.ManifestTarget
return result
}

func RemoveK8sTargets(targets []*store.ManifestTarget) []*store.ManifestTarget {
result := []*store.ManifestTarget{}
for _, target := range targets {
if !target.Manifest.IsK8s() {
result = append(result, target)
}
}
return result
}

func IsBuildingAnything(state store.EngineState) bool {
mts := state.Targets()
for _, mt := range mts {
Expand All @@ -221,6 +240,16 @@ func IsBuildingLocalTarget(state store.EngineState) bool {
return false
}

func IsBuildingUncategorizedYAML(state store.EngineState) bool {
mts := state.Targets()
for _, mt := range mts {
if mt.State.IsBuilding() && mt.Manifest.Name == model.UnresourcedYAMLManifestName {
return true
}
}
return false
}

// Go through all the manifests, and check:
// 1) all pending file changes
// 2) all pending dependency changes (where an image has been rebuilt by another manifest), and
Expand Down
13 changes: 13 additions & 0 deletions internal/engine/buildcontrol/build_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ func TestCurrentlyBuildingK8sResourceDisablesLocalScheduling(t *testing.T) {
f.assertNoTargetNextToBuild()
}

func TestCurrentlyBuildingUncategorizedDisablesOtherK8sTargets(t *testing.T) {
f := newTestFixture(t)
defer f.TearDown()

_ = f.upsertK8sManifest("k8s1")
k8sUnresourced := f.upsertK8sManifest(model.UnresourcedYAMLManifestName)
_ = f.upsertK8sManifest("k8s2")

f.assertNextTargetToBuild(model.UnresourcedYAMLManifestName)
k8sUnresourced.State.CurrentBuild = model.BuildRecord{StartTime: time.Now()}
f.assertNoTargetNextToBuild()
}

func TestCurrentlyBuildingLocalResourceDisablesK8sScheduling(t *testing.T) {
f := newTestFixture(t)
defer f.TearDown()
Expand Down