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

fix: delete istio resources when istio is disabled, fixes RHOAIENG-5158 #84

Merged
merged 3 commits into from
Apr 8, 2024
Merged
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
83 changes: 70 additions & 13 deletions internal/controller/modelregistry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,23 @@ func (r *ModelRegistryReconciler) updateRegistryResources(ctx context.Context, p
}
}

if registry.Spec.Istio != nil {
result2, err = r.createOrUpdateIstioConfig(ctx, params, registry)
if err != nil {
return result2, err
}
if result2 != ResourceUnchanged {
result = result2
if r.HasIstio {
if registry.Spec.Istio != nil {
result2, err = r.createOrUpdateIstioConfig(ctx, params, registry)
if err != nil {
return result2, err
}
if result2 != ResourceUnchanged {
result = result2
}
} else {
result2, err = r.deleteIstioConfig(ctx, params)
if err != nil {
return result2, err
}
if result2 != ResourceUnchanged {
result = result2
}
}
}

Expand Down Expand Up @@ -449,17 +459,64 @@ func (r *ModelRegistryReconciler) createOrUpdateIstioConfig(ctx context.Context,
result = result2
}

result2, err = r.createOrUpdateGateway(ctx, params, registry, "gateway.yaml.tmpl")
if err != nil {
return result2, err
}
if result2 != ResourceUnchanged {
result = result2
if params.Spec.Istio.Gateway != nil {
result2, err = r.createOrUpdateGateway(ctx, params, registry, "gateway.yaml.tmpl")
if err != nil {
return result2, err
}
if result2 != ResourceUnchanged {
result = result2
}
} else {
// remove gateway if it exists
if err = r.deleteGatewayConfig(ctx, params); err != nil {
return ResourceUpdated, err
}
}

return result, nil
}

func (r *ModelRegistryReconciler) deleteIstioConfig(ctx context.Context, params *ModelRegistryParams) (OperationResult, error) {
var err error

objectMeta := metav1.ObjectMeta{Name: params.Name, Namespace: params.Namespace}
virtualService := networking.VirtualService{ObjectMeta: objectMeta}
if err = r.Client.Delete(ctx, &virtualService); client.IgnoreNotFound(err) != nil {
return ResourceUpdated, err
}

destinationRule := networking.DestinationRule{ObjectMeta: objectMeta}
if err = r.Client.Delete(ctx, &destinationRule); client.IgnoreNotFound(err) != nil {
return ResourceUpdated, err
}

authorizationPolicy := security.AuthorizationPolicy{ObjectMeta: objectMeta}
authorizationPolicy.Name = authorizationPolicy.Name + "-authorino"
if err = r.Client.Delete(ctx, &authorizationPolicy); client.IgnoreNotFound(err) != nil {
return ResourceUpdated, err
}

authConfig := authorino.AuthConfig{ObjectMeta: objectMeta}
if err = r.Client.Delete(ctx, &authConfig); client.IgnoreNotFound(err) != nil {
return ResourceUpdated, err
}

if err = r.deleteGatewayConfig(ctx, params); err != nil {
return ResourceUpdated, err
}

return ResourceUnchanged, nil
}

func (r *ModelRegistryReconciler) deleteGatewayConfig(ctx context.Context, params *ModelRegistryParams) error {
gateway := networking.Gateway{ObjectMeta: metav1.ObjectMeta{Name: params.Name, Namespace: params.Namespace}}
if err := r.Client.Delete(ctx, &gateway); client.IgnoreNotFound(err) != nil {
return err
}
return nil
}

func (r *ModelRegistryReconciler) createOrUpdateGateway(ctx context.Context, params *ModelRegistryParams,
registry *modelregistryv1alpha1.ModelRegistry, templateName string) (result OperationResult, err error) {
result = ResourceUnchanged
Expand Down