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

TaskDependentResource: support preview when the task isn't ready #9837

Merged
merged 1 commit into from
Aug 29, 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
5 changes: 5 additions & 0 deletions upup/pkg/fi/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func equalFieldValues(a, e reflect.Value) bool {
if ok && (e.Kind() == reflect.Ptr || e.Kind() == reflect.Interface) && !e.IsNil() {
eResource, ok := e.Interface().(Resource)
if ok {
if hasIsReady, ok := eResource.(HasIsReady); ok {
if !hasIsReady.IsReady() {
return false
}
}
same, err := ResourcesMatch(aResource, eResource)
if err != nil {
klog.Fatalf("error while comparing resources: %v", err)
Expand Down
13 changes: 12 additions & 1 deletion upup/pkg/fi/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type Resource interface {
Open() (io.Reader, error)
}

// HasIsReady is implemented by Resources that are derived (and thus may not be ready at comparison time)
type HasIsReady interface {
IsReady() bool
}

type TemplateResource interface {
Resource
Curry(args []string) TemplateResource
Expand Down Expand Up @@ -264,14 +269,20 @@ type TaskDependentResource struct {

var _ Resource = &TaskDependentResource{}
var _ HasDependencies = &TaskDependentResource{}
var _ HasIsReady = &TaskDependentResource{}

func (r *TaskDependentResource) Open() (io.Reader, error) {
if r.Resource == nil {
return nil, fmt.Errorf("resource opened before it is ready")
return nil, fmt.Errorf("resource opened before it is ready (task=%v)", r.Task)
}
return r.Resource.Open()
}

func (r *TaskDependentResource) GetDependencies(tasks map[string]Task) []Task {
return []Task{r.Task}
}

// IsReady implements HasIsReady::IsReady
func (r *TaskDependentResource) IsReady() bool {
return r.Resource != nil
}