-
Notifications
You must be signed in to change notification settings - Fork 51
feat: added status fields for API #650
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
Open
yashisrani
wants to merge
9
commits into
volcano-sh:main
Choose a base branch
from
yashisrani:add/status-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+556
−9
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb2842b
feat: added status fields for API
yashisrani bc27568
fix: linting issues
yashisrani 894c9d1
feat: added setGatewayListenerConditions function
yashisrani 6e0f585
feat(gateway): report listener startup errors via status
yashisrani 8887408
fix: golint errors
yashisrani d238e65
fix: golint errors
yashisrani 3cdfddd
feat: implement gateway listener status reporting and error tracking
yashisrani 58ef3f0
feat: resource status reporting and test stability improvements
yashisrani 581c0a8
fix: go build issue
yashisrani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,24 +17,28 @@ limitations under the License. | |
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "sync/atomic" | ||
| "time" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| "k8s.io/client-go/tools/cache" | ||
| "k8s.io/client-go/util/workqueue" | ||
| "k8s.io/klog/v2" | ||
| gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
| gatewayclientset "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned" | ||
| gatewayinformers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions" | ||
| gatewaylisters "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1" | ||
|
|
||
| "github.com/volcano-sh/kthena/pkg/kthena-router/datastore" | ||
| ) | ||
|
|
||
| type GatewayController struct { | ||
| gatewayClient gatewayclientset.Interface | ||
| gatewayLister gatewaylisters.GatewayLister | ||
| gatewaySynced cache.InformerSynced | ||
| registration cache.ResourceEventHandlerRegistration | ||
|
|
@@ -45,12 +49,14 @@ type GatewayController struct { | |
| } | ||
|
|
||
| func NewGatewayController( | ||
| gatewayClient gatewayclientset.Interface, | ||
| gatewayInformerFactory gatewayinformers.SharedInformerFactory, | ||
| store datastore.Store, | ||
| ) *GatewayController { | ||
| gatewayInformer := gatewayInformerFactory.Gateway().V1().Gateways() | ||
|
|
||
| controller := &GatewayController{ | ||
| gatewayClient: gatewayClient, | ||
| gatewayLister: gatewayInformer.Lister(), | ||
| gatewaySynced: gatewayInformer.Informer().HasSynced, | ||
| workqueue: workqueue.NewTypedRateLimitingQueue(workqueue.DefaultTypedControllerRateLimiter[any]()), | ||
|
|
@@ -160,7 +166,139 @@ func (c *GatewayController) syncHandler(key string) error { | |
| return err | ||
| } | ||
|
|
||
| return nil | ||
| return c.updateGatewayStatus(gateway) | ||
| } | ||
|
|
||
| func (c *GatewayController) updateGatewayStatus(gateway *gatewayv1.Gateway) error { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add corresponding E2E to make sure the status setting for Gateway/HTTPRoute/InferencePool all work properly. |
||
| gateway = gateway.DeepCopy() | ||
|
|
||
| // Update conditions | ||
| acceptedCond := metav1.Condition{ | ||
| Type: string(gatewayv1.GatewayConditionAccepted), | ||
| Status: metav1.ConditionTrue, | ||
| Reason: string(gatewayv1.GatewayReasonAccepted), | ||
| Message: "Gateway has been accepted by kthena-router", | ||
| LastTransitionTime: metav1.Now(), | ||
| ObservedGeneration: gateway.Generation, | ||
| } | ||
|
|
||
| programmedCond := metav1.Condition{ | ||
| Type: string(gatewayv1.GatewayConditionProgrammed), | ||
| Status: metav1.ConditionTrue, | ||
| Reason: string(gatewayv1.GatewayReasonProgrammed), | ||
| Message: "Gateway has been programmed by kthena-router", | ||
| LastTransitionTime: metav1.Now(), | ||
| ObservedGeneration: gateway.Generation, | ||
| } | ||
|
|
||
| c.setGatewayCondition(gateway, acceptedCond) | ||
| c.setGatewayCondition(gateway, programmedCond) | ||
|
|
||
| // Update listener status | ||
| gatewayKey := fmt.Sprintf("%s/%s", gateway.Namespace, gateway.Name) | ||
| for _, listener := range gateway.Spec.Listeners { | ||
| listenerErr := c.store.GetListenerStatus(gatewayKey, string(listener.Name)) | ||
|
|
||
| acceptedCond, programmedCond := c.getGatewayListenerConditions(listenerErr, gateway.Generation) | ||
| c.setGatewayListenerStatus(gateway, listener.Name, []metav1.Condition{acceptedCond, programmedCond}) | ||
| } | ||
|
|
||
| _, err := c.gatewayClient.GatewayV1().Gateways(gateway.Namespace).UpdateStatus(context.Background(), gateway, metav1.UpdateOptions{}) | ||
| return err | ||
| } | ||
|
|
||
| func (c *GatewayController) setGatewayCondition(gateway *gatewayv1.Gateway, newCond metav1.Condition) { | ||
| for i, cond := range gateway.Status.Conditions { | ||
| if cond.Type == newCond.Type { | ||
| if cond.Status == newCond.Status && cond.Reason == newCond.Reason { | ||
| newCond.LastTransitionTime = cond.LastTransitionTime | ||
| } | ||
| gateway.Status.Conditions[i] = newCond | ||
| return | ||
| } | ||
| } | ||
| gateway.Status.Conditions = append(gateway.Status.Conditions, newCond) | ||
| } | ||
|
|
||
| func (c *GatewayController) setGatewayListenerStatus(gateway *gatewayv1.Gateway, listenerName gatewayv1.SectionName, conditions []metav1.Condition) { | ||
| var listenerStatus *gatewayv1.ListenerStatus | ||
| for i := range gateway.Status.Listeners { | ||
| if gateway.Status.Listeners[i].Name == listenerName { | ||
| listenerStatus = &gateway.Status.Listeners[i] | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if listenerStatus == nil { | ||
| gateway.Status.Listeners = append(gateway.Status.Listeners, gatewayv1.ListenerStatus{ | ||
| Name: listenerName, | ||
| SupportedKinds: []gatewayv1.RouteGroupKind{ | ||
| { | ||
| Group: (*gatewayv1.Group)(&gatewayv1.GroupVersion.Group), | ||
| Kind: gatewayv1.Kind("HTTPRoute"), | ||
| }, | ||
| }, | ||
| }) | ||
| listenerStatus = &gateway.Status.Listeners[len(gateway.Status.Listeners)-1] | ||
| } | ||
|
|
||
| // Update conditions | ||
| for _, newCond := range conditions { | ||
| found := false | ||
| for i, cond := range listenerStatus.Conditions { | ||
| if cond.Type == newCond.Type { | ||
| if cond.Status == newCond.Status && cond.Reason == newCond.Reason { | ||
| newCond.LastTransitionTime = cond.LastTransitionTime | ||
| } | ||
| listenerStatus.Conditions[i] = newCond | ||
| found = true | ||
| break | ||
| } | ||
| } | ||
| if !found { | ||
| listenerStatus.Conditions = append(listenerStatus.Conditions, newCond) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (c *GatewayController) getGatewayListenerConditions(listenerErr error, generation int64) (metav1.Condition, metav1.Condition) { | ||
| acceptedStatus := metav1.ConditionTrue | ||
| acceptedReason := string(gatewayv1.ListenerReasonAccepted) | ||
| acceptedMessage := "Listener has been accepted" | ||
|
|
||
| programmedStatus := metav1.ConditionTrue | ||
| programmedReason := string(gatewayv1.ListenerReasonProgrammed) | ||
| programmedMessage := "Listener has been programmed" | ||
|
|
||
| if listenerErr != nil { | ||
| acceptedStatus = metav1.ConditionFalse | ||
| acceptedReason = "PortUnavailable" | ||
| acceptedMessage = fmt.Sprintf("Failed to start listener: %v", listenerErr) | ||
|
|
||
| programmedStatus = metav1.ConditionFalse | ||
| programmedReason = "Invalid" | ||
| programmedMessage = "Listener could not be programmed due to error" | ||
| } | ||
|
|
||
| acceptedCond := metav1.Condition{ | ||
| Type: string(gatewayv1.ListenerConditionAccepted), | ||
| Status: acceptedStatus, | ||
| Reason: acceptedReason, | ||
| Message: acceptedMessage, | ||
| LastTransitionTime: metav1.Now(), | ||
| ObservedGeneration: generation, | ||
| } | ||
|
|
||
| programmedCond := metav1.Condition{ | ||
| Type: string(gatewayv1.ListenerConditionProgrammed), | ||
| Status: programmedStatus, | ||
| Reason: programmedReason, | ||
| Message: programmedMessage, | ||
| LastTransitionTime: metav1.Now(), | ||
| ObservedGeneration: generation, | ||
| } | ||
|
|
||
| return acceptedCond, programmedCond | ||
| } | ||
|
|
||
| func (c *GatewayController) enqueueGateway(obj interface{}) { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain why set nil(// Clear listener status in store)