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

Prepare Helm release logic rewrite #477

Merged
merged 5 commits into from
May 9, 2022
Merged

Prepare Helm release logic rewrite #477

merged 5 commits into from
May 9, 2022

Conversation

hiddeco
Copy link
Member

@hiddeco hiddeco commented May 6, 2022

In short (see individual commits for further detail):

  • Introduce a Helm storage observer to keep track of writes to the storage.
  • Move HelmChart handling to a separate reconciler.
  • Factor various bits out of the reconciler to slim it down to almost only Helm release related things.
  • Move some elements to their own homes.

⚠️ This is merged into dev, given the total size of the work. I am going to follow up with more PRs.

@hiddeco hiddeco added the enhancement New feature or request label May 6, 2022
@hiddeco hiddeco added this to the GA milestone May 6, 2022
@hiddeco hiddeco force-pushed the prepare-rewrite branch from 7ae7f4d to 576ef27 Compare May 6, 2022 11:28
@hiddeco hiddeco force-pushed the prepare-rewrite branch from 576ef27 to 4ab6418 Compare May 6, 2022 12:09
internal/kube/builder.go Outdated Show resolved Hide resolved
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Overall it is looking really good. Great job @hiddeco!

internal/storage/observer.go Outdated Show resolved Hide resolved
@hiddeco hiddeco force-pushed the prepare-rewrite branch from 4ab6418 to ca71ba0 Compare May 6, 2022 15:55
@hiddeco hiddeco changed the title Prepare release logic rewrite Prepare Helm release logic rewrite May 6, 2022
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

LGTM

@hiddeco hiddeco force-pushed the prepare-rewrite branch from ca71ba0 to aff5d9f Compare May 6, 2022 17:00
@hiddeco
Copy link
Member Author

hiddeco commented May 6, 2022

Something is making the current end-to-end tests take precisely 5 minutes (and a little more) to be marked as Ready. I am unable to produce this locally however (using the same testdata), so am inclined to say it has something to do with the bash magic in CI.

In any case, taking a note here, but not going to invest time in it now. As the tests are going to reworked anyway.

internal/storage/observer.go Outdated Show resolved Hide resolved
internal/storage/observer.go Outdated Show resolved Hide resolved
internal/storage/observer.go Outdated Show resolved Hide resolved
internal/storage/observer.go Show resolved Hide resolved
obj.Status.HelmChart = ""
}

if obj.DeletionTimestamp != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a new check in all the various reconcileDelete() implementations.
Is this necessary in certain situations or just added it here for safety?

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 is new because reconcileDelete can happen both due to a change, and due to Reconcile calling it due to DeletionTimestamp != nil. Given this, it gate keeps a change from removing the finalizer.

@hiddeco hiddeco force-pushed the prepare-rewrite branch 2 times, most recently from 5e6cf57 to 4a79e96 Compare May 9, 2022 10:18
hiddeco added 5 commits May 9, 2022 12:21
This adds an observer which wraps around a Helm storage driver, to keep
track of the release metadata as written to the storage. This enables
you to work with, and compare release data as persisted by Helm.
Without having to rely on the result as returned by the Helm SDK. Which
at times of an error, may differ from last written state.

The observer does at present expect to be watching a single namespace,
and was designed without working with multiple releases simultianiously
into account, although this should theoretically still work.

The releases are at stored in a simple map by index storage key, which
are unique to the namespace. The `ObservedRelease` objects the keys hold are
overwritten on sequential writes to the same release object, and
returned by getter methods as deep copies.

This could theoretically be changed to observing e.g. all writes, I have
left this as a refinement TODO while actually implementing it in the
reconciler. The same goes for the included metadata, which might be not
all relevant.

Signed-off-by: Hidde Beydals <[email protected]>
This moves the HelmChart template handling to a separate reconciler,
with predicates detecing relevant changes. The idea is that this would
both facilitate working _without_ chart templates but with references
in the future, and to reduce cognitive load while working with
reconciler logic.

The predicate uses cmp.Equal to inspect the Chart template objects of
the old and new HelmRelease object in the update vent.

The reconciler uses cmp.Diff with a custom SimpleReporter, to reduce
the output to a minimum. Example:

```
//  Path:
//  -old
//  +new
//
//  Path.Nested:
//  -removed
//
//  Path.Other:
//  +added
```

The implementation on the release reconciler's end is a rough sketch,
but in working shape. The foresight is that much of the reconciler will
change when the release logic will be adjusted to work with the earlier
introduced storage observer.

Signed-off-by: Hidde Beydals <[email protected]>
This commit moves various generic bits out of the reconciler into
separate modules, while adding more test coverage.

Some of the logic around merging chart values from references has been
improved to work with `client.Object`, instead of two separate maps.

In addition, the option to override the hostname of an Artifact has
been removed. It was undocumented and for testing purposes only, which
these days can be better achieved by e.g. configuring the
`--storage-adv-addr`.

Signed-off-by: Hidde Beydals <[email protected]>
Plus change the tests a tiny bit to work with Gomega, and break the
further API free from direct attachment to our Helm API objects.

Signed-off-by: Hidde Beydals <[email protected]>
@hiddeco hiddeco force-pushed the prepare-rewrite branch from 4a79e96 to 0b02c82 Compare May 9, 2022 10:21
Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

@hiddeco hiddeco merged commit 37eb919 into dev May 9, 2022
@hiddeco hiddeco deleted the prepare-rewrite branch May 9, 2022 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants