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

Implement template rendering action #1364

Conversation

lburgazzoli
Copy link
Contributor

@lburgazzoli lburgazzoli commented Nov 11, 2024

Description

This PR introduces a new rendering engine that is based on the go text/template package.

The template is rendered to the actual objects taking a subset of the ReconciliationRequest struct: Instance and DSCI so as an example, the ServiceMeshMember template that is part of the model registry component would looks like:

apiVersion: maistra.io/v1
kind: ServiceMeshMember
metadata:
  name: default
  namespace: {{.Instance.Spec.RegistriesNamespace}}
spec:
  controlPlaneRef:
    namespace: {{ .DSCI.Spec.ServiceMesh.ControlPlane.Namespace }}
    name: {{ .DSCI.Spec.ServiceMesh.ControlPlane.Name }}

https://issues.redhat.com/browse/RHOAIENG-15534

How Has This Been Tested?

  1. Enable the model registry component in DSC
  2. Check for the presence of a ServiceMeshMember instance in the model registries namespace named default and that it contains the expected values
  3. Check metrics related to the render action, it should include something like:
# HELP action_renderer_manifests_total Number of rendered resources
# TYPE action_renderer_manifests_total counter
action_renderer_manifests_total{controller="modelregistry",engine="kustomize"} 17
action_renderer_manifests_total{controller="modelregistry",engine="template"} 1

Screenshot or short clip

Merge criteria

  • You have read the contributors guide.
  • Commit messages are meaningful - have a clear and concise summary and detailed explanation of what was changed and why.
  • Pull Request contains a description of the solution, a link to the JIRA issue, and to any dependent or related Pull Request.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@openshift-ci openshift-ci bot requested review from grdryn and ykaliuta November 11, 2024 11:43
@lburgazzoli lburgazzoli requested review from zdtsw and removed request for ykaliuta November 11, 2024 11:43
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 73.56322% with 23 lines in your changes missing coverage. Please review.

Please upload report for BASE (feature-operator-refactor@1209501). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...actions/render/template/action_render_templates.go 73.25% 17 Missing and 6 partials ⚠️
Additional details and impacted files
@@                     Coverage Diff                      @@
##             feature-operator-refactor    #1364   +/-   ##
============================================================
  Coverage                             ?   26.68%           
============================================================
  Files                                ?       55           
  Lines                                ?     4455           
  Branches                             ?        0           
============================================================
  Hits                                 ?     1189           
  Misses                               ?     3125           
  Partials                             ?      141           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@grdryn grdryn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

pkg/controller/predicates/resources/resources.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot added lgtm and removed lgtm labels Nov 12, 2024
@lburgazzoli lburgazzoli requested a review from grdryn November 12, 2024 06:51
var buffer bytes.Buffer

for i := range rr.Templates {
content, err := fs.ReadFile(rr.Templates[i].FS, rr.Templates[i].Path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pat only accept file name not the folder name, not for this PR, but we will need extend it a bit later if we have multiple templates

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you have multiple templates, the you can pass multiple paths, I didn't want to make it over complicated at this stage given we have only a few templates.

But yeah, it would probably be useful. I'll have a look for a follow up PR

pkg/controller/reconciler/component_reconciler_support.go Outdated Show resolved Hide resolved
pkg/controller/predicates/resources/resources.go Outdated Show resolved Hide resolved
Copy link
Member

@zdtsw zdtsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lburgazzoli lburgazzoli requested a review from zdtsw November 12, 2024 09:13
@lburgazzoli
Copy link
Contributor Author

/retest

@openshift-ci openshift-ci bot removed the lgtm label Nov 12, 2024
name: default
namespace: {{.DSCI.Spec.ApplicationsNamespace}}
annotations:
instance-name: {{.Component.Name}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zdtsw renamed Instance -> Component as it sounds better

name: {{.SMM.Name}}
namespace: {{.DSCI.Spec.ApplicationsNamespace}}
annotations:
instance-name: {{.Component.Name}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zdtsw renamed Instance -> Component as it sounds better

@openshift-ci openshift-ci bot added the lgtm label Nov 12, 2024
@lburgazzoli
Copy link
Contributor Author

/retest

1 similar comment
@lburgazzoli
Copy link
Contributor Author

/retest

@openshift-ci openshift-ci bot removed the lgtm label Nov 12, 2024
@lburgazzoli lburgazzoli force-pushed the RHOAIENG-15534-render-template branch from 4b28fa5 to 45a5623 Compare November 12, 2024 21:15
Copy link
Member

@grdryn grdryn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Nov 12, 2024
Copy link

openshift-ci bot commented Nov 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grdryn, zdtsw

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit acd89b8 into opendatahub-io:feature-operator-refactor Nov 12, 2024
8 checks passed
@lburgazzoli lburgazzoli deleted the RHOAIENG-15534-render-template branch November 13, 2024 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants