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
@@ -691,10 +691,10 @@ have a built-in `nil` value (e.g. maps and slices).
691
691
- The API server should allow POSTing and PUTing a resource with this field
692
692
unset.
693
693
694
-
In most cases, optional fields should also have the `omitempty` struct tag (the
694
+
In most cases, optional fields should also have the `omitempty` struct tag (the
695
695
`omitempty`option specifies that the field should be omitted from the json
696
-
encoding if the field has an empty value). However, If you want to have
697
-
different logic for an optional field which is not provided vs. provided with
696
+
encoding if the field has an empty value). However, If you want to have
697
+
different logic for an optional field which is not provided vs. provided with
698
698
empty values, do not use `omitempty` (e.g. https://github.com/kubernetes/kubernetes/issues/34641).
699
699
700
700
Note that for backward compatibility, any field that has the `omitempty` struct
@@ -709,7 +709,7 @@ Required fields have the opposite properties, namely:
709
709
- The API server should not allow POSTing or PUTing a resource with this field
710
710
unset.
711
711
712
-
Using the `+optional` or the `omitempty` tag causes OpenAPI documentation to
712
+
Using the `+optional` or the `omitempty` tag causes OpenAPI documentation to
713
713
reflect that the field is optional.
714
714
715
715
Using a pointer allows distinguishing unset from the zero value for that type.
@@ -739,6 +739,13 @@ Incorporating the default values into the `Spec` ensures that `Spec` depicts the
739
739
full desired state so that it is easier for the system to determine how to
740
740
achieve the state, and for the user to know what to anticipate.
741
741
742
+
Default values can be specified on a field using the `+default=` tag. Primitives
743
+
will have their values directly assigned while structs will go through the
744
+
JSON unmarshalling process. Fields that do not have an `omitempty` json tag will
745
+
default to the zero value of their corresponding type if no default is assigned.
746
+
747
+
Refer to [defaulting docs](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#defaulting) for more information.
748
+
742
749
API version-specific default values are set by the API server.
743
750
744
751
## Late Initialization
@@ -880,16 +887,16 @@ references can have unexpected impacts, including:
880
887
or opt-in's from both involved namespaces.
881
888
3. referential integrity problems that one party cannot solve. Referencing namespace/B from namespace/A doesn't imply the
882
889
power to control the other namespace. This means that you can refer to a thing you cannot create or update.
883
-
4. unclear semantics on deletion. If a namespaced resource is referenced by other namespaces, should a delete of the
890
+
4. unclear semantics on deletion. If a namespaced resource is referenced by other namespaces, should a delete of the
884
891
referenced resource result in removal or should the referenced resource be force to remain.
885
892
5. unclear semantics on creation. If a referenced resource is created after its reference, there is no way to know if it
886
893
is the one that is expected or if it is a different one created with the same name.
887
894
888
895
Built-in types and ownerReferences do not support cross namespaces references.
889
-
If a non-built-in types chooses to have cross-namespace references the semantics of the edge cases above should be
896
+
If a non-built-in types chooses to have cross-namespace references the semantics of the edge cases above should be
890
897
clearly described and the permissions issues should be resolved.
891
898
This could be done with a double opt-in (an opt-in from both the referrer and the refer-ee) or with secondary permissions
892
-
checks performed in admission.
899
+
checks performed in admission.
893
900
894
901
### Naming of the reference field
895
902
@@ -974,9 +981,9 @@ A single kind object reference is straightforward in that the controller can har
974
981
```yaml
975
982
# for a single resource, the suffix should be Ref, with the field name
976
983
# providing an indication as to the resource type referenced.
977
-
secretRef:
984
+
secretRef:
978
985
name: foo
979
-
# namespace would generally not be needed and is discouraged,
986
+
# namespace would generally not be needed and is discouraged,
980
987
# as explained above.
981
988
namespace: foo-namespace
982
989
```
@@ -1023,7 +1030,7 @@ fooObjectRef:
1023
1030
group: operator.openshift.io
1024
1031
resource: openshiftapiservers
1025
1032
name: cluster
1026
-
# namespace is unset if the resource is cluster-scoped, or lives in the
1033
+
# namespace is unset if the resource is cluster-scoped, or lives in the
1027
1034
# same namespace as the referrer.
1028
1035
```
1029
1036
@@ -1394,7 +1401,7 @@ reduce data volume, load on the system, and noise exposed to users.
1394
1401
* Go field names must be PascalCase. JSON field names must be camelCase. Other
1395
1402
than capitalization of the initial letter, the two should almost always match.
1396
1403
No underscores or dashes in either.
1397
-
* Field and resource names should be declarative, not imperative (SomethingDoer,
1404
+
* Field and resource names should be declarative, not imperative (SomethingDoer,
1398
1405
DoneBy, DoneAt).
1399
1406
* Use `Node` where referring to
1400
1407
the node resource in the context of the cluster. Use `Host` where referring to
@@ -1528,7 +1535,7 @@ Kubernetes components and tools:
1528
1535
- Key prefixes under "kubernetes.io" and "k8s.io" are reserved for the Kubernetes
1529
1536
project.
1530
1537
- Such keys are effectively part of the kubernetes API and may be subject
1531
-
to deprecation and compatibility policies.
1538
+
to deprecation and compatibility policies.
1532
1539
- Key names, including prefixes, should be precise enough that a user could
1533
1540
plausibly understand where it came from and what it is for.
1534
1541
- Key prefixes should carry as much context as possible.
@@ -1617,19 +1624,19 @@ API objects often are [union](#Unions) object containing the following:
1617
1624
1. One or more fields identifying the `Type` specific to API object (aka the `discriminator`).
1618
1625
2. A set of N fields, only one of which should be set at any given time - effectively a union.
1619
1626
1620
-
Controllers operating on the API type often allocate resources based on
1621
-
the `Type` and/or some additional data provided by user. A canonical example
1622
-
of this is the `Service` API object where resources such as IPs and network ports
1623
-
will be set in the API object based on `Type`. When the user does not specify
1624
-
resources, they will be allocated, and when the user specifies exact value, they will
1627
+
Controllers operating on the API type often allocate resources based on
1628
+
the `Type` and/or some additional data provided by user. A canonical example
1629
+
of this is the `Service` API object where resources such as IPs and network ports
1630
+
will be set in the API object based on `Type`. When the user does not specify
1631
+
resources, they will be allocated, and when the user specifies exact value, they will
1625
1632
be reserved or rejected.
1626
1633
1627
-
When the user chooses to change the `discriminator` value (e.g., from `Type X` to `Type Y`) without
1628
-
changing any other fields then the system should clear the fields that were used to represent `Type X`
1629
-
in the union along with releasing resources that were attached to `Type X`. This should automatically
1630
-
happen irrespective of how these values and resources were allocated (i.e., reserved by the user or
1631
-
automatically allocated by the system. A concrete example of this is again `Service` API. The system
1632
-
allocates resources such as `NodePorts` and `ClusterIPs` and automatically fill in the fields that
1633
-
represent them in case of the service is of type `NodePort` or `ClusterIP` (`discriminator` values).
1634
-
These resources and the fields representing them are automatically cleared when the users changes
1635
-
service type to `ExternalName` where these resources and field values no longer apply.
1634
+
When the user chooses to change the `discriminator` value (e.g., from `Type X` to `Type Y`) without
1635
+
changing any other fields then the system should clear the fields that were used to represent `Type X`
1636
+
in the union along with releasing resources that were attached to `Type X`. This should automatically
1637
+
happen irrespective of how these values and resources were allocated (i.e., reserved by the user or
1638
+
automatically allocated by the system. A concrete example of this is again `Service` API. The system
1639
+
allocates resources such as `NodePorts` and `ClusterIPs` and automatically fill in the fields that
1640
+
represent them in case of the service is of type `NodePort` or `ClusterIP` (`discriminator` values).
1641
+
These resources and the fields representing them are automatically cleared when the users changes
1642
+
service type to `ExternalName` where these resources and field values no longer apply.
0 commit comments