Skip to content

Commit

Permalink
Rename WantToCreateResource() to ReadyToProcessResource() to reflect …
Browse files Browse the repository at this point in the history
…the fact that resources will not be created in case readOnly is set to true
  • Loading branch information
barney-s committed Feb 5, 2025
1 parent e4cd30f commit 788e0d3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/instance/controller_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func (igr *instanceGraphReconciler) reconcileResource(ctx context.Context, resou
resourceState := &ResourceState{State: "IN_PROGRESS"}
igr.state.ResourceStates[resourceID] = resourceState

// Check if resource should be created
if want, err := igr.runtime.WantToCreateResource(resourceID); err != nil || !want {
// Check if resource should be processed (create or get)
if want, err := igr.runtime.ReadyToProcessResource(resourceID); err != nil || !want {
log.V(1).Info("Skipping resource creation", "reason", err)
resourceState.State = "SKIPPED"
igr.runtime.IgnoreResource(resourceID)
Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ type Interface interface {
// IsResourceReady returns true if the resource is ready, and false otherwise.
IsResourceReady(resourceID string) (bool, string, error)

// WantToCreateResource returns true if all the condition expressions return true
// ReadyToProcessResource returns true if all the condition expressions return true
// if not it will add itself to the ignored resources
WantToCreateResource(resourceID string) (bool, error)
ReadyToProcessResource(resourceID string) (bool, error)

// IgnoreResource ignores resource that has a condition expressison that evaluated
// to false
Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ func (rt *ResourceGraphDefinitionRuntime) areDependenciesIgnored(resourceID stri
return false
}

// WantToCreateResource returns true if all the condition expressions return true
// ReadyToProcessResource returns true if all the condition expressions return true
// if not it will add itself to the ignored resources
func (rt *ResourceGraphDefinitionRuntime) WantToCreateResource(resourceID string) (bool, error) {
func (rt *ResourceGraphDefinitionRuntime) ReadyToProcessResource(resourceID string) (bool, error) {
if rt.areDependenciesIgnored(resourceID) {
return false, nil
}
Expand Down
18 changes: 11 additions & 7 deletions pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,11 @@ func Test_IsResourceReady(t *testing.T) {
{
name: "multiple expressions all true",
resource: newTestResource(
withReadyExpressions([]string{"test.status.ready", "test.status.healthy && test.status.count > 10", "test.status.count > 5"}),
withReadyExpressions([]string{
"test.status.ready",
"test.status.healthy && test.status.count > 10",
"test.status.count > 5",
}),
),
resolvedObject: map[string]interface{}{
"status": map[string]interface{}{
Expand Down Expand Up @@ -2280,7 +2284,7 @@ func Test_IsResourceReady(t *testing.T) {
})
}
}
func Test_WantToCreateResource(t *testing.T) {
func Test_ReadyToProcessResource(t *testing.T) {
tests := []struct {
name string
resource Resource
Expand Down Expand Up @@ -2368,25 +2372,25 @@ func Test_WantToCreateResource(t *testing.T) {
},
}

got, err := rt.WantToCreateResource("test")
got, err := rt.ReadyToProcessResource("test")
if tt.wantErr {
if err == nil {
t.Error("WantToCreateResource() expected error, got none")
t.Error("ReadyToProcessResource() expected error, got none")
}
return
}
if tt.wantSkip {
if err == nil || !strings.Contains(err.Error(), "Skipping resource creation due to condition") {
t.Errorf("WantToCreateResource() expected skip message, got %v", err)
t.Errorf("ReadyToProcessResource() expected skip message, got %v", err)
}
return
}
if err != nil {
t.Errorf("WantToCreateResource() unexpected error = %v", err)
t.Errorf("ReadyToProcessResource() unexpected error = %v", err)
return
}
if got != tt.want {
t.Errorf("WantToCreateResource() = %v, want %v", got, tt.want)
t.Errorf("ReadyToProcessResource() = %v, want %v", got, tt.want)
}
})
}
Expand Down

0 comments on commit 788e0d3

Please sign in to comment.