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

Add conditions and patch helpers, and docs to runtime #101

Merged
merged 28 commits into from
Jul 7, 2021

Conversation

hiddeco
Copy link
Member

@hiddeco hiddeco commented May 14, 2021

This pull request introduces conditions and patch helper packages to runtime, and documents all runtime code and related API packages to a bare minimum in a hope to drive implementation efforts.

Fixes #117

hiddeco added a commit to fluxcd/source-controller that referenced this pull request May 17, 2021
This commit loosely implements the events and metrics helpers that have
been newly introduced to `fluxcd/pkg/runtime`, and heavily reduces code
duplication. It is in preparation of a much bigger overhaul to
implement the work pending in fluxcd/pkg#101.

While implementing, I ran into little annoyances that likely should be
addressed before the "official" `runtime` MINOR release:

- Passing `nil` every time there isn't any metadata for an event quickly
  becomes cumbersome; we should look into an `EventWithMetadata` and/or
  `EventfWithMetadata`, or some other way to _optionally_ provide
  metadata without annoying the consumer.
- There is an inconsistency in the method names of the metric helper,
  i.e. `RecordReadinessMetric` vs `RecordSuspend`. We either need to
  append or remove the `Metric` suffix on all recording methods.

Signed-off-by: Hidde Beydals <hello@hidde.co>
hiddeco added a commit to fluxcd/source-controller that referenced this pull request Jun 14, 2021
This commit loosely implements the events and metrics helpers that have
been newly introduced to `fluxcd/pkg/runtime`, and heavily reduces code
duplication. It is in preparation of a much bigger overhaul to
implement the work pending in fluxcd/pkg#101.

While implementing, I ran into little annoyances that likely should be
addressed before the "official" `runtime` MINOR release:

- Passing `nil` every time there isn't any metadata for an event quickly
  becomes cumbersome; we should look into an `EventWithMetadata` and/or
  `EventfWithMetadata`, or some other way to _optionally_ provide
  metadata without annoying the consumer.
- There is an inconsistency in the method names of the metric helper,
  i.e. `RecordReadinessMetric` vs `RecordSuspend`. We either need to
  append or remove the `Metric` suffix on all recording methods.

Signed-off-by: Hidde Beydals <hello@hidde.co>
@hiddeco hiddeco force-pushed the conditions-patch-helpers branch 2 times, most recently from 88061f2 to a8405cb Compare June 23, 2021 11:12
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

Thanks @hiddeco 🥇

@hiddeco hiddeco force-pushed the conditions-patch-helpers branch 7 times, most recently from 2ac95df to 18c56eb Compare July 5, 2021 18:17
@hiddeco hiddeco force-pushed the conditions-patch-helpers branch 2 times, most recently from 9301197 to 57a37ad Compare July 6, 2021 10:18
@hiddeco hiddeco marked this pull request as ready for review July 6, 2021 10:24
@@ -21,19 +21,19 @@ const (
// outside of the defined schedule. Despite the name, the value is not
// interpreted as a timestamp, and any change in value shall trigger a
// reconciliation.
// DEPRECATED: has been replaced by ReconcileRequestAnnotation.
// DEPRECATED: has been replaced by ReconcileRequestAnnotation. For
Copy link
Member

Choose a reason for hiding this comment

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

I think it's time to remove this, we've switched all controllers to ReconcileRequestAnnotation in 2020.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would probably do this in a separate PR to not incorporate more "hidden" breaking changes in this one.

Copy link
Member

@squaremo squaremo left a comment

Choose a reason for hiding this comment

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

Lots of goodies here 🎉, representing much valuable work. In particular, I want to applaud the explanations for why someone should use these things, and the examples of how to use them. The explanations are great because they describe the benefit to the user of the library, rather than just what will happen.

NB I only skimmed the stuff adapted from Kubernetes' libraries, noting that it has plenty of tests.

@@ -0,0 +1,302 @@
/*
Copyright 2020 The Kubernetes Authors.
Copyright 2021 The Flux authors
Copy link
Member

Choose a reason for hiding this comment

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

I think to comply with the license (https://www.apache.org/licenses/LICENSE-2.0, section 4):

  • "You must cause any modified files to carry prominent notices stating that You changed the files"
  • "You may add Your own copyright statement to Your modifications"

I'm not sure exactly what these entail, but I think it would work to use the format:

Copyright 2020 The Kubernetes Authors.

This file is modified from the source at <url> to

 - adapt the Foo interface to better suit this project
 - ...

Modifications copyright 2021 the Flux authors

Copy link
Member Author

@hiddeco hiddeco Jul 7, 2021

Choose a reason for hiding this comment

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

Given keeping a list with modifications is not realistic, I opted for the following format:

This file is modified from the source at
<url>,
and initially adapted to <reason for copying and making modifications>.

// deal with more complex logic in which for example a finite error state can be observed, it is RECOMMENDED to
// implement the StalledCondition and ReconcilingCondition.
//
// By doing this, observers making use of kstatus to determine the current state of the resource will have a better
Copy link
Member

Choose a reason for hiding this comment

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

<3 this explanation

apis/meta/conditions.go Show resolved Hide resolved
runtime/controller/doc.go Outdated Show resolved Hide resolved
runtime/predicates/doc.go Outdated Show resolved Hide resolved
This commit adds a helper to work with the conditions of GitOps Toolkit
object kinds, including but not limited to aggregration,
summarization and mirroring of condition types.

The work has been derived from
https://github.com/kubernetes-sigs/cluster-api/tree/7478817225e0a75acb6e14fc7b438231578073d2/util/conditions
but adapted to work with the `metav1.Condition` and
`metav1.ConditionStatus` types.

More concretely, this includes the removal of "condition severity"
related functionalities, as this is not supported by the
`metav1.Condition` type.

The following work is still required before it can be considered ready
for consumption:

* Support for "negative polarity" or "normal-false" conditions; this is
  required to properly support the `Stalled` and `Reconciling`
  conditions of `meta` (and `kstatus`).
* Summarization to other target conditions than `Ready`; results in a
  more generic API.
* Support setting the `ObservedGeneration` in the status condition.

Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit adds support for negative polarity conditions, also
known as "normal-false" or "abnormal-true" types[1], during merge and
set operations.

The polarity is taken into account during sort operations, and results
in the following order:

- P0 - Status=True, NegativePolarity=True
- P1 - Status=False, NegativePolarity=False
- P2 - Condition=True, NegativePolarity=False
- P3 - Status=False, NegativePolarity=True
- P4 - Status=Unknown

This order ensures that condifitions of most importance to the user are
listed first.

[1]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties

Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit ensures `Stalled`, `Ready` and `Reconciling` conditions
are always ordered first while setting and merging conditions.

This eases usage for end-users that are observing a resource via e.g.
`kubectl`, and provides better integration with `kstatus`:
https://github.com/kubernetes-sigs/cli-utils/blob/master/pkg/kstatus/README.md#conditions

Signed-off-by: Hidde Beydals <hello@hidde.co>
hiddeco added 19 commits July 7, 2021 21:46
Signed-off-by: Hidde Beydals <hello@hidde.co>
This includes the renaming and introduction of a set of interfaces around
working with objects that follow GitOps Toolkit conventions.

Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit makes the runtime dependency package use the API structs
and interface from our own meta package, and aligns the way we make
assumptions about objects being being controller-runtime compatible
options with that of the other helper packages like `controller` and
`conditions`.

Signed-off-by: Hidde Beydals <hello@hidde.co>
Quite a lot of the errors in the package had close to the same meaning,
or could be used together with a context defining wrapping error. They
also assumed knowledge of component implementation details at times.

This commit de-duplicates the and removes the errors in these category,
and also properly documents them.

Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Extension includes the default configuration of mutex profiling, and
inclusion of additional endpoints.

Signed-off-by: Hidde Beydals <hello@hidde.co>
Including some `go <vet|fmt>` changes.

Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
Signed-off-by: Hidde Beydals <hello@hidde.co>
@hiddeco hiddeco changed the title Add conditions and patch helper to runtime Add conditions and patch helper and docs to runtime Jul 7, 2021
@hiddeco hiddeco merged commit 11abd07 into main Jul 7, 2021
@hiddeco hiddeco deleted the conditions-patch-helpers branch July 7, 2021 19:58
@hiddeco hiddeco changed the title Add conditions and patch helper and docs to runtime Add conditions and patch helpers, and docs to runtime Jul 7, 2021
@hiddeco hiddeco added area/runtime Controller runtime related issues and pull requests area/api API related issues and pull requests labels Jul 8, 2021
hiddeco added a commit to fluxcd/source-controller that referenced this pull request Jul 13, 2021
This commit loosely implements the events and metrics helpers that have
been newly introduced to `fluxcd/pkg/runtime`, and heavily reduces code
duplication. It is in preparation of a much bigger overhaul to
implement the work pending in fluxcd/pkg#101.

While implementing, I ran into little annoyances that likely should be
addressed before the "official" `runtime` MINOR release:

- Passing `nil` every time there isn't any metadata for an event quickly
  becomes cumbersome; we should look into an `EventWithMetadata` and/or
  `EventfWithMetadata`, or some other way to _optionally_ provide
  metadata without annoying the consumer.
- There is an inconsistency in the method names of the metric helper,
  i.e. `RecordReadinessMetric` vs `RecordSuspend`. We either need to
  append or remove the `Metric` suffix on all recording methods.

Signed-off-by: Hidde Beydals <hello@hidde.co>
hiddeco added a commit to fluxcd/source-controller that referenced this pull request Jul 15, 2021
This commit loosely implements the events and metrics helpers that have
been newly introduced to `fluxcd/pkg/runtime`, and heavily reduces code
duplication. It is in preparation of a much bigger overhaul to
implement the work pending in fluxcd/pkg#101.

While implementing, I ran into little annoyances that likely should be
addressed before the "official" `runtime` MINOR release:

- Passing `nil` every time there isn't any metadata for an event quickly
  becomes cumbersome; we should look into an `EventWithMetadata` and/or
  `EventfWithMetadata`, or some other way to _optionally_ provide
  metadata without annoying the consumer.
- There is an inconsistency in the method names of the metric helper,
  i.e. `RecordReadinessMetric` vs `RecordSuspend`. We either need to
  append or remove the `Metric` suffix on all recording methods.

Signed-off-by: Hidde Beydals <hello@hidde.co>
hiddeco added a commit to fluxcd/source-controller that referenced this pull request Jul 27, 2021
This commit loosely implements the events and metrics helpers that have
been newly introduced to `fluxcd/pkg/runtime`, and heavily reduces code
duplication. It is in preparation of a much bigger overhaul to
implement the work pending in fluxcd/pkg#101.

While implementing, I ran into little annoyances that likely should be
addressed before the "official" `runtime` MINOR release:

- Passing `nil` every time there isn't any metadata for an event quickly
  becomes cumbersome; we should look into an `EventWithMetadata` and/or
  `EventfWithMetadata`, or some other way to _optionally_ provide
  metadata without annoying the consumer.
- There is an inconsistency in the method names of the metric helper,
  i.e. `RecordReadinessMetric` vs `RecordSuspend`. We either need to
  append or remove the `Metric` suffix on all recording methods.

Signed-off-by: Hidde Beydals <hello@hidde.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api API related issues and pull requests area/runtime Controller runtime related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document runtime package and APIs, provide additional helpers
3 participants