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

Fix nodetask.File dependency on owner #9169

Merged
merged 1 commit into from
May 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions upup/pkg/fi/nodeup/nodetasks/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ var _ fi.HasDependencies = &File{}
func (e *File) GetDependencies(tasks map[string]fi.Task) []fi.Task {
var deps []fi.Task
if e.Owner != nil {
ownerTask := tasks["user/"+*e.Owner]
ownerTask := tasks["UserTask/"+*e.Owner]
if ownerTask == nil {
// The user might be a pre-existing user (e.g. admin)
klog.Warningf("Unable to find task %q", "user/"+*e.Owner)
klog.Warningf("Unable to find task %q", "UserTask/"+*e.Owner)
} else {
deps = append(deps, ownerTask)
}
Expand Down
61 changes: 48 additions & 13 deletions upup/pkg/fi/nodeup/nodetasks/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,39 @@ func TestFileDependencies(t *testing.T) {
childFileName := "/dependent"

grid := []struct {
name string
parent fi.Task
child fi.Task
}{
{
name: "user",
parent: &UserTask{
Name: "owner",
UID: 3,
Shell: "/bin/shell",
Home: "/home/owner",
},
child: &File{
Owner: fi.String("owner"),
Path: childFileName,
Contents: fi.NewStringResource("I depend on an owner"),
Type: FileType_File,
},
},
{
name: "parentDir",
parent: &File{
Path: parentFileName,
Type: FileType_Directory,
},
child: &File{
Path: parentFileName + "/" + childFileName,
Contents: fi.NewStringResource("I depend on my parent directory"),
Type: FileType_File,
},
},
{
name: "afterFiles",
parent: &File{
Path: parentFileName,
Contents: fi.NewStringResource("I am depended on by " + childFileName),
Expand All @@ -46,18 +75,24 @@ func TestFileDependencies(t *testing.T) {
}

for _, g := range grid {
allTasks := make(map[string]fi.Task)
allTasks["parent"] = g.parent
allTasks["child"] = g.child

deps := g.parent.(fi.HasDependencies).GetDependencies(allTasks)
if len(deps) != 0 {
t.Errorf("found unexpected dependencies for parent: %v %v", g.parent, deps)
}

childDeps := g.child.(fi.HasDependencies).GetDependencies(allTasks)
if len(childDeps) != 1 {
t.Errorf("found unexpected dependencies for child: %v %v", g.child, childDeps)
}
t.Run(g.name, func(t *testing.T) {
context := &fi.ModelBuilderContext{
Tasks: make(map[string]fi.Task),
}
context.AddTask(g.parent)
context.AddTask(g.child)

if _, ok := g.parent.(fi.HasDependencies); ok {
deps := g.parent.(fi.HasDependencies).GetDependencies(context.Tasks)
if len(deps) != 0 {
t.Errorf("found unexpected dependencies for parent: %v %v", g.parent, deps)
}
}

childDeps := g.child.(fi.HasDependencies).GetDependencies(context.Tasks)
if len(childDeps) != 1 {
t.Errorf("found unexpected dependencies for child: %v %v", g.child, childDeps)
}
})
}
}