mirror of
https://github.com/kubernetes/sample-controller.git
synced 2026-05-01 00:00:03 +08:00
Merge pull request #60021 from nikhita/sample-controller-subresources
Automatic merge from submit-queue (batch tested with PRs 60102, 59970, 60021, 62011, 62080). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. sample-controller: add status subresource support Builds on top of https://github.com/kubernetes/kubernetes/pull/55168. **DO NOT MERGE** until https://github.com/kubernetes/kubernetes/pull/55168 is merged. Adding a hold. /hold Update: It is now merged! 🎉 This PR: - Adds an example to show how to use the `/status` subresource with custom resources. - Generates `UpdateStatus` for the `Foo` resource. - Updates the comment in the controller to mention that `UpdateStatus` can now be used. Note: this is not enabled by default because subresources require the feature gate to be enabled and are not on by default. - Updates the README to add feature gate information and examples for `CustomResourceSubresources`. - Updates the README to remove feature gate information for CRD validation since the current example uses `apps/v1` deployments (and thus requires v1.9 anyway). **Release note**: ```release-note NONE ``` /assign sttts munnerz Kubernetes-commit: 7bde13f191f0791a87fe5e2575feb3d4849de536
This commit is contained in:
+1
-1
@@ -82,7 +82,7 @@ func (obj *Unstructured) EachListItem(fn func(runtime.Object) error) error {
|
||||
|
||||
func (obj *Unstructured) UnstructuredContent() map[string]interface{} {
|
||||
if obj.Object == nil {
|
||||
obj.Object = make(map[string]interface{})
|
||||
return make(map[string]interface{})
|
||||
}
|
||||
return obj.Object
|
||||
}
|
||||
|
||||
+8
-9
@@ -53,19 +53,18 @@ func (u *UnstructuredList) EachListItem(fn func(runtime.Object) error) error {
|
||||
}
|
||||
|
||||
// UnstructuredContent returns a map contain an overlay of the Items field onto
|
||||
// the Object field. Items always overwrites overlay. Changing "items" in the
|
||||
// returned object will affect items in the underlying Items field, but changing
|
||||
// the "items" slice itself will have no effect.
|
||||
// TODO: expose SetUnstructuredContent on runtime.Unstructured that allows
|
||||
// items to be changed.
|
||||
// the Object field. Items always overwrites overlay.
|
||||
func (u *UnstructuredList) UnstructuredContent() map[string]interface{} {
|
||||
out := u.Object
|
||||
if out == nil {
|
||||
out = make(map[string]interface{})
|
||||
out := make(map[string]interface{}, len(u.Object)+1)
|
||||
|
||||
// shallow copy every property
|
||||
for k, v := range u.Object {
|
||||
out[k] = v
|
||||
}
|
||||
|
||||
items := make([]interface{}, len(u.Items))
|
||||
for i, item := range u.Items {
|
||||
items[i] = item.Object
|
||||
items[i] = item.UnstructuredContent()
|
||||
}
|
||||
out["items"] = items
|
||||
return out
|
||||
|
||||
+9
-2
@@ -411,8 +411,7 @@ func (c *unstructuredConverter) ToUnstructured(obj interface{}) (map[string]inte
|
||||
var u map[string]interface{}
|
||||
var err error
|
||||
if unstr, ok := obj.(Unstructured); ok {
|
||||
// UnstructuredContent() mutates the object so we need to make a copy first
|
||||
u = unstr.DeepCopyObject().(Unstructured).UnstructuredContent()
|
||||
u = unstr.UnstructuredContent()
|
||||
} else {
|
||||
t := reflect.TypeOf(obj)
|
||||
value := reflect.ValueOf(obj)
|
||||
@@ -449,12 +448,20 @@ func DeepCopyJSON(x map[string]interface{}) map[string]interface{} {
|
||||
func DeepCopyJSONValue(x interface{}) interface{} {
|
||||
switch x := x.(type) {
|
||||
case map[string]interface{}:
|
||||
if x == nil {
|
||||
// Typed nil - an interface{} that contains a type map[string]interface{} with a value of nil
|
||||
return x
|
||||
}
|
||||
clone := make(map[string]interface{}, len(x))
|
||||
for k, v := range x {
|
||||
clone[k] = DeepCopyJSONValue(v)
|
||||
}
|
||||
return clone
|
||||
case []interface{}:
|
||||
if x == nil {
|
||||
// Typed nil - an interface{} that contains a type []interface{} with a value of nil
|
||||
return x
|
||||
}
|
||||
clone := make([]interface{}, len(x))
|
||||
for i, v := range x {
|
||||
clone[i] = DeepCopyJSONValue(v)
|
||||
|
||||
+2
-2
@@ -234,9 +234,9 @@ type Object interface {
|
||||
// to JSON allowed.
|
||||
type Unstructured interface {
|
||||
Object
|
||||
// UnstructuredContent returns a non-nil, mutable map of the contents of this object. Values may be
|
||||
// UnstructuredContent returns a non-nil map with this object's contents. Values may be
|
||||
// []interface{}, map[string]interface{}, or any primitive type. Contents are typically serialized to
|
||||
// and from JSON.
|
||||
// and from JSON. SetUnstructuredContent should be used to mutate the contents.
|
||||
UnstructuredContent() map[string]interface{}
|
||||
// SetUnstructuredContent updates the object content to match the provided map.
|
||||
SetUnstructuredContent(map[string]interface{})
|
||||
|
||||
+23
@@ -880,6 +880,29 @@ func StrategicMergeMapPatchUsingLookupPatchMeta(original, patch JSONMap, schema
|
||||
return mergeMap(original, patch, schema, mergeOptions)
|
||||
}
|
||||
|
||||
// MergeStrategicMergeMapPatchUsingLookupPatchMeta merges strategic merge
|
||||
// patches retaining `null` fields and parallel lists. If 2 patches change the
|
||||
// same fields and the latter one will override the former one. If you don't
|
||||
// want that happen, you need to run func MergingMapsHaveConflicts before
|
||||
// merging these patches. Applying the resulting merged merge patch to a JSONMap
|
||||
// yields the same as merging each strategic merge patch to the JSONMap in
|
||||
// succession.
|
||||
func MergeStrategicMergeMapPatchUsingLookupPatchMeta(schema LookupPatchMeta, patches ...JSONMap) (JSONMap, error) {
|
||||
mergeOptions := MergeOptions{
|
||||
MergeParallelList: false,
|
||||
IgnoreUnmatchedNulls: false,
|
||||
}
|
||||
merged := JSONMap{}
|
||||
var err error
|
||||
for _, patch := range patches {
|
||||
merged, err = mergeMap(merged, patch, schema, mergeOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return merged, nil
|
||||
}
|
||||
|
||||
// handleDirectiveInMergeMap handles the patch directive when merging 2 maps.
|
||||
func handleDirectiveInMergeMap(directive interface{}, patch map[string]interface{}) (map[string]interface{}, error) {
|
||||
if directive == replaceDirective {
|
||||
|
||||
Reference in New Issue
Block a user