Skip to content

Commit a329a26

Browse files
authored
Merge pull request #6558 from deads2k/metav1-Condition
update condition guidance to use metav1.Conditions
2 parents 5b23b66 + 4bee49a commit a329a26

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
@@ -419,27 +419,46 @@ Conditions are most useful when they follow some consistent conventions:
419419
consistent standard, the `Ready` and `Succeeded` condition types may be used
420420
by API designers for long-running and bounded-execution objects, respectively.
421421

422-
The `FooCondition` type for some resource type `Foo` may include a subset of the
423-
following fields, but must contain at least `type` and `status` fields:
424-
422+
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).
423+
It should be included as a top level element in status, similar to
425424
```go
426-
Type FooConditionType `json:"type" description:"type of Foo condition"`
427-
Status ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"`
425+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
426+
```
428427

429-
// +optional
430-
Reason *string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"`
431-
// +optional
432-
Message *string `json:"message,omitempty" description:"human-readable message indicating details about last transition"`
428+
The `metav1.Conditions` includes the following fields
433429

434-
// +optional
435-
LastTransitionTime *unversioned.Time `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"`
430+
```go
431+
// type of condition in CamelCase or in foo.example.com/CamelCase.
432+
// +required
433+
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
434+
// status of the condition, one of True, False, Unknown.
435+
// +required
436+
Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status"`
437+
// observedGeneration represents the .metadata.generation that the condition was set based upon.
438+
// For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
439+
// with respect to the current state of the instance.
440+
// +optional
441+
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`
442+
// lastTransitionTime is the last time the condition transitioned from one status to another.
443+
// This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
444+
// +required
445+
LastTransitionTime Time `json:"lastTransitionTime" protobuf:"bytes,4,opt,name=lastTransitionTime"`
446+
// reason contains a programmatic identifier indicating the reason for the condition's last transition.
447+
// Producers of specific condition types may define expected values and meanings for this field,
448+
// and whether the values are considered a guaranteed API.
449+
// The value should be a CamelCase string.
450+
// This field may not be empty.
451+
// +required
452+
Reason string `json:"reason" protobuf:"bytes,5,opt,name=reason"`
453+
// message is a human readable message indicating details about the transition.
454+
// This may be an empty string.
455+
// +required
456+
Message string `json:"message" protobuf:"bytes,6,opt,name=message"`
436457
```
437458

438459
Additional fields may be added in the future.
439460

440-
Do not use fields that you don't need - simpler is better.
441-
442-
Use of the `Reason` field is encouraged.
461+
Use of the `Reason` field is required.
443462

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

0 commit comments

Comments
 (0)