diff --git a/pkg/apis/config/v1alpha1/explorereview_types.go b/pkg/apis/config/v1alpha1/explorereview_types.go index 56acecc7d..a0a9ca091 100644 --- a/pkg/apis/config/v1alpha1/explorereview_types.go +++ b/pkg/apis/config/v1alpha1/explorereview_types.go @@ -52,6 +52,11 @@ type ExploreRequest struct { // +optional Object runtime.RawExtension `json:"object,omitempty"` + // ObservedObject is the object observed from the kube-apiserver of member clusters. + // Not nil only when OperationType is ExploreRetaining. + // +optional + ObservedObject *runtime.RawExtension `json:"observedObject,omitempty"` + // DesiredReplicas represents the desired pods number which webhook should revise with. // It'll be set only if OperationType is ExploreReplicaRevising. // +optional diff --git a/pkg/apis/config/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/config/v1alpha1/zz_generated.deepcopy.go index e40317b7c..266aa1720 100644 --- a/pkg/apis/config/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/config/v1alpha1/zz_generated.deepcopy.go @@ -32,6 +32,11 @@ func (in *ExploreRequest) DeepCopyInto(out *ExploreRequest) { *out = *in out.Kind = in.Kind in.Object.DeepCopyInto(&out.Object) + if in.ObservedObject != nil { + in, out := &in.ObservedObject, &out.ObservedObject + *out = new(runtime.RawExtension) + (*in).DeepCopyInto(*out) + } if in.DesiredReplicas != nil { in, out := &in.DesiredReplicas, &out.DesiredReplicas *out = new(int32) diff --git a/pkg/crdexplorer/crdexplorer.go b/pkg/crdexplorer/crdexplorer.go index 2ff9e1e57..82f24bc1a 100644 --- a/pkg/crdexplorer/crdexplorer.go +++ b/pkg/crdexplorer/crdexplorer.go @@ -25,8 +25,8 @@ type CustomResourceExplorer interface { // GetReplicas returns the desired replicas of the object as well as the requirements of each replica. GetReplicas(object *unstructured.Unstructured) (replica int32, replicaRequires *workv1alpha2.ReplicaRequirements, err error) - // Retain returns the objects that based on the "desired" object but with values retained from the "cluster" object. - Retain(desired *unstructured.Unstructured, cluster *unstructured.Unstructured) (retained *unstructured.Unstructured, err error) + // Retain returns the objects that based on the "desired" object but with values retained from the "observed" object. + Retain(desired *unstructured.Unstructured, observed *unstructured.Unstructured) (retained *unstructured.Unstructured, err error) // other common method } @@ -93,6 +93,7 @@ func (i *customResourceExplorerImpl) GetReplicas(object *unstructured.Unstructur return } +// Retain returns the objects that based on the "desired" object but with values retained from the "observed" object. func (i *customResourceExplorerImpl) Retain(desired *unstructured.Unstructured, cluster *unstructured.Unstructured) (retained *unstructured.Unstructured, err error) { // TODO(RainbowMango): consult to the dynamic webhooks first. diff --git a/pkg/crdexplorer/defaultexplorer/default.go b/pkg/crdexplorer/defaultexplorer/default.go index a83b0d322..83af10bf4 100644 --- a/pkg/crdexplorer/defaultexplorer/default.go +++ b/pkg/crdexplorer/defaultexplorer/default.go @@ -51,12 +51,12 @@ func (e *DefaultExplorer) GetReplicas(object *unstructured.Unstructured) (int32, return handler(object) } -// Retain returns the objects that based on the "desired" object but with values retained from the "cluster" object. -func (e *DefaultExplorer) Retain(desired *unstructured.Unstructured, cluster *unstructured.Unstructured) (retained *unstructured.Unstructured, err error) { +// Retain returns the objects that based on the "desired" object but with values retained from the "observed" object. +func (e *DefaultExplorer) Retain(desired *unstructured.Unstructured, observed *unstructured.Unstructured) (retained *unstructured.Unstructured, err error) { handler, exist := e.retentionHandlers[desired.GroupVersionKind()] if !exist { return nil, fmt.Errorf("default explorer for operation %s not found", configv1alpha1.ExploreRetaining) } - return handler(desired, cluster) + return handler(desired, observed) }