-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set GatewayClass status for ignored GatewayClasses (#804)
Problem: It is expected that any GatewayClass that references our controller should have its status set properly, even if not used by our controller. Solution: Both the provisioner and controller will now add Accepted status False and ObservedGeneration to any GatewayClass that references our controller but is not configured to be used by our controller.
- Loading branch information
Showing
18 changed files
with
476 additions
and
154 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
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,47 @@ | ||
package predicate | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
) | ||
|
||
// GatewayClassPredicate implements a predicate function based on the controllerName of a GatewayClass. | ||
// This predicate will skip events for GatewayClasses that don't reference this controller. | ||
type GatewayClassPredicate struct { | ||
predicate.Funcs | ||
ControllerName string | ||
} | ||
|
||
// Create implements default CreateEvent filter for validating a GatewayClass controllerName. | ||
func (gcp GatewayClassPredicate) Create(e event.CreateEvent) bool { | ||
if e.Object == nil { | ||
return false | ||
} | ||
|
||
gc, ok := e.Object.(*v1beta1.GatewayClass) | ||
if !ok { | ||
return false | ||
} | ||
|
||
return string(gc.Spec.ControllerName) == gcp.ControllerName | ||
} | ||
|
||
// Update implements default UpdateEvent filter for validating a GatewayClass controllerName. | ||
func (gcp GatewayClassPredicate) Update(e event.UpdateEvent) bool { | ||
if e.ObjectOld != nil { | ||
gcOld, ok := e.ObjectOld.(*v1beta1.GatewayClass) | ||
if ok && string(gcOld.Spec.ControllerName) == gcp.ControllerName { | ||
return true | ||
} | ||
} | ||
|
||
if e.ObjectNew != nil { | ||
gcNew, ok := e.ObjectNew.(*v1beta1.GatewayClass) | ||
if ok && string(gcNew.Spec.ControllerName) == gcp.ControllerName { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
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,34 @@ | ||
package predicate | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
) | ||
|
||
func TestGatewayClassPredicate(t *testing.T) { | ||
g := NewGomegaWithT(t) | ||
|
||
p := GatewayClassPredicate{ControllerName: "nginx-ctlr"} | ||
|
||
gc := &v1beta1.GatewayClass{ | ||
Spec: v1beta1.GatewayClassSpec{ | ||
ControllerName: "nginx-ctlr", | ||
}, | ||
} | ||
|
||
g.Expect(p.Create(event.CreateEvent{Object: gc})).To(BeTrue()) | ||
g.Expect(p.Update(event.UpdateEvent{ObjectNew: gc})).To(BeTrue()) | ||
|
||
gc2 := &v1beta1.GatewayClass{ | ||
Spec: v1beta1.GatewayClassSpec{ | ||
ControllerName: "unknown", | ||
}, | ||
} | ||
g.Expect(p.Create(event.CreateEvent{Object: gc2})).To(BeFalse()) | ||
g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc, ObjectNew: gc2})).To(BeTrue()) | ||
g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc2, ObjectNew: gc})).To(BeTrue()) | ||
g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc2, ObjectNew: gc2})).To(BeFalse()) | ||
} |
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
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
Oops, something went wrong.