Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

add items to dynamic watch in helm #517

Merged
merged 1 commit into from
Oct 12, 2022

Conversation

akihikokuroda
Copy link
Member

Closes #514

Signed-off-by: akihikokuroda akuroda@us.ibm.com

@akihikokuroda akihikokuroda requested a review from a team as a code owner August 22, 2022 18:02
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 22, 2022
@akihikokuroda akihikokuroda changed the title [WIP] add items to dynamicwtach in helm add items to dynamicwtach in helm Aug 22, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 22, 2022
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

This seems to take a different approach than the plain provisioner. Should this with how the plain provisioner works? That would hopefully make it easier to find re-use opportunities in the future, and it would ensure the UX is generally the same for both.

@akihikokuroda
Copy link
Member Author

@joelanford The UX should be the same. It is doing the same thing as the plain provisioner but it can not do the same way. It is adding to the watch using the release.manifest after the install because the yaml files in the charts can not be decoded without the rendering. It is adding the labels using the postrenderer because it must be done against the rendered objects.

@joelanford
Copy link
Member

Oh right. In Plain, we know the full content of the "templates" ahead of time. In Helm, we have to run the chart through the helm libraries to know what the resulting manifest is.

One other thing that comes to mind. We use a post-renderer under the hood in the helm-operator-plugins repo to inject owner references. If we override the post-renderer to set these labels, we might be overriding the ownerref post renderer.

@akihikokuroda
Copy link
Member Author

If we override the post-renderer to set these labels, we might be overriding the ownerref post renderer.

Yes, I found that. I added the ownerref injection in the post-render function.

@joelanford
Copy link
Member

Not blocking for this PR, but I imagine that unknowingly setting a post-renderer like you did could be a footgun for others. I wonder if there's a way in helm-operator-plugins to support adding more caller-defined post-renderers to the chain.

@akihikokuroda
Copy link
Member Author

I made changes to call the preset PostRenderer after our PostRenderer if it is set.

@joelanford
Copy link
Member

joelanford commented Aug 24, 2022

@akihikokuroda I've got a PR up in helm-operator-plugins that I think should get rid of the awkward hacking you had to do to use both the built-in and extra post-renderer.

operator-framework/helm-operator-plugins#195

@akihikokuroda akihikokuroda force-pushed the reconcile branch 2 times, most recently from 02920f9 to 2a9a878 Compare August 25, 2022 21:58
Copy link
Member

@timflannagan timflannagan left a comment

Choose a reason for hiding this comment

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

These changes seem reasonable. If we're hacking around the helm-operator-plugins implementation here, does it make sense to create a ticket that tracks cleaning up the implementation once Joe's changes land and a new release is cut?

break
}
if err != nil {
return fmt.Errorf("read %q: %v", obj, err)
Copy link
Member

Choose a reason for hiding this comment

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

Is printing the obj here potentially problem for logs? Or does this just print the metadata information we care about?

Copy link
Member Author

Choose a reason for hiding this comment

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

The err has enough information. I take out the obj.

@@ -286,7 +323,7 @@ const (
stateError releaseState = "Error"
)

func (r *BundleDeploymentReconciler) getReleaseState(cl helmclient.ActionInterface, obj metav1.Object, chrt *chart.Chart, values chartutil.Values) (*release.Release, releaseState, error) {
func (r *BundleDeploymentReconciler) getReleaseState(cl helmclient.ActionInterface, obj metav1.Object, chrt *chart.Chart, values chartutil.Values, post *postrenderer) (*release.Release, releaseState, error) {
Copy link
Member

Choose a reason for hiding this comment

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

We may want/need a tech debt ticket here given the number of parameters for this method.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I'll add a TODO comment.

if err != nil {
return currentRelease, stateError, err
}
if desiredRelease.Manifest != currentRelease.Manifest ||
!reflect.DeepEqual(desiredRelease.Chart.Metadata, currentRelease.Chart.Metadata) ||
Copy link
Member

Choose a reason for hiding this comment

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

Any idea on why this comparison is needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is checking for the changes in Chart.yaml file. It's contents are here.

@@ -251,6 +278,16 @@ func (r *BundleDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
}),
updater.EnsureInstalledName(bundle.GetName()),
)
if err := r.addDynamicWatch(cl, bd, bundle); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This feels like something the plain provisioner could also hook into?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is checking for the changes in Chart.yaml file. The plain provisioner is generating the contents of the Chart.yam file on the fly so it's always same.

rel, state, err := r.getReleaseState(cl, bd, chrt, values)
post := &postrenderer{
labels: map[string]string{
util.CoreOwnerKindKey: "BundleDeployment",
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we have a const variable somewhere for the BD GVK.

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't seem defined.

@akihikokuroda
Copy link
Member Author

@timflannagan I created the issue for refactoring. #534

@timflannagan
Copy link
Member

Awesome. Follow-up question: do we think it would be valuable to also add a comment linking to that issue for the postrenderer hacks?

@akihikokuroda
Copy link
Member Author

akihikokuroda commented Aug 26, 2022

That's a good idea. I'll do it.

Refactor issue: #534

@akihikokuroda akihikokuroda force-pushed the reconcile branch 2 times, most recently from 6169128 to 6be4583 Compare August 31, 2022 13:29
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2022
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 23, 2022
@akihikokuroda
Copy link
Member Author

Refactor has done. Please review.

Comment on lines 505 to 507
For(&rukpakv1alpha1.BundleDeployment{}, builder.WithPredicates(
util.BundleDeploymentProvisionerFilter(plain.ProvisionerID)),
).
Copy link
Member

Choose a reason for hiding this comment

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

I haven't had a chance to look over the new directory structure since #447 landed: we're specifying the plain.ProvisionerID here, and filtering BundleDeployments that don't match that unique provisioner class ID from the cache. Is that the right read here? If so, I think we'll need to solve this in an agnostic way s.t. our core provisioners can leverage this functionality without inter-depending on the plain provisioner libraries.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, it's my mistake. This function is not used any more since #447 changes. I'll take this out.

@@ -426,7 +450,13 @@ func (p *bundledeploymentProvisioner) getReleaseState(cl helmclient.ActionInterf
desiredRelease, err := cl.Upgrade(obj.GetName(), p.releaseNamespace, chrt, values, func(upgrade *action.Upgrade) error {
upgrade.DryRun = true
return nil
})
},
// To be refactored issue 534
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we copy/paste the 534 issue link so it's easier to track when reading through the codebase locally?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. It must be better.

rel, state, err := p.getReleaseState(cl, bd, chrt, values)
post := &postrenderer{
labels: map[string]string{
util.CoreOwnerKindKey: "BundleDeployment",
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I'll update.

@timflannagan
Copy link
Member

Sorry for the slow turnaround on this. I've been pretty heads down with other projects/work recently. Can we also re-title this PR to fix the typo?

@akihikokuroda akihikokuroda changed the title add items to dynamicwtach in helm add items to dynamic watch in helm Oct 10, 2022
Signed-off-by: akihikokuroda <akuroda@us.ibm.com>
@timflannagan
Copy link
Member

timflannagan commented Oct 12, 2022

Pulling this down now, and quickly testing it out locally.

Copy link
Member

@timflannagan timflannagan left a comment

Choose a reason for hiding this comment

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

I tested these changes out locally, and it looks like we're good to go:

apiVersion: core.rukpak.io/v1alpha1
kind: BundleDeployment
metadata:
  name: hello-world-helm
  namespace: demo1
spec:
  provisionerClassName: core-rukpak-io-helm
  template:
    metadata:
      labels:
        app: hello-world-helm
    spec:
      provisionerClassName: core-rukpak-io-helm
      source:
        http:
          url: https://github.com/helm/examples/releases/download/hello-world-0.1.0/hello-world-0.1.0.tgz
        type: http

And then deleted the deployment that got created from that Bundle resource a couple of times, and waited for it to be quickly recreated.

I haven't had a chance to catch up the new repository structure, but this looks like a reasonable short term hack while we wait for a release to be cut.

@akihikokuroda akihikokuroda merged commit e430327 into operator-framework:main Oct 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

helm provisioner doesn't dynamically reconcile underlying bundle contents
5 participants