You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Making a new API Version](#making-a-new-api-version)
25
29
-[Making a new API Group](#making-a-new-api-group)
26
30
-[Update the fuzzer](#update-the-fuzzer)
@@ -30,6 +34,9 @@ found at [API Conventions](api-conventions.md).
30
34
-[Examples and docs](#examples-and-docs)
31
35
-[Alpha, Beta, and Stable Versions](#alpha-beta-and-stable-versions)
32
36
-[Adding Unstable Features to Stable Versions](#adding-unstable-features-to-stable-versions)
37
+
-[New field in existing API version](#new-field-in-existing-api-version)
38
+
-[New enum value in existing field](#new-enum-value-in-existing-field)
39
+
-[New alpha API version](#new-alpha-api-version)
33
40
34
41
## So you want to change the API?
35
42
@@ -316,9 +323,10 @@ worked before the change.
316
323
values of a given field will not be able to handle the new values. However, removing a
317
324
value from an enumerated set *can* be a compatible change, if handled properly (treat the
318
325
removed value as deprecated but allowed). For enumeration-like fields that expect to add
319
-
new values in the future, such as `reason` fields, please document that expectation clearly
320
-
in the API field descriptions. Clients should treat such sets of values as potentially
321
-
open-ended.
326
+
new values in the future, such as `reason` fields, document that expectation clearly
327
+
in the API field description in the first release the field is made available,
328
+
and describe how clients should treat an unknown value. Clients should treat such
329
+
sets of values as potentially open-ended.
322
330
323
331
* For [Unions](api-conventions.md#unions), sets of fields where at most one should
324
332
be set, it is acceptable to add a new option to the union if the [appropriate
@@ -880,7 +888,10 @@ users are only able or willing to accept a released version of Kubernetes. In
880
888
that case, the developer has a few options, both of which require staging work
881
889
over several releases.
882
890
883
-
#### Alpha field in existing API version
891
+
The mechanism used depends on whether a new field is being added,
892
+
or a new value is being permitted in an existing field.
893
+
894
+
#### New field in existing API version
884
895
885
896
Previously, annotations were used for experimental alpha features, but are no longer recommended for several reasons:
886
897
@@ -1016,6 +1027,159 @@ In future Kubernetes versions:
1016
1027
}
1017
1028
```
1018
1029
1030
+
#### New enum value in existing field
1031
+
1032
+
A developer is considering adding a new allowed enum value of `"OnlyOnTuesday"`
1033
+
to the following existing enum field:
1034
+
1035
+
```go
1036
+
type Frobber struct {
1037
+
// restartPolicy may be set to "Always" or "Never".
1038
+
// Additional policies may be defined in the future.
1039
+
// Clients should expect to handle additional values,
1040
+
// and treat unrecognized values in this field as "Never".
1041
+
RestartPolicy string `json:"policy"
1042
+
}
1043
+
```
1044
+
1045
+
Older versions of expected API clients must be able handle the new value in a safe way:
1046
+
1047
+
* If the enum field drives behavior of a single component, ensure all versions of that component
1048
+
that will encounter API objects containing the new value handle it properly or fail safe.
1049
+
For example, a new allowed value in a `Pod` enum field consumed by the kubelet must be handled
1050
+
safely by kubelets up to two versions older than the first API server release that allowed the new value.
1051
+
* If an API drives behavior that is implemented by external clients (like `Ingress` or `NetworkPolicy`),
1052
+
the enum field must explicitly indicate that additional values may be allowed in the future,
1053
+
and define how unrecognized values must be handled by clients. If this was not done in the first release
1054
+
containing the enum field, it is not safe to add new values that can break existing clients.
1055
+
1056
+
If expected API clients safely handle the new enum value, the next requirement is to begin allowing it
1057
+
in a way that does not break validation of that object by a previous API server.
1058
+
This requires at least two releases to accomplish safely:
1059
+
1060
+
Release 1:
1061
+
1062
+
* Only allow the new enum value when updating existing objects that already contain the new enum value
1063
+
* Disallow it in other cases (creation, and update of objects that do not already contain the new enum value)
1064
+
* Verify that known clients handle the new value as expected, honoring the new value or using previously defined "unknown value" behavior,
1065
+
(depending on whether the associated feature gate is enabled or not)
1066
+
1067
+
1068
+
Release 2:
1069
+
1070
+
* Allow the new enum value in create and update scenarios
1071
+
1072
+
This ensures a cluster with multiple servers at skewed releases (which happens during a rolling upgrade),
1073
+
will not allow data to be persisted which the previous release of the API server would choke on.
1074
+
1075
+
Typically, a feature gate is used to do this rollout, starting in alpha and disabled by default in release 1,
1076
+
and graduating to beta and enabled by default in release 2.
1077
+
1078
+
1. Add a feature gate to the API server to control enablement of the new enum value (and associated function):
1079
+
1080
+
In [staging/src/k8s.io/apiserver/pkg/features/kube_features.go](https://git.k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/features/kube_features.go):
if f.RestartPolicy == RestartPolicyOnTuesday && !opts.AllowRestartPolicyOnTuesday {
1157
+
allErrs = append(allErrs, field.Invalid(field.NewPath("restartPolicy"), f.RestartPolicy, "only allowed if the FrobberRestartPolicyOnTuesday feature is enabled"))
1158
+
} else if !validRestartPolicies.Has(f.RestartPolicy) {
5. After at least one release, the feature can be promoted to beta or GA and enabled by default.
1166
+
1167
+
In [staging/src/k8s.io/apiserver/pkg/features/kube_features.go](https://git.k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/features/kube_features.go):
0 commit comments