Skip to content
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

feat: add annotations for external service host and port in MR service, fixes RHOAIENG-11092 #125

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/controller/config/templates/service.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ 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-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
Expand Down
57 changes: 34 additions & 23 deletions internal/controller/modelregistry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down