-
-
Notifications
You must be signed in to change notification settings - Fork 47
Fix watch for changes to LeaderWorkerSet created by llmaz and trigger a Reconcile for the owner #108
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
Merged
Merged
Fix watch for changes to LeaderWorkerSet created by llmaz and trigger a Reconcile for the owner #108
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ import ( | |
| "sigs.k8s.io/controller-runtime/pkg/builder" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/apiutil" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
| "sigs.k8s.io/controller-runtime/pkg/event" | ||
| "sigs.k8s.io/controller-runtime/pkg/handler" | ||
| "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
|
@@ -81,6 +82,24 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request) | |
|
|
||
| logger.V(10).Info("reconcile Playground", "Playground", klog.KObj(playground)) | ||
|
|
||
| service := &inferenceapi.Service{} | ||
| if err := r.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service); err == nil { | ||
| if !controllerutil.HasControllerReference(service) { | ||
| condition := metav1.Condition{ | ||
| Type: inferenceapi.PlaygroundProgressing, | ||
| Status: metav1.ConditionFalse, | ||
| Reason: "AbortProcessing", | ||
| Message: "Playground owns the same name with an existing Service", | ||
| } | ||
| apimeta.SetStatusCondition(&playground.Status.Conditions, condition) | ||
| if err := r.Client.Status().Update(ctx, playground); err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
| // No need to requeue. Once the Service is deleted, the Playground will be reconciled. | ||
| return ctrl.Result{}, nil | ||
| } | ||
| } | ||
|
|
||
| var serviceApplyConfiguration *inferenceclientgo.ServiceApplyConfiguration | ||
|
|
||
| model := &coreapi.OpenModel{} | ||
|
|
@@ -94,7 +113,6 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request) | |
| } | ||
|
|
||
| // TODO: handle MultiModelsClaims in the future. | ||
|
|
||
| if err := setControllerReferenceForService(playground, serviceApplyConfiguration, r.Scheme); err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
|
|
@@ -104,7 +122,7 @@ func (r *PlaygroundReconciler) Reconcile(ctx context.Context, req ctrl.Request) | |
| } | ||
|
|
||
| // Handle status. | ||
| service := &inferenceapi.Service{} | ||
| service = &inferenceapi.Service{} | ||
| if err := r.Get(ctx, types.NamespacedName{Name: playground.Name, Namespace: playground.Namespace}, service); err != nil { | ||
| return ctrl.Result{}, err | ||
| } | ||
|
|
@@ -272,7 +290,7 @@ func buildWorkerTemplate(model *coreapi.OpenModel, playground *inferenceapi.Play | |
|
|
||
| func setPlaygroundCondition(playground *inferenceapi.Playground, service *inferenceapi.Service) { | ||
| // For the start up. | ||
| if len(playground.Status.Conditions) == 0 { | ||
| if len(playground.Status.Conditions) == 0 || !apimeta.IsStatusConditionTrue(service.Status.Conditions, inferenceapi.PlaygroundProgressing) { | ||
|
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. This should also be refactored once introducing the pending for model creation condition. Because not progressing doesn't mean it's waiting for inferenceService ready. |
||
| condition := metav1.Condition{ | ||
| Type: inferenceapi.PlaygroundProgressing, | ||
| Status: metav1.ConditionTrue, | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| Copyright 2022 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // Copy from https://github.com/kubernetes/kubernetes/blob/master/test/utils/format/format.go | ||
|
|
||
| // Package format is an extension of Gomega's format package which | ||
| // improves printing of objects that can be serialized well as YAML, | ||
| // like the structs in the Kubernetes API. | ||
| // | ||
| // Just importing it is enough to activate this special YAML support | ||
| // in Gomega. | ||
| package format | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "strings" | ||
|
|
||
| "github.com/onsi/gomega/format" | ||
|
|
||
| "sigs.k8s.io/yaml" | ||
| ) | ||
|
|
||
| func init() { | ||
| format.RegisterCustomFormatter(handleYAML) | ||
| } | ||
|
|
||
| // Object makes Gomega's [format.Object] available without having to import that | ||
| // package. | ||
| func Object(object interface{}, indentation uint) string { | ||
| return format.Object(object, indentation) | ||
| } | ||
|
|
||
| // handleYAML formats all values as YAML where the result | ||
| // is likely to look better as YAML: | ||
| // - pointer to struct or struct where all fields | ||
| // have `json` tags | ||
| // - slices containing such a value | ||
| // - maps where the key or value are such a value | ||
| func handleYAML(object interface{}) (string, bool) { | ||
| value := reflect.ValueOf(object) | ||
| if !useYAML(value.Type()) { | ||
| return "", false | ||
| } | ||
| y, err := yaml.Marshal(object) | ||
| if err != nil { | ||
| return "", false | ||
| } | ||
| return "\n" + strings.TrimSpace(string(y)), true | ||
| } | ||
|
|
||
| func useYAML(t reflect.Type) bool { | ||
| switch t.Kind() { | ||
| case reflect.Pointer, reflect.Slice, reflect.Array: | ||
| return useYAML(t.Elem()) | ||
| case reflect.Map: | ||
| return useYAML(t.Key()) || useYAML(t.Elem()) | ||
| case reflect.Struct: | ||
| // All fields must have a `json` tag. | ||
| for i := 0; i < t.NumField(); i++ { | ||
| field := t.Field(i) | ||
| if _, ok := field.Tag.Lookup("json"); !ok { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } |
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
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.
We should collect all the condition handlers to one place just like
setPlaygroundConditionbut this can be a follow up when implementing the Pending status for waiting for model creation.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.
ok