-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove webhook and add the isvc_service_cert_reconciler again
Signed-off-by: jooho lee <[email protected]>
- Loading branch information
Showing
11 changed files
with
203 additions
and
200 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 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
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
131 changes: 131 additions & 0 deletions
131
controllers/reconcilers/kserve_isvc_service_cert_reconciler.go
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,131 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
package reconcilers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
kservev1beta1 "github.com/kserve/kserve/pkg/apis/serving/v1beta1" | ||
"github.com/opendatahub-io/odh-model-controller/controllers/constants" | ||
"github.com/opendatahub-io/odh-model-controller/controllers/resources" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var _ SubResourceReconciler = (*KserveIsvcServiceReconciler)(nil) | ||
|
||
type KserveIsvcServiceReconciler struct { | ||
client client.Client | ||
serviceHandler resources.ServiceHandler | ||
} | ||
|
||
func NewKserveIsvcServiceReconciler(client client.Client) *KserveIsvcServiceReconciler { | ||
return &KserveIsvcServiceReconciler{ | ||
client: client, | ||
serviceHandler: resources.NewServiceHandler(client), | ||
} | ||
} | ||
|
||
func (r *KserveIsvcServiceReconciler) Delete(ctx context.Context, log logr.Logger, isvc *kservev1beta1.InferenceService) error { | ||
// NOOP - Resources are deleted along with the deletion of InferenceServices | ||
return nil | ||
} | ||
|
||
func (r *KserveIsvcServiceReconciler) Cleanup(_ context.Context, _ logr.Logger, _ string) error { | ||
// NOOP - Resources are deleted along with the deletion of InferenceServices | ||
return nil | ||
} | ||
|
||
func (r *KserveIsvcServiceReconciler) Reconcile(ctx context.Context, log logr.Logger, isvc *kservev1beta1.InferenceService) error { | ||
log.V(1).Info("Reconciling InferenceService Service serving cert") | ||
|
||
// return if Address.URL is not set | ||
if isvc.Status.Address != nil && isvc.Status.Address.URL == nil { | ||
log.V(1).Info("Waiting for the URL as the InferenceService is not ready yet") | ||
return nil | ||
} | ||
|
||
// Create Desired resource | ||
desiredResource, err := r.createDesiredResource(isvc) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Get Existing resource | ||
existingResource, err := r.getExistingResource(ctx, log, isvc) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Process Delta | ||
if err = r.processDelta(ctx, log, desiredResource, existingResource); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (r *KserveIsvcServiceReconciler) createDesiredResource(isvc *kservev1beta1.InferenceService) (*v1.Service, error) { | ||
service := &v1.Service{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "isvc-service", | ||
Annotations: map[string]string{ | ||
constants.ServingCertAnnotationKey: isvc.Name, | ||
}, | ||
}, | ||
} | ||
return service, nil | ||
} | ||
|
||
func (r *KserveIsvcServiceReconciler) getExistingResource(ctx context.Context, log logr.Logger, isvc *kservev1beta1.InferenceService) (*v1.Service, error) { | ||
return r.serviceHandler.FetchService(ctx, log, types.NamespacedName{Name: isvc.Name, Namespace: isvc.Namespace}) | ||
} | ||
|
||
func (r *KserveIsvcServiceReconciler) processDelta(ctx context.Context, log logr.Logger, desiredService *v1.Service, existingService *v1.Service) (err error) { | ||
if isUpdated(desiredService, existingService, log) { | ||
log.V(1).Info("Delta found", "update", existingService.GetName()) | ||
service := existingService.DeepCopy() | ||
if service.Annotations == nil { | ||
service.Annotations = make(map[string]string) | ||
} | ||
service.Annotations = desiredService.Annotations | ||
|
||
if err = r.client.Update(ctx, service); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func isUpdated(desiredService *v1.Service, existingService *v1.Service, log logr.Logger) bool { | ||
if existingService == nil { | ||
log.Info("The service for the InferenceService has not been created yet") | ||
return false | ||
} | ||
deployedAnnotations := existingService.GetAnnotations() | ||
|
||
if len(deployedAnnotations) != 0 { | ||
if val, exists := existingService.Annotations[constants.ServingCertAnnotationKey]; exists { | ||
if val == desiredService.Annotations[constants.ServingCertAnnotationKey] { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
return true | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.