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
@@ -696,10 +696,10 @@ have a built-in `nil` value (e.g. maps and slices).
696
696
- The API server should allow POSTing and PUTing a resource with this field
697
697
unset.
698
698
699
-
In most cases, optional fields should also have the `omitempty` struct tag (the
699
+
In most cases, optional fields should also have the `omitempty` struct tag (the
700
700
`omitempty`option specifies that the field should be omitted from the json
701
-
encoding if the field has an empty value). However, If you want to have
702
-
different logic for an optional field which is not provided vs. provided with
701
+
encoding if the field has an empty value). However, If you want to have
702
+
different logic for an optional field which is not provided vs. provided with
703
703
empty values, do not use `omitempty` (e.g. https://github.com/kubernetes/kubernetes/issues/34641).
704
704
705
705
Note that for backward compatibility, any field that has the `omitempty` struct
@@ -714,7 +714,7 @@ Required fields have the opposite properties, namely:
714
714
- The API server should not allow POSTing or PUTing a resource with this field
715
715
unset.
716
716
717
-
Using the `+optional` or the `omitempty` tag causes OpenAPI documentation to
717
+
Using the `+optional` or the `omitempty` tag causes OpenAPI documentation to
718
718
reflect that the field is optional.
719
719
720
720
Using a pointer allows distinguishing unset from the zero value for that type.
@@ -744,6 +744,13 @@ Incorporating the default values into the `Spec` ensures that `Spec` depicts the
744
744
full desired state so that it is easier for the system to determine how to
745
745
achieve the state, and for the user to know what to anticipate.
746
746
747
+
Default values can be specified on a field using the `+default=` tag. Primitives
748
+
will have their values directly assigned while structs will go through the
749
+
JSON unmarshalling process. Fields that do not have an `omitempty` json tag will
750
+
default to the zero value of their corresponding type if no default is assigned.
751
+
752
+
Refer to [defaulting docs](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting) for more information.
753
+
747
754
API version-specific default values are set by the API server.
748
755
749
756
## Late Initialization
@@ -885,16 +892,16 @@ references can have unexpected impacts, including:
885
892
or opt-in's from both involved namespaces.
886
893
3. referential integrity problems that one party cannot solve. Referencing namespace/B from namespace/A doesn't imply the
887
894
power to control the other namespace. This means that you can refer to a thing you cannot create or update.
888
-
4. unclear semantics on deletion. If a namespaced resource is referenced by other namespaces, should a delete of the
895
+
4. unclear semantics on deletion. If a namespaced resource is referenced by other namespaces, should a delete of the
889
896
referenced resource result in removal or should the referenced resource be force to remain.
890
897
5. unclear semantics on creation. If a referenced resource is created after its reference, there is no way to know if it
891
898
is the one that is expected or if it is a different one created with the same name.
892
899
893
900
Built-in types and ownerReferences do not support cross namespaces references.
894
-
If a non-built-in types chooses to have cross-namespace references the semantics of the edge cases above should be
901
+
If a non-built-in types chooses to have cross-namespace references the semantics of the edge cases above should be
895
902
clearly described and the permissions issues should be resolved.
896
903
This could be done with a double opt-in (an opt-in from both the referrer and the refer-ee) or with secondary permissions
897
-
checks performed in admission.
904
+
checks performed in admission.
898
905
899
906
### Naming of the reference field
900
907
@@ -979,9 +986,9 @@ A single kind object reference is straightforward in that the controller can har
979
986
```yaml
980
987
# for a single resource, the suffix should be Ref, with the field name
981
988
# providing an indication as to the resource type referenced.
982
-
secretRef:
989
+
secretRef:
983
990
name: foo
984
-
# namespace would generally not be needed and is discouraged,
991
+
# namespace would generally not be needed and is discouraged,
985
992
# as explained above.
986
993
namespace: foo-namespace
987
994
```
@@ -1077,7 +1084,7 @@ fooObjectRef:
1077
1084
group: operator.openshift.io
1078
1085
resource: openshiftapiservers
1079
1086
name: cluster
1080
-
# namespace is unset if the resource is cluster-scoped, or lives in the
1087
+
# namespace is unset if the resource is cluster-scoped, or lives in the
1081
1088
# same namespace as the referrer.
1082
1089
```
1083
1090
@@ -1448,7 +1455,7 @@ reduce data volume, load on the system, and noise exposed to users.
1448
1455
* Go field names must be PascalCase. JSON field names must be camelCase. Other
1449
1456
than capitalization of the initial letter, the two should almost always match.
1450
1457
No underscores or dashes in either.
1451
-
* Field and resource names should be declarative, not imperative (SomethingDoer,
1458
+
* Field and resource names should be declarative, not imperative (SomethingDoer,
1452
1459
DoneBy, DoneAt).
1453
1460
* Use `Node` where referring to
1454
1461
the node resource in the context of the cluster. Use `Host` where referring to
@@ -1582,7 +1589,7 @@ Kubernetes components and tools:
1582
1589
- Key prefixes under "kubernetes.io" and "k8s.io" are reserved for the Kubernetes
1583
1590
project.
1584
1591
- Such keys are effectively part of the kubernetes API and may be subject
1585
-
to deprecation and compatibility policies.
1592
+
to deprecation and compatibility policies.
1586
1593
- Key names, including prefixes, should be precise enough that a user could
1587
1594
plausibly understand where it came from and what it is for.
1588
1595
- Key prefixes should carry as much context as possible.
@@ -1671,19 +1678,19 @@ API objects often are [union](#Unions) object containing the following:
1671
1678
1. One or more fields identifying the `Type` specific to API object (aka the `discriminator`).
1672
1679
2. A set of N fields, only one of which should be set at any given time - effectively a union.
1673
1680
1674
-
Controllers operating on the API type often allocate resources based on
1675
-
the `Type` and/or some additional data provided by user. A canonical example
1676
-
of this is the `Service` API object where resources such as IPs and network ports
1677
-
will be set in the API object based on `Type`. When the user does not specify
1678
-
resources, they will be allocated, and when the user specifies exact value, they will
1681
+
Controllers operating on the API type often allocate resources based on
1682
+
the `Type` and/or some additional data provided by user. A canonical example
1683
+
of this is the `Service` API object where resources such as IPs and network ports
1684
+
will be set in the API object based on `Type`. When the user does not specify
1685
+
resources, they will be allocated, and when the user specifies exact value, they will
1679
1686
be reserved or rejected.
1680
1687
1681
-
When the user chooses to change the `discriminator` value (e.g., from `Type X` to `Type Y`) without
1682
-
changing any other fields then the system should clear the fields that were used to represent `Type X`
1683
-
in the union along with releasing resources that were attached to `Type X`. This should automatically
1684
-
happen irrespective of how these values and resources were allocated (i.e., reserved by the user or
1685
-
automatically allocated by the system. A concrete example of this is again `Service` API. The system
1686
-
allocates resources such as `NodePorts` and `ClusterIPs` and automatically fill in the fields that
1687
-
represent them in case of the service is of type `NodePort` or `ClusterIP` (`discriminator` values).
1688
-
These resources and the fields representing them are automatically cleared when the users changes
1689
-
service type to `ExternalName` where these resources and field values no longer apply.
1688
+
When the user chooses to change the `discriminator` value (e.g., from `Type X` to `Type Y`) without
1689
+
changing any other fields then the system should clear the fields that were used to represent `Type X`
1690
+
in the union along with releasing resources that were attached to `Type X`. This should automatically
1691
+
happen irrespective of how these values and resources were allocated (i.e., reserved by the user or
1692
+
automatically allocated by the system. A concrete example of this is again `Service` API. The system
1693
+
allocates resources such as `NodePorts` and `ClusterIPs` and automatically fill in the fields that
1694
+
represent them in case of the service is of type `NodePort` or `ClusterIP` (`discriminator` values).
1695
+
These resources and the fields representing them are automatically cleared when the users changes
1696
+
service type to `ExternalName` where these resources and field values no longer apply.
0 commit comments