From 23065f8a995311dc5841e2bdf49fdc830f860a61 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Sat, 16 Nov 2024 00:19:15 +0800 Subject: [PATCH] Make changes on the Work object status API --- apis/cluster/v1beta1/zz_generated.deepcopy.go | 2 +- .../v1alpha1/zz_generated.deepcopy.go | 5 +- apis/placement/v1beta1/work_types.go | 87 ++++++- .../v1beta1/zz_generated.deepcopy.go | 62 ++++- apis/v1alpha1/zz_generated.deepcopy.go | 2 +- .../placement.kubernetes-fleet.io_works.yaml | 240 +++++++++++------- test/apis/v1alpha1/zz_generated.deepcopy.go | 2 +- 7 files changed, 281 insertions(+), 119 deletions(-) diff --git a/apis/cluster/v1beta1/zz_generated.deepcopy.go b/apis/cluster/v1beta1/zz_generated.deepcopy.go index 6c25f0189..6d06cb15b 100644 --- a/apis/cluster/v1beta1/zz_generated.deepcopy.go +++ b/apis/cluster/v1beta1/zz_generated.deepcopy.go @@ -10,7 +10,7 @@ Licensed under the MIT license. package v1beta1 import ( - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) diff --git a/apis/placement/v1alpha1/zz_generated.deepcopy.go b/apis/placement/v1alpha1/zz_generated.deepcopy.go index 1a3f72658..d26fe49a5 100644 --- a/apis/placement/v1alpha1/zz_generated.deepcopy.go +++ b/apis/placement/v1alpha1/zz_generated.deepcopy.go @@ -10,11 +10,10 @@ Licensed under the MIT license. package v1alpha1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "go.goms.io/fleet/apis/placement/v1beta1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" - - "go.goms.io/fleet/apis/placement/v1beta1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/apis/placement/v1beta1/work_types.go b/apis/placement/v1beta1/work_types.go index 823651496..2a7c38200 100644 --- a/apis/placement/v1beta1/work_types.go +++ b/apis/placement/v1beta1/work_types.go @@ -113,6 +113,73 @@ type WorkResourceIdentifier struct { Name string `json:"name,omitempty"` } +// DriftDetails describes the observed configuration drifts. +type DriftDetails struct { + // ObservationTime is the timestamp when the drift was last detected. + // + // +kubebuilder:validation:Required + // +kubebuilder:validation:Type=string + // +kubebuilder:validation:Format=date-time + ObservationTime metav1.Time `json:"observationTime"` + + // ObservedInMemberClusterGeneration is the generation of the applied manifest on the member + // cluster side. + // + // +kubebuilder:validation:Required + ObservedInMemberClusterGeneration int64 `json:"observedInMemberClusterGeneration"` + + // FirsftDriftedObservedTime is the timestamp when the drift was first detected. + // + // +kubebuilder:validation:Required + // +kubebuilder:validation:Type=string + // +kubebuilder:validation:Format=date-time + FirstDriftedObservedTime metav1.Time `json:"firstDriftedObservedTime"` + + // ObservedDrifts describes each drifted field found from the applied manifest. + // Fleet might truncate the details as appropriate to control object size. + // + // Each entry specifies how the live state (the state on the member cluster side) compares + // against the desired state (the state kept in the hub cluster manifest). + // + // +kubebuilder:validation:Optional + ObservedDrifts []PatchDetail `json:"observedDrifts,omitempty"` +} + +// DiffDetails describes the observed configuration differences. +type DiffDetails struct { + // ObservationTime is the timestamp when the configuration difference was last detected. + // + // +kubebuilder:validation:Required + // +kubebuilder:validation:Type=string + // +kubebuilder:validation:Format=date-time + ObservationTime metav1.Time `json:"observationTime"` + + // ObservedInMemberClusterGeneration is the generation of the applied manifest on the member + // cluster side. + // + // +kubebuilder:validation:Required + ObservedInMemberClusterGeneration int64 `json:"observedInMemberClusterGeneration"` + + // FirsftDiffedObservedTime is the timestamp when the configuration difference + // was first detected. + // + // +kubebuilder:validation:Required + // +kubebuilder:validation:Type=string + // +kubebuilder:validation:Format=date-time + FirstDiffedObservedTime metav1.Time `json:"firstDiffedObservedTime"` + + // ObservedDiffs describes each field with configuration difference as found from the + // member cluster side. + // + // Fleet might truncate the details as appropriate to control object size. + // + // Each entry specifies how the live state (the state on the member cluster side) compares + // against the desired state (the state kept in the hub cluster manifest). + // + // +kubebuilder:validation:Optional + ObservedDiffs []PatchDetail `json:"observedDiffs,omitempty"` +} + // ManifestCondition represents the conditions of the resources deployed on // spoke cluster. type ManifestCondition struct { @@ -124,31 +191,27 @@ type ManifestCondition struct { // +required Conditions []metav1.Condition `json:"conditions"` - // ObservedDrifts explains the details about the observed configuration drifts. + // DriftDetails explains about the observed configuration drifts. // Fleet might truncate the details as appropriate to control object size. // - // Each detail entry specifies how the live state (the state on the member - // cluster side) compares against the desired state (the state kept in the hub cluster manifest). - // // Note that configuration drifts can only occur on a resource if it is currently owned by // Fleet and its corresponding placement is set to use the ClientSideApply or ServerSideApply - // apply strategy. In other words, ObservedDrifts and ObservedDiffs will not be populated + // apply strategy. In other words, DriftDetails and DiffDetails will not be populated // at the same time. + // // +kubebuilder:validation:Optional - ObservedDrifts []PatchDetail `json:"observedDrifts,omitempty"` + DriftDetails *DriftDetails `json:"driftDetails,omitempty"` - // ObservedDiffs explains the details about the observed configuration differences. + // DiffDetails explains the details about the observed configuration differences. // Fleet might truncate the details as appropriate to control object size. // - // Each detail entry specifies how the live state (the state on the member - // cluster side) compares against the desired state (the state kept in the hub cluster manifest). - // // Note that configuration differences can only occur on a resource if it is not currently owned // by Fleet (i.e., it is a pre-existing resource that needs to be taken over), or if its // corresponding placement is set to use the ReportDiff apply strategy. In other words, - // ObservedDiffs and ObservedDrifts will not be populated at the same time. + // DiffDetails and DriftDetails will not be populated at the same time. + // // +kubebuilder:validation:Optional - ObservedDiffs []PatchDetail `json:"observedDiffs,omitempty"` + DiffDetails *DiffDetails `json:"diffDetails,omitempty"` } // +genclient diff --git a/apis/placement/v1beta1/zz_generated.deepcopy.go b/apis/placement/v1beta1/zz_generated.deepcopy.go index 754effe01..803ac0287 100644 --- a/apis/placement/v1beta1/zz_generated.deepcopy.go +++ b/apis/placement/v1beta1/zz_generated.deepcopy.go @@ -10,7 +10,7 @@ Licensed under the MIT license. package v1beta1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -614,6 +614,28 @@ func (in *ClusterSelectorTerm) DeepCopy() *ClusterSelectorTerm { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DiffDetails) DeepCopyInto(out *DiffDetails) { + *out = *in + in.ObservationTime.DeepCopyInto(&out.ObservationTime) + in.FirstDiffedObservedTime.DeepCopyInto(&out.FirstDiffedObservedTime) + if in.ObservedDiffs != nil { + in, out := &in.ObservedDiffs, &out.ObservedDiffs + *out = make([]PatchDetail, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiffDetails. +func (in *DiffDetails) DeepCopy() *DiffDetails { + if in == nil { + return nil + } + out := new(DiffDetails) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DiffedResourcePlacement) DeepCopyInto(out *DiffedResourcePlacement) { *out = *in @@ -637,6 +659,28 @@ func (in *DiffedResourcePlacement) DeepCopy() *DiffedResourcePlacement { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DriftDetails) DeepCopyInto(out *DriftDetails) { + *out = *in + in.ObservationTime.DeepCopyInto(&out.ObservationTime) + in.FirstDriftedObservedTime.DeepCopyInto(&out.FirstDriftedObservedTime) + if in.ObservedDrifts != nil { + in, out := &in.ObservedDrifts, &out.ObservedDrifts + *out = make([]PatchDetail, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DriftDetails. +func (in *DriftDetails) DeepCopy() *DriftDetails { + if in == nil { + return nil + } + out := new(DriftDetails) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DriftedResourcePlacement) DeepCopyInto(out *DriftedResourcePlacement) { *out = *in @@ -719,15 +763,15 @@ func (in *ManifestCondition) DeepCopyInto(out *ManifestCondition) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - if in.ObservedDrifts != nil { - in, out := &in.ObservedDrifts, &out.ObservedDrifts - *out = make([]PatchDetail, len(*in)) - copy(*out, *in) + if in.DriftDetails != nil { + in, out := &in.DriftDetails, &out.DriftDetails + *out = new(DriftDetails) + (*in).DeepCopyInto(*out) } - if in.ObservedDiffs != nil { - in, out := &in.ObservedDiffs, &out.ObservedDiffs - *out = make([]PatchDetail, len(*in)) - copy(*out, *in) + if in.DiffDetails != nil { + in, out := &in.DiffDetails, &out.DiffDetails + *out = new(DiffDetails) + (*in).DeepCopyInto(*out) } } diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index ac4844274..0d4061551 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -11,7 +11,7 @@ package v1alpha1 import ( corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) diff --git a/config/crd/bases/placement.kubernetes-fleet.io_works.yaml b/config/crd/bases/placement.kubernetes-fleet.io_works.yaml index b1faf9bc7..de85a3e7f 100644 --- a/config/crd/bases/placement.kubernetes-fleet.io_works.yaml +++ b/config/crd/bases/placement.kubernetes-fleet.io_works.yaml @@ -740,6 +740,154 @@ spec: - type type: object type: array + diffDetails: + description: |- + DiffDetails explains the details about the observed configuration differences. + Fleet might truncate the details as appropriate to control object size. + + + Note that configuration differences can only occur on a resource if it is not currently owned + by Fleet (i.e., it is a pre-existing resource that needs to be taken over), or if its + corresponding placement is set to use the ReportDiff apply strategy. In other words, + DiffDetails and DriftDetails will not be populated at the same time. + properties: + firstDiffedObservedTime: + description: |- + FirsftDiffedObservedTime is the timestamp when the configuration difference + was first detected. + format: date-time + type: string + observationTime: + description: ObservationTime is the timestamp when the configuration + difference was last detected. + format: date-time + type: string + observedDiffs: + description: |- + ObservedDiffs describes each field with configuration difference as found from the + member cluster side. + + + Fleet might truncate the details as appropriate to control object size. + + + Each entry specifies how the live state (the state on the member cluster side) compares + against the desired state (the state kept in the hub cluster manifest). + items: + description: |- + PatchDetail describes a patch that explains an observed configuration drift or + difference. + + + A patch detail can be transcribed as a JSON patch operation, as specified in RFC 6902. + properties: + path: + description: The JSON path that points to a field + that has drifted or has configuration differences. + type: string + valueInHub: + description: |- + The value at the JSON path from the hub cluster side. + + + This field can be empty if the JSON path does not exist on the hub cluster side; i.e., + applying the manifest from the hub cluster side would remove the field. + type: string + valueInMember: + description: |- + The value at the JSON path from the member cluster side. + + + This field can be empty if the JSON path does not exist on the member cluster side; i.e., + applying the manifest from the hub cluster side would add a new field. + type: string + required: + - path + type: object + type: array + observedInMemberClusterGeneration: + description: |- + ObservedInMemberClusterGeneration is the generation of the applied manifest on the member + cluster side. + format: int64 + type: integer + required: + - firstDiffedObservedTime + - observationTime + - observedInMemberClusterGeneration + type: object + driftDetails: + description: |- + DriftDetails explains about the observed configuration drifts. + Fleet might truncate the details as appropriate to control object size. + + + Note that configuration drifts can only occur on a resource if it is currently owned by + Fleet and its corresponding placement is set to use the ClientSideApply or ServerSideApply + apply strategy. In other words, DriftDetails and DiffDetails will not be populated + at the same time. + properties: + firstDriftedObservedTime: + description: FirsftDriftedObservedTime is the timestamp + when the drift was first detected. + format: date-time + type: string + observationTime: + description: ObservationTime is the timestamp when the drift + was last detected. + format: date-time + type: string + observedDrifts: + description: |- + ObservedDrifts describes each drifted field found from the applied manifest. + Fleet might truncate the details as appropriate to control object size. + + + Each entry specifies how the live state (the state on the member cluster side) compares + against the desired state (the state kept in the hub cluster manifest). + items: + description: |- + PatchDetail describes a patch that explains an observed configuration drift or + difference. + + + A patch detail can be transcribed as a JSON patch operation, as specified in RFC 6902. + properties: + path: + description: The JSON path that points to a field + that has drifted or has configuration differences. + type: string + valueInHub: + description: |- + The value at the JSON path from the hub cluster side. + + + This field can be empty if the JSON path does not exist on the hub cluster side; i.e., + applying the manifest from the hub cluster side would remove the field. + type: string + valueInMember: + description: |- + The value at the JSON path from the member cluster side. + + + This field can be empty if the JSON path does not exist on the member cluster side; i.e., + applying the manifest from the hub cluster side would add a new field. + type: string + required: + - path + type: object + type: array + observedInMemberClusterGeneration: + description: |- + ObservedInMemberClusterGeneration is the generation of the applied manifest on the member + cluster side. + format: int64 + type: integer + required: + - firstDriftedObservedTime + - observationTime + - observedInMemberClusterGeneration + type: object identifier: description: resourceId represents a identity of a resource linking to manifests in spec. @@ -772,98 +920,6 @@ spec: required: - ordinal type: object - observedDiffs: - description: |- - ObservedDiffs explains the details about the observed configuration differences. - Fleet might truncate the details as appropriate to control object size. - - - Each detail entry specifies how the live state (the state on the member - cluster side) compares against the desired state (the state kept in the hub cluster manifest). - - - Note that configuration differences can only occur on a resource if it is not currently owned - by Fleet (i.e., it is a pre-existing resource that needs to be taken over), or if its - corresponding placement is set to use the ReportDiff apply strategy. In other words, - ObservedDiffs and ObservedDrifts will not be populated at the same time. - items: - description: |- - PatchDetail describes a patch that explains an observed configuration drift or - difference. - - - A patch detail can be transcribed as a JSON patch operation, as specified in RFC 6902. - properties: - path: - description: The JSON path that points to a field that - has drifted or has configuration differences. - type: string - valueInHub: - description: |- - The value at the JSON path from the hub cluster side. - - - This field can be empty if the JSON path does not exist on the hub cluster side; i.e., - applying the manifest from the hub cluster side would remove the field. - type: string - valueInMember: - description: |- - The value at the JSON path from the member cluster side. - - - This field can be empty if the JSON path does not exist on the member cluster side; i.e., - applying the manifest from the hub cluster side would add a new field. - type: string - required: - - path - type: object - type: array - observedDrifts: - description: |- - ObservedDrifts explains the details about the observed configuration drifts. - Fleet might truncate the details as appropriate to control object size. - - - Each detail entry specifies how the live state (the state on the member - cluster side) compares against the desired state (the state kept in the hub cluster manifest). - - - Note that configuration drifts can only occur on a resource if it is currently owned by - Fleet and its corresponding placement is set to use the ClientSideApply or ServerSideApply - apply strategy. In other words, ObservedDrifts and ObservedDiffs will not be populated - at the same time. - items: - description: |- - PatchDetail describes a patch that explains an observed configuration drift or - difference. - - - A patch detail can be transcribed as a JSON patch operation, as specified in RFC 6902. - properties: - path: - description: The JSON path that points to a field that - has drifted or has configuration differences. - type: string - valueInHub: - description: |- - The value at the JSON path from the hub cluster side. - - - This field can be empty if the JSON path does not exist on the hub cluster side; i.e., - applying the manifest from the hub cluster side would remove the field. - type: string - valueInMember: - description: |- - The value at the JSON path from the member cluster side. - - - This field can be empty if the JSON path does not exist on the member cluster side; i.e., - applying the manifest from the hub cluster side would add a new field. - type: string - required: - - path - type: object - type: array required: - conditions type: object diff --git a/test/apis/v1alpha1/zz_generated.deepcopy.go b/test/apis/v1alpha1/zz_generated.deepcopy.go index ef7e4433a..0b5d2e30b 100644 --- a/test/apis/v1alpha1/zz_generated.deepcopy.go +++ b/test/apis/v1alpha1/zz_generated.deepcopy.go @@ -10,7 +10,7 @@ Licensed under the MIT license. package v1alpha1 import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" )