Skip to content

Commit

Permalink
Merge pull request #9837 from justinsb/is_ready
Browse files Browse the repository at this point in the history
TaskDependentResource: support preview when the task isn't ready
  • Loading branch information
k8s-ci-robot authored Aug 29, 2020
2 parents 3f079cd + a1553bd commit 3941bd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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
}

0 comments on commit 3941bd5

Please sign in to comment.