-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Status Updater to be resource agnostic (#1814)
Problem: Currently, the status updater is aware of what resource it is updating the status of. This makes it difficult to extend because for each new resource we add support for, we have to modify the status updater. Solution: Replace old status updater with two new ones (1) Regular Updater, to update statuses of multiple resources via UpdateRequest type. (2) LeaderAwareGroupUpdater to update statuses of groups of resources and save any pending UpdateRequests until the updater is enabled (when pod becomes leader). It uses Regular Updater. Using groups allow replacing UpdateRequests of subset of resources, without the need to recompute UpdateRequests for all resources. The new status package is resource agnostic. This is accomplished by representing status update as a function (Setter). Other updates: - provisioner manager uses regular Updater. - static manager uses LeaderAwareGroupUpdater (because it needs to support leader election) - framework Status setter were simplified and moved to static/status package - status related functions in static package were moved to static/status package. - Previous Build* functions were replaced with PrepareRequests functions. Such functions don't create any intermediate status representation (like it was before), but create status UpdateRequests which directly set the resource statuses. - static manager handler conditionally updates statuses GatewayClass based on manager configuration. Previously, the conditional logic was implemented in the Status Updater. CLOSES -- #1071
- Loading branch information
Showing
36 changed files
with
3,035 additions
and
3,268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package helpers | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
) | ||
|
||
func TestMustCastObject(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
var obj client.Object = &gatewayv1.Gateway{} | ||
|
||
g.Expect(func() { | ||
_ = MustCastObject[*gatewayv1.Gateway](obj) | ||
}).ToNot(Panic()) | ||
|
||
g.Expect(func() { | ||
_ = MustCastObject[*gatewayv1alpha2.BackendTLSPolicy](obj) | ||
}).To(Panic()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
package status | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"slices" | ||
|
||
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/conditions" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func convertConditions( | ||
conds []conditions.Condition, | ||
observedGeneration int64, | ||
transitionTime metav1.Time, | ||
) []metav1.Condition { | ||
apiConds := make([]metav1.Condition, len(conds)) | ||
// ConditionsEqual compares conditions. | ||
// It doesn't check the last transition time of conditions. | ||
func ConditionsEqual(prev, cur []metav1.Condition) bool { | ||
return slices.EqualFunc(prev, cur, func(c1, c2 metav1.Condition) bool { | ||
if c1.ObservedGeneration != c2.ObservedGeneration { | ||
return false | ||
} | ||
|
||
if c1.Type != c2.Type { | ||
return false | ||
} | ||
|
||
if c1.Status != c2.Status { | ||
return false | ||
} | ||
|
||
for i := range conds { | ||
apiConds[i] = metav1.Condition{ | ||
Type: conds[i].Type, | ||
Status: conds[i].Status, | ||
ObservedGeneration: observedGeneration, | ||
LastTransitionTime: transitionTime, | ||
Reason: conds[i].Reason, | ||
Message: conds[i].Message, | ||
if c1.Message != c2.Message { | ||
return false | ||
} | ||
} | ||
|
||
return apiConds | ||
return c1.Reason == c2.Reason | ||
}) | ||
} |
Oops, something went wrong.