Skip to content

Commit 4bee49a

Browse files
committed
update condition guidance to use metav1.Conditions
1 parent 9a4dbd3 commit 4bee49a

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

contributors/devel/sig-architecture/api-conventions.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,27 +393,46 @@ Conditions are most useful when they follow some consistent conventions:
393393
consistent standard, the `Ready` and `Succeeded` condition types may be used
394394
by API designers for long-running and bounded-execution objects, respectively.
395395

396-
The `FooCondition` type for some resource type `Foo` may include a subset of the
397-
following fields, but must contain at least `type` and `status` fields:
398-
396+
Conditions should follow the standard schema included in [k8s.io/apimachinery/pkg/apis/meta/v1/types.go](https://github.com/kubernetes/apimachinery/blob/release-1.23/pkg/apis/meta/v1/types.go#L1432-L1492).
397+
It should be included as a top level element in status, similar to
399398
```go
400-
Type FooConditionType `json:"type" description:"type of Foo condition"`
401-
Status ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"`
399+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
400+
```
402401

403-
// +optional
404-
Reason *string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"`
405-
// +optional
406-
Message *string `json:"message,omitempty" description:"human-readable message indicating details about last transition"`
402+
The `metav1.Conditions` includes the following fields
407403

408-
// +optional
409-
LastTransitionTime *unversioned.Time `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"`
404+
```go
405+
// type of condition in CamelCase or in foo.example.com/CamelCase.
406+
// +required
407+
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
408+
// status of the condition, one of True, False, Unknown.
409+
// +required
410+
Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status"`
411+
// observedGeneration represents the .metadata.generation that the condition was set based upon.
412+
// For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
413+
// with respect to the current state of the instance.
414+
// +optional
415+
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`
416+
// lastTransitionTime is the last time the condition transitioned from one status to another.
417+
// This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
418+
// +required
419+
LastTransitionTime Time `json:"lastTransitionTime" protobuf:"bytes,4,opt,name=lastTransitionTime"`
420+
// reason contains a programmatic identifier indicating the reason for the condition's last transition.
421+
// Producers of specific condition types may define expected values and meanings for this field,
422+
// and whether the values are considered a guaranteed API.
423+
// The value should be a CamelCase string.
424+
// This field may not be empty.
425+
// +required
426+
Reason string `json:"reason" protobuf:"bytes,5,opt,name=reason"`
427+
// message is a human readable message indicating details about the transition.
428+
// This may be an empty string.
429+
// +required
430+
Message string `json:"message" protobuf:"bytes,6,opt,name=message"`
410431
```
411432

412433
Additional fields may be added in the future.
413434

414-
Do not use fields that you don't need - simpler is better.
415-
416-
Use of the `Reason` field is encouraged.
435+
Use of the `Reason` field is required.
417436

418437
Condition types should be named in PascalCase. Short condition names are
419438
preferred (e.g. "Ready" over "MyResourceReady").

0 commit comments

Comments
 (0)