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 GEP-1364 proposal #1383

Merged
merged 7 commits into from
Sep 26, 2022
Merged
Changes from 5 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
389 changes: 389 additions & 0 deletions site-src/geps/gep-1364.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,389 @@
# GEP-1364: Status and Conditions Update

* Issue: [#1364](https://github.com/kubernetes-sigs/gateway-api/issues/1364)
* Status: Implementable

(See definitions in [Kubernetes KEP][kep-status].



## TLDR

The status, particularly the Conditions, across the whole Gateway API have very much
grown organically, and so have many inconsistencies and odd behaviors.
This GEP covers doing a review and consolidation to make Condition behavior consistent
across the whole API.

## Goals

* Update Conditions design to be consistent across Gateway API resources
* Provide a model and guidelines for Conditions for future new resources
* Specify changes to conformance required for Condition updates

## Non-Goals

* Define the full set of Conditions that will ever be used with Gateway API

## Introduction

Gateway API currently has a lot of issues related to status, especially that
status is inconsistent ([#1111][1111]), that names are hard to understand ([#1110][1110]),
and that Reasons aren't explained properly ([#1362][1362]).

As the API has grown, the way we talk about resources has changed a lot, and some of the
status design hasn't been updated since resources were created.

So, for example, we have GatewayClass with `Accepted`, Gateway with `Scheduled`,
the Gateway Listeners with `Detached` (which you want to be `false`, unlike the previous
two), and then Gateways and Gateway Listeners have `Ready`, but Route doesn't (and which
also you want to be `true`).

This document lays out large-scale changes to the way that we talk about resources,
and the Conditions to match them. This means that there will be an unavoidable break
in what constitutes a healthy or unhealthy resource, and there will be changes
required for all implementations to be conformant with the release that includes
these changes.

This level of change is not optimal, and the intent is to make this a one-off change
that can be built upon for future resources - since there are definitely more resources
on the way.

## Background: Kubernetes API conventions and prior art on Conditions

Because this GEP is mainly concerned with updating the Conditions we are setting in
Gateway API resources' `status`, it's worth reviewing some important points about
Conditions. (This information is mainly taken from the [Typical status properties][typstatus]
section of the API conventions document.)

1. Conditions are a standard type used to represent arbitrary higher-level status from
a controller.
2. They are a listMapType, a list that is enforced by the apiserver to have only
one entry of each item, using the `type` field as a key. (So, this is effectively
a map that looks like a list in YAML form).
Comment on lines +67 to +69
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually hadn't realized the uniqueness on type constraint - this should probably be documented more clearly within the Gateway API spec, as it has some bearing on how "multiple error" cases may be expressed, and explains the structure of RouteParentStatus, which will be increasingly relevant if we start expecting resources like HTTPRoute to bind to multiple parentRefs (for GAMMA and N/S concurrent usage or route delegation).

3. Each has a number of fields, the most important of which for this discussion
are `type`, `status`, `reason`, and `observedGeneration`.

* `type` is a string value indicating the Condition type. `Accepted`, `Scheduled`,
and `Ready` are current examples.
* `status` indicates the state of the condition, and can be one of three values,
`true`, `false`, or `unknown`. Unkown in particular is important, because it
means that the controller is unable to determine the status for some reason.
* `reason` is a CamelCase string that is a brief description of the reason why
the `status` is set the way it is.
* `observedGeneration` is an optional field that sets what the `metadata.generation`
field was when the controller last saw a resource.
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 we'd had some conversations about making this required for conformant Gateway implementations. Probably out of scope for this GEP, just wanted to make sure it was intentionally excluded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I updated.


4. Conditions shoud describe the _current state_ of the resource at observation
time, which means that they should be an adjective (like `Ready`), or a past-tense
verb (like `Attached`).
Copy link
Member

Choose a reason for hiding this comment

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

Would Attaching ever be valid as a condition? Maybe just verb or adjective is sufficient here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sort of usage is specifically called out as not desirable in the API conventions, and I agree. Conditions are supposed to be level-triggered, not edge-triggered, so having a condition that says that something is happening is a bit weird. (Should Attaching transition to false once the attaching process is complete?)

Copy link
Member

Choose a reason for hiding this comment

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

For posterity, can we cite some sources for that assertion? It would probably actually be good as a part of this status effort to document somewhere in the code that we're avoiding this due to conventions, and then point to those conventions, as this will help future contributors to more quickly avoid pursuing such things (or give them a path to who they need to convince in the greater kubernetes community).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is almost a direct quote from the API conventions as it is, should I put a link in here to the exact line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exact quote is as follows, I can just inline if it's better, but I was trying to avoid just pasting in the entire section:


Condition type names should describe the current observed state of the resource, rather than describing the current state transitions. This typically means that the name should be an adjective ("Ready", "OutOfDisk") or a past-tense verb ("Succeeded", "Failed") rather than a present-tense verb ("Deploying"). Intermediate states may be indicated by setting the status of the condition to Unknown.

For state transitions which take a long period of time (e.g. more than 1 minute), it is reasonable to treat the transition itself as an observed state. In these cases, the Condition (such as "Resizing") itself should not be transient, and should instead be signalled using the True/False/Unknown pattern. This allows other observers to determine the last update from the controller, whether successful or failed. In cases where the state transition is unable to complete and continued reconciliation is not feasible, the Reason and Message should be used to indicate that the transition failed.


I don't believe that we generally have any process that we want to handle in the way called out in the exception bullet point. Happy to be guided here on what you'd like to see.

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 a direct link to the language would be nice, but not a blocker.

5. Conditions should be applied to a resource the first time the controller sees
the resource. This seems to imply that _all conditions should be present on every
resource owned by a controller_, but the rest of the conventions don't make this
Copy link
Contributor

Choose a reason for hiding this comment

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

Conditions which appear and disappear from a resource can make status reporting UIs harder, so I'd recommend keeping the Condition set consistent.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that we should have a set of permanent and reliable conditions that are always present, but I personally don't think it makes sense for error conditions to always be present, especially since that tends to lead to confusing double negative states.

clear, and it is often not complied with.
6. It's helpful to have a top-level condition which summarizes more detailed conditions.
The guidelines suggest using either `Ready` for long-running processes, or `Succeeded`
for bounded exection.

From these guidelines, we can see that Conditions can be either _positive polarity_
(healthy resources have them as `status: true`) or _negative polarity_ (healthy
resources have them as `status: false`). `Ready` is an example of a positive polarity
condition, and conditions like `Conflicted` from Listener or `NetworkUnavailable`,
`MemoryPressure`, or `DiskPressure` from the Node resource are examples of
negative-polarity conditions.

There is also some extra context that's not in the API conventions doc:

SIG-API Machinery has been reluctant to add fields that would aid in machine-parsing
of Conditions, especially fields that would indicate the polarity, because they
are intended more for human consumption than machine consumption.

This means that there's no guidance from upstream about condition polarity. We'll
discuss this more when we talk about new conditions.

The guidance about Conditions being added as soon as a controller sees a resource
is a bit unclear - as written in the conventions, it seems to imply that _all_
relevant conditions should always be added, even if their status has to be set to
Copy link

Choose a reason for hiding this comment

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

I think it is reasonable for the controller to do this - as an indication the resource is in use by the controller.

It becomes problematic if a resource may be processed by multiple controllers - for example the discussion
of HttpRoute applying to both mesh and Gateway can only work if the type has a prefix (MeshReady).

In general it would be good to indicate how to handle resources where multiple controllers operate on. While
it's good to know which controller mess with the resource - maybe the controller should skip this step if the
resource is not ignored ( a mesh controller will ignore any route that don't target both mesh and gateway as example)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In most cases, the Conditions slice is in a separate struct that's part of a slice that's namespaced by controller name - so that controllers should be able to update only their own Conditions. I'd expect that mesh controllers should have a distinct controller name string, so this method should continue working.

Copy link
Contributor

Choose a reason for hiding this comment

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

@thockin has said that getting multiple controllers to cooperate on node health status was very subtle, so I'd be careful and maybe distill his experience if you need multiple controllers writing one status.

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 our practice of including controllerName for each distinct set of conditions should largely allow multiple controllers to cooperate on status for the same resource, but open to other potential improvements.

Copy link
Contributor

Choose a reason for hiding this comment

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

How do controllerName conditions roll up to Accepted?

Also, controllers probably need to be sure to use PATCH on the status sub-resource or do conditional PUTs and avoid extra writes if the conditions haven't changed.

Copy link
Contributor Author

@youngnick youngnick Sep 26, 2022

Choose a reason for hiding this comment

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

For some resources, all conditions are namespaced by controllerName. I agree we need to ensure that the rollup behavior is specified. I'm going to add a section about partial validity that should help.

Copy link
Contributor

Choose a reason for hiding this comment

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

For HTTPRoute as a specific example, the structure of RouteParentStatus appears well-suited to handle a separate list of conditions for each parentRef or controller, so a mesh or Service relationship for a route would have a separate set of conditions and Accepted status than those used for relaying the status of a concurrent parent relationship to a Gateway, with no need to collaborate on writing to a single status.

`unknown`.
Gateway API resources do not currently require this, and the practice seems to be
uncommon.

## Proposed changes

### Proposed changes summary

* All the current Conditions that indicate that the resource is okay and ready
for processing witll be replaced with `Attached`, except for GatewayClass (since
it is the root of the resource tree, it will stay with `Accepted`).
Copy link
Member

Choose a reason for hiding this comment

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

I don't feel strongly about this, but any reason not just to use Accepted everywhere instead of Attached in most places and Accepted in this one place?

Copy link
Contributor

Choose a reason for hiding this comment

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

I had the same thought and am +1 to this, Accepted seems a little bit easier to understand for users IMO and can be consistently used across all resources.

* In general, resources should be considered `Attached` if their config is valid
enough to generate some config in the underlying data plane.
* There will be a limited set of positive polarity summary conditions, and a number
of other specific negative-polarity error conditions.
Copy link
Contributor

Choose a reason for hiding this comment

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

This will make UI display somewhat harder (green dots / checkmarks / exclamation points), but I realize it may align with human reading a bit more easily.

I don't have a strong opinion here, just want to highlight the cost elsewhere in the stack.

* All relevant positive-polarity summary Conditions for a resource must be added
when it's observed.
For example, HTTPRoutes must always have `Accepted` and `ResolvedRefs`, regardless
Copy link
Member

Choose a reason for hiding this comment

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

Is Accepted distinct from Attached here? Would Accepted ever be true if ResolvedRefs was false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hadn't updated, but with the change to Accepted everywhere, this is now correct, thanks.

of their state.
* Negative polarity error conditions must only be added when the error is True.

(For discussion): Should the summary conditions be added into the CRD definitions
as default values for `status.Conditions`, with a status of `Unknown`?

The exact list of changes is detailed below. The next few sections detail
the reasons for these large-scale changes.

### Conceptual and language changes

Gateway API resources are, conceptually, all about breaking up the configuration for a
data plane into separate resources that are _expressive_ and _extensible_, while being
split up along _role-oriented_ boundaries.

So, when we talk about Gateway API, it's _always_ about a _system of related resources_.

We already acknowledge this when we talk about Routes "attaching" to Gateways, or Gateways
referencing Services, or Gateways requiring a GatewayClass in their spec.

So, this GEP proposes that we formalize this by leaning into the word "attach" as the
primary verb to describe the relationships between resources in the system.

So, Gateways _attach_ to GatewayClasses, Routes _attach_ to Gateways, and in a
bit of an extension, ReferenceGrants _attach_ to the things they are Granting
Reference access to.

Of course, because we're using all of this configuration to describe some sort of data
path from "outside"/lacking cluster context to "inside"/enriched with cluster context,
we also need a way to describe when that data path is configured and working.

We already have a word in the Kubernetes API, but it comes with some expectations
that implementations are not currently able to meet. That word is `Ready`, but it
implies that the data path is Ready _when you read the status_, rather than that
it _will be ready soon_ (which is what most implementations can guarantee currently.)

So we have an unresolved question as to what to do with the `Ready` condition.
This is addressed further below.

### Condition polarity

In terms of the polarity of conditions, we have three options, of which only two are
really viable:
* All conditions must be negative polarity
* All conditions must be positive polarity
* Some conditions can be positive polarity, but most should be negative.
Copy link
Member

Choose a reason for hiding this comment

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

My own personal preference would be for conditions with a positive polarity to represent the normal healthy state and always be present, and for conditions with a negative polarity to represent very specific error states and to only be present when true. I think we should do everything we can to avoid the presence of double negatives like "Detached == False", but recognize that there are some error states that are best represented with a negative condition. I just don't think those negative conditions should be present when false.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1. As I mentioned above -- as long we document and check for it in conformance, this is the only guarantee that the conditions are meaningful programmatically, which is basically what we are looking for when we build for consistency.

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 we're going to have a mixed-polarity set of conditions, then I think we need to define:

  • which Conditions are positive polarity (Probably Attached, Programmed, Ready, and Valid if we do it)
  • which Conditions are positive polarity and should always be present (Probably Attached, Programmed, and Valid if we do it).
  • which Conditions are core (currently, everything other than Ready)
  • which Conditions are extended (only Ready).
  • which Conditions are negative (all the error conditions).


The fact that the user experience of `Ready` or conditions like `Accepted` being `true`
in the healthy case is much better rules out the first option, so we are left to
decide between enforcing that all conditions are positive, or that we have a mix.

Having an arbitrary mix will make doing machine-based extraction of information
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if this is necessarily true -- it just needs to be explicitly documented for and tested. I think the previous attempt by K8s to force one polarity just simply didn't work out because it didn't line up with people's intuition. We should really try to keep things intuitive as much as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It means that anything consuming the Conditions will need to have a hard-coded list of the positive polarity conditions. Not a deal breaker, but it's another obstacle in the way of building a generic condition-parsing library.

much harder, so here I'm going to talk about the distinction between having all
conditions positive or some, summary conditions positive, and the rest negative.

#### All Conditions Positive

In this case, all Condition types are written in such a way that they're positive
polarity, and are `true` in the healthy case.

As already discussed, `Ready`, and `Accepted` are current examples, but another
one that's a little more important here is `ResolvedRefs` which is set to `true`
when all references to other resources have been successfully resolved. This is
not a _blocking_ Condition that affects the `Ready` condition, since having _some_
references valid is enough to produce some configuration in the underlying data
plane.

So, All Conditions Positive pros:
* We're close already. Most conditions in the API are currently positive polarity.
* Easier to understand - there are no double negatives. "Good: true" is less
cognitive overhead than "NotGood: false".

Cons:
* Reduces flexibility - it can surprisingly difficult to avoid double negatives for
conditions that describe error states, as in general programmers are more used
to reporting "something went wrong" than they are "everything's okay".

Not sure if pro or con:
* Leans the design towards favoring conditions always being present, since you
can't be sure if everything is good unless you see `AllGood: true`. The absence
of a positive-polarity condition implies that the condition could be false. This
puts this option more in line with the API guidelines on this point.

#### Some Conditions Positive

In this case, only a limited set of summary conditions are positive, and the rest
are negative.

Pros:
* Error states can be described with `Error: true` instead of `NoError: false`.
* Negative polarity error conditions are more friendly to not being present (since
absence of `Error: true` implies everything's okay).

Cons:
* Any code handling conditions will need a list of the positive ones, and will
need to assume that any others are negative.

#### Decision

Gateway API conditions will be positive for conditions that describe the happy
state of the object, which is currently `Attached` and `ResolvedRefs`.


### Should conditions always be added?

Not all of them.

Positive polarity Conditions that describe the desirable state of the object must
always be set. These are currently `Attached`, `ResolvedRefs`, and whatever we
end up choosing to represent "the data path will be done soon", `Ready`, `Programmed`,
or other.

### New and Updated Conditions

#### `Attached`

This GEP proposes replacing all conditions that indicate syntactic and semantic
validity with one, `Attached` condition type, with the exception of the
GatewayClass resource (because it's the root of the resource tree and doesn't
attach to anything).

That is, the proposal is to replace:
* `Scheduled` on Gateway
* `Detached` on Listener
* `Accpeted` on Route

with `Attached` in all these locations.

GatewayClass will maintain the `Accepted` condition.

All of these conditions share the following meanings:
* The resource has been accepted for processing by the controller
* The resource is syntatically and semantically valid, and internally consistent
* The resource fits into a larger system of Gateway API resources, and there is
is no missing information, including but not limited to:
* Any mandatory references resolve to existing resources (examples here are the
Gateway's gatewayClass field, or the `parentRefs` field in Route resources)
* Any specified TLS secrets exist
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently the API supports partially-valid resources. I believe this is proposing a partially-valid resource would be Attached=false, but the config is actually 'active' (or, I would describe it, "attached").

To me this feels a bit odd. The old API sort of had this issue as well.

Thinking purely from a pedantic-correctness POV (which may not be ideal - sometimes simpler is better), I would expect there to be two conditions (I use bad names intentionally to avoid confusion): "ThisResourceWasApplied" - any part of the rule had some effect on the system, and "ThisRuleIsEntirelyValid" - no errors found in the rule at all.

Its possible my concern would be addressed with a different word than "Attached", rather than more conditions, as well

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is somewhat addressed below.. but I am not sure its accurate? It seems we are defining a very small set of "failures that do not become unattached", but there are a lot more partially-accepted resources I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The guideline I've been basing the "does something become unattached?" on is "Does this produce at least some configuration in the underlying data plane?". So I guess it sounds like I need to be more explicit with that guideline, but that aside from that, we're largely in agreement?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to have "Is this attached" and "is this 100% valid" as two separate things.

Part of my confusion, I think, is I am not actually sure which fields result in "not attached". It seems most issues are partially accepted. Which is fine - Attached just becomes basically a pretty high level acknowledgement that the controller is handling the resource

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think I agree with @howardjohn's point here: "does this resource produce config" is distinct from "does this resource produce valid config". I'm sure some implementations don't allow invalid (e.g. duplicate route names or something) to be sent to the data plane, but it doesn't feel like that's a requirement for the Gateway API at this juncture.

Copy link
Contributor Author

@youngnick youngnick Sep 14, 2022

Choose a reason for hiding this comment

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

I guess I wrote this pooly - by "Does this resource produce config" I meant to read "Is this resource valid enough to produce some config when combined with the rest of the resource set".

The thing I'm thinking of particularly here is that for HTTPRoute, invalid references still produce data path config because the match will respond with 500s. Whereas for TCPRoute etc, if you don't have a service to route to, there's no way you can build a forwarding path - there's nothing to forward to! So that won't produce any data path config at all, and so, in the current design, would cause the resource to fail to be attached.

I don't think anything should be allowed to produce invalid config in the underlying data plane. If so, that should mean that the resource becomes unattached.

I guess this means that we need some more clarity about what attached means. I've been assuming that if we consider a resource to be "attached" to another, that:

  • the resource is valid in itself
  • the resource will produce at least some valid config in the underlying data plane. (note that "return a 500 for this route" is valid config).

And so, that having a "valid" condition is not really useful because if something is not valid, it won't be attached either.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for something like an HTTPRoute to define two paths, one of which is "valid enough" config, while the other is garbage?

If so, are there expectations or requirements from a conformance PoV ("always apply all or none") that we need to specify?

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for something like an HTTPRoute to define two paths, one of which is "valid enough" config, while the other is garbage?

Most cases of an invalid configuration in one route rule (with others being completely valid within the same HTTPRoute) seem to be misconfigurable only in the context of a reference to another resource and fall into the ResolvedRefs bucket (which seems stated below and possibly agreed upon that Attached: true be set with ResolvedRefs: false and return HTTP code 500 for the invalid rule).

One such example not covered is if you were to use a HTTPRequestRedirectFilter and HTTPURLRewrite in the list of filters for an individual HTTPRouteRule (ref). At the moment it doesn't appear we have prescribed any status code or other error handling for this error. This seems to fall into the bucket of things that cannot produce data plane configuration.

Going by the statements below, if this rule were the only one present Attached: false should be set, since it cannot result in any configuration (with another more specific error condition). If present with other valid rules, Attached: true should be set (with another more specific error condition again). I can definitely see the argument for setting Attached: false however in the latter case, since stated above, the Attached condition means The resource is syntatically and semantically valid, and internally consistent.

It seems that the Valid: true condition mentioned above ends up being somewhat equivalent to having for example for HTTPRoute ResolvedRefs: true and no error conditions (and vice versa, Valid: false equivalent to ResolvedRefs: false or some more specific error condition). Maybe this framing helps a little with determining possible merits of having another condition?

If so, are there expectations or requirements from a conformance PoV ("always apply all or none") that we need to specify?

Just doing a quick pass, I don't think I saw any existing conformance tests that cover this kind of thing so I agree that would be good to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoiding "always apply all or none" is the reason this is tricky. There are mixed expectations about what happens if some config is present but bad, and I'm attempting to thread the needle here and make this as user-friendly as possible while not becoming really difficult to implement or understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a section on partial validity to hopefully make this clearer.

* The resource is supported by the controller by ensuring things like:
* Any Kinds being referred to by the resource are supported
* Features being used by the resource are supported

All of these rules can be summarized into:
* The resource is valid enough to produce some configuration in the underlying
data plane.

For Gateway, `Attached` also subsumes the functions of `Scheduled`: `Attached`
Copy link
Contributor

Choose a reason for hiding this comment

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

On some impls, provisioning takes about a minute. That may mean that some errors that are immediately known are masked. Or I suppose they aren't masked, but we need to wait the entire minute to know if its valid. The message field could say "all fields valid, waiting for deployment" perhaps, but that isn't in the machine parse-able section.

That may not warrant change, just a thought

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I worded this carefully, so as not to imply that the provisioning needs to have completed, just that it can be started. The completion of infra provisioning should be handled by Programmed or Ready, or both.

set to `true` means that sufficient capacity exists on underlying infrastructure
for the Gateway to be provisioned. If that capacity does not exist, then the
Gateway cannot be reconciled successfully, and so fails to attach to the
owning GatewayClass.

Note that some classes of inter-resource reference failure do _not_ cause a resource
to become unattached (that is, to have the `Attached` condition set to `status: false`).
* Nonexistent Service backends - if the backend does not exist on a HTTPRoute that
Copy link
Contributor

Choose a reason for hiding this comment

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

This starts painting an observability problem IMO. Even if conditions are only meant to be human-readable, how does a human look at an HTTPRoute resource and know "oops I have a typo in my service backend"? Yes, 500s indicate something's wrong, but I would expect to find a condition pointing to the specific issue

Copy link
Contributor

Choose a reason for hiding this comment

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

We should allow room for error conditions in addition to attached in this case so the intformation can be conveyed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I guess I should make this clearer, that in this case, it's absolutely expected that there be some additional, negative-polarity error conditions that tell you that the backendRef doesn't exist. (This is a distinct case from the backend existing, but having zero endpoints, which would not generate a "backendRef doesn't exist" error, but would end up with the same behavior).

Copy link
Contributor

Choose a reason for hiding this comment

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

You might also get a BackendRefEmpty condition...

is otherwise okay, then the data plane must generate 500s for traffic that matches
that HTTPRoute. In this case, the `Attached` Condition must be true, and the
`ResolvedRefs` Condition must be false, with reasons and messages indicating that
the backend services do not exist.
* HTTPRoutes with *all* backends in other namespaces, but not permitted by ReferenceGrants.
In this case, the "nonexistent service backends" rules apply, and 500s must be
generated. In this case, again, the `Attached` condition is true, and the
`ResolvedRefs` Condition is false, with reasons and messages indicating that the
backend services are not reachable.

For ReferenceGrant or not-designed-yet Policy resources, `Attached` means that:
* the resource has a correctly-defined set of resources that it applies to
* the resource has a syntactically and semantically valid `spec`

Note that having a correctly-defined set of resources that is empty does not make
these resources unattached.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this. What would empty resources look like? If they're not unattached what are they?


Note that for other Route types that don't have a clear mechanism like HTTP does
for indicating a server failure (like the HTTP code 500 does), not having existing
backends may not produce any configuration in the data plane, and so may cause
the resource to fail to attach. (An example here could be a TCP Route with
no backends, we need to decide if that means that a port should be opened that
actively closes connections, or if no port should be opened.)

Examples of Conditions:
* HTTPRoute with one match with one backend that is valid. `Attached` is true,
`ResolvedRefs` is true.
* HTTPRoute with one match with one backend that is a nonexistent Service backend.
The `Attached` Condition is true, the `ResolvedRefs` condition is false. `Attached`
is true in this case because the data path must respond to requests that would be
sent to that backend with a 500 response.
* HTTPRoute with one match with two backends, one of which is a nonexistent Service
backend. The `Attached` Condition is true, the `ResolvedRefs` condition is false.
`Attached` is true in this case because the data path must respond to a percentage
of the requests matching the rule corresponding to the weighting of the nonexistent
backend (which would be fifty percent unless weights are applied).
* HTTPRoute with one match with one backend that is in a different namespace, and
does _not_ have a ReferenceGrant permitting that access. The `Attached` condition
is true, and the `ResolvedRefs` Condition is false. As before, `Attached` is true
because in this case, the data path must be programmed with 500s for the match.
* TCPRoute with one match with a backend that is a nonexistent Service. `Attached`
is false, and `ResolvedRefs` is false. `Attached` is false in this case because
there is not enough information to program any rules to handle the traffic in the
underlying data plane - TCP doesn't have a way to say "this is a valid destination
that has something wrong with it".
* HTTPRoute with one Custom supported filter added that is not supported by the
implementation. Our spec is currently unclear on what happens in this case, but
custom HTTP Filters require the use of the `ExtensionRef` filter type, and the
setting of the ExtensionRef field to the name, group, version, and kind of a
custom resource that describes the filter. If that custom resource is not supported,
it seems reasonable to say that this should be a reference failure, and be treated
like other reference failures (`Attached` will be set to true, `ResolvedRefs` to
false, and traffic that would have matched the filter should receive a 500 error.)



#### Ready

Currently, the `Ready` condition text for Gateway says:
```go
// This condition is true when the Gateway is expected to be able
// to serve traffic. Note that this does not indicate that the
// Gateway configuration is current or even complete (e.g. the
// controller may still not have reconciled the latest version,
// or some parts of the configuration could be missing).
```

This is pretty unclear - how can the Gateway serve traffic if config is missing?
In the past, we've been asked to have a Condition that only flips to `true` when
*all* required configuration is present.

For many implementations (certainly for Envoy-based ones), getting this information
correctly and avoiding races on applying it is surprisingly difficult.

For this reason, this GEP proposes that we exclude the `Ready` condition from Core
conformance, and make it a feature that implementations may opt in to - making it
an Extended condition.

It will have the following behavior:
* `Ready` is an optional Condition that has Extended support, with conformance
tests to verify the behvaior.
* When it's set, the condition indicates that traffic is ready to flow through
the data plane _immediately_, not at some eventual point in the future.


#### Programmed

The `Programmed` condition is being added to replicate the functionality that the
`Ready` condition currently indicates, namely that all the resources in the set
are valid enough to produce some data plane configuration, and that configuration
has been sent to the data plane, and should be ready soon.

It is a positive-polarity summary condition, and so should always be present on
the resource. It should be set to `Unknown` if the implementation performs updates
to the status before it has all the information it needs to be able to determine
if the condition is true.


## Alternatives

(Most alternatives have been discussed inline. Please comment here if this section
needs updating.)

## References
[kep-status]: https://github.com/kubernetes/enhancements/blob/master/keps/NNNN-kep-template/kep.yaml#L9

[1111]: https://github.com/kubernetes-sigs/gateway-api/issues/1111
[1110]: https://github.com/kubernetes-sigs/gateway-api/issues/1110
[1362]: https://github.com/kubernetes-sigs/gateway-api/issues/1362

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