From 2fbcca3fba4da3ef09a78c6b7e9caa7c3359c68e Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Wed, 21 Aug 2024 22:32:11 -0700 Subject: [PATCH 1/2] feat: add annotations for external service host and port in MR service, fixes RHOAIENG-11092 --- .../config/templates/service.yaml.tmpl | 6 ++ .../controller/modelregistry_controller.go | 57 +++++++++++-------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/internal/controller/config/templates/service.yaml.tmpl b/internal/controller/config/templates/service.yaml.tmpl index 8b9db5e..e2443ba 100644 --- a/internal/controller/config/templates/service.yaml.tmpl +++ b/internal/controller/config/templates/service.yaml.tmpl @@ -12,6 +12,12 @@ metadata: app.kubernetes.io/created-by: model-registry-operator app.kubernetes.io/part-of: model-registry app.kubernetes.io/managed-by: model-registry-operator + annotations: + {{- if and .Spec.Istio .Spec.Istio.Gateway .Spec.Istio.Gateway.Domain}} + routing.opendatahub.io/external-address: {{.Name}}-rest.{{.Spec.Istio.Gateway.Domain}}:{{.Spec.Istio.Gateway.Rest.Port}} + routing.opendatahub.io/external-address-rest: {{.Name}}-rest.{{.Spec.Istio.Gateway.Domain}}:{{.Spec.Istio.Gateway.Rest.Port}} + routing.opendatahub.io/external-address-grpc: {{.Name}}-grpc.{{.Spec.Istio.Gateway.Domain}}:{{.Spec.Istio.Gateway.Grpc.Port}} + {{- end}} spec: ports: - name: grpc-api diff --git a/internal/controller/modelregistry_controller.go b/internal/controller/modelregistry_controller.go index 98f521e..b55b8d1 100644 --- a/internal/controller/modelregistry_controller.go +++ b/internal/controller/modelregistry_controller.go @@ -194,6 +194,13 @@ func (r *ModelRegistryReconciler) Reconcile(ctx context.Context, req ctrl.Reques } } + // set defaults in registry from reconciler + err = r.setRegistryDefaults(ctx, modelRegistry) + if err != nil { + log.Error(err, "error setting registry defaults") + return ctrl.Result{}, err + } + params := &ModelRegistryParams{ Name: req.Name, Namespace: req.Namespace, @@ -605,23 +612,6 @@ func (r *ModelRegistryReconciler) createOrUpdateGateway(ctx context.Context, par registry *modelregistryv1alpha1.ModelRegistry, templateName string) (result OperationResult, err error) { result = ResourceUnchanged - - updated := false - // autoconfigure domain if needed - if len(registry.Spec.Istio.Gateway.Domain) == 0 { - err = r.setClusterDomain(ctx, registry) - if err != nil { - return result, err - } - updated = true - } - // set default cert if needed - updated = updated || r.setDefaultCert(registry) - if updated { - // update current reconcile spec - params.Spec = registry.Spec - } - var gateway networking.Gateway if err = r.Apply(params, templateName, &gateway); err != nil { return result, err @@ -635,11 +625,33 @@ func (r *ModelRegistryReconciler) createOrUpdateGateway(ctx context.Context, par return result, err } - if !updated { - return result, nil - } else { - return ResourceUpdated, nil + return result, nil +} + +func (r *ModelRegistryReconciler) setRegistryDefaults(ctx context.Context, registry *modelregistryv1alpha1.ModelRegistry) (err error) { + + if registry.Spec.Istio == nil || registry.Spec.Istio.Gateway == nil { + return nil + } + + // autoconfigure domain if needed + domainUpdated := false + if len(registry.Spec.Istio.Gateway.Domain) == 0 { + err = r.setClusterDomain(ctx, registry) + if err != nil { + return err + } + domainUpdated = true } + + // set default cert if needed + certUpdated := r.setDefaultCert(registry) + + // update registry if domain or cert were updated + if domainUpdated || certUpdated { + err = r.Client.Update(ctx, registry) + } + return err } func (r *ModelRegistryReconciler) createOrUpdateAuthConfig(ctx context.Context, params *ModelRegistryParams, @@ -1008,8 +1020,7 @@ func (r *ModelRegistryReconciler) setClusterDomain(ctx context.Context, registry return fmt.Errorf("model registry %s is missing gateway domain and default domain is not configured", registry.Name) } - // update domain in model registry resource - return r.Client.Update(ctx, registry) + return nil } func (r *ModelRegistryReconciler) setDefaultCert(registry *modelregistryv1alpha1.ModelRegistry) bool { From a4ad175e9d70f82561f3c36c7852dd932c55078a Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Thu, 22 Aug 2024 13:19:53 -0700 Subject: [PATCH 2/2] fix: remove unprefixed non protocol annotation --- internal/controller/config/templates/service.yaml.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/controller/config/templates/service.yaml.tmpl b/internal/controller/config/templates/service.yaml.tmpl index e2443ba..d5e56ce 100644 --- a/internal/controller/config/templates/service.yaml.tmpl +++ b/internal/controller/config/templates/service.yaml.tmpl @@ -14,7 +14,6 @@ metadata: app.kubernetes.io/managed-by: model-registry-operator annotations: {{- if and .Spec.Istio .Spec.Istio.Gateway .Spec.Istio.Gateway.Domain}} - routing.opendatahub.io/external-address: {{.Name}}-rest.{{.Spec.Istio.Gateway.Domain}}:{{.Spec.Istio.Gateway.Rest.Port}} routing.opendatahub.io/external-address-rest: {{.Name}}-rest.{{.Spec.Istio.Gateway.Domain}}:{{.Spec.Istio.Gateway.Rest.Port}} routing.opendatahub.io/external-address-grpc: {{.Name}}-grpc.{{.Spec.Istio.Gateway.Domain}}:{{.Spec.Istio.Gateway.Grpc.Port}} {{- end}}