Skip to content

Commit

Permalink
tiltfile: actually ignore invalid resource deps (#5775)
Browse files Browse the repository at this point in the history
  • Loading branch information
landism authored May 5, 2022
1 parent ee0d758 commit 802fb41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions internal/tiltfile/tiltfile_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ to your Tiltfile. Otherwise, switch k8s contexts and restart Tilt.`, kubeContext
manifests = append(manifests, yamlManifest)
}

err = s.validateResourceDependencies(manifests)
err = s.sanitizeDependencies(manifests)
if err != nil {
return nil, starkit.Model{}, err
}
Expand Down Expand Up @@ -1626,10 +1626,9 @@ func (s *tiltfileState) tempDir() (*fwatch.TempDir, error) {
return s.scratchDir, nil
}

func (s *tiltfileState) validateResourceDependencies(ms []model.Manifest) error {
// make sure that:
// 1. all deps exist
// 2. we have a DAG
func (s *tiltfileState) sanitizeDependencies(ms []model.Manifest) error {
// warn + delete resource deps that don't exist
// error if resource deps are not a DAG

knownResources := make(map[model.ManifestName]bool)
for _, m := range ms {
Expand All @@ -1638,7 +1637,8 @@ func (s *tiltfileState) validateResourceDependencies(ms []model.Manifest) error

// construct the graph and make sure all edges are valid
edges := make(map[interface{}][]interface{})
for _, m := range ms {
for i, m := range ms {
var sanitizedDeps []model.ManifestName
for _, b := range m.ResourceDependencies {
if m.Name == b {
return fmt.Errorf("resource %s specified a dependency on itself", m.Name)
Expand All @@ -1648,7 +1648,11 @@ func (s *tiltfileState) validateResourceDependencies(ms []model.Manifest) error
continue
}
edges[m.Name] = append(edges[m.Name], b)
sanitizedDeps = append(sanitizedDeps, b)
}

m.ResourceDependencies = sanitizedDeps
ms[i] = m
}

// check for cycles
Expand Down
6 changes: 5 additions & 1 deletion internal/tiltfile/tiltfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4694,10 +4694,14 @@ func TestDependsOnMissingResource(t *testing.T) {
f := newFixture(t)

f.file("Tiltfile", `
local_resource('bar', 'echo bar', resource_deps=['foo'])
local_resource('baz', 'echo baz')
local_resource('bar', 'echo bar', resource_deps=['foo', 'baz'])
`)

f.loadAssertWarnings("resource bar specified a dependency on unknown resource foo - dependency ignored")
f.assertNumManifests(2)
f.assertNextManifest("baz", resourceDeps())
f.assertNextManifest("bar", resourceDeps("baz"))
}

func TestDependsOnSelf(t *testing.T) {
Expand Down

0 comments on commit 802fb41

Please sign in to comment.