Skip to content

Commit

Permalink
update merge annotation for kruise apis (openkruise#1402)
Browse files Browse the repository at this point in the history
* update merge annotation for apis


* fix sidecarset ut and change annotation


---------
  • Loading branch information
y-ykcir authored Sep 19, 2023
1 parent a8d07f1 commit 154db5f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 12 deletions.
4 changes: 3 additions & 1 deletion apis/apps/v1alpha1/containerrecreaterequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ type ContainerRecreateRequestSpec struct {
// PodName is name of the Pod that owns the recreated containers.
PodName string `json:"podName"`
// Containers contains the containers that need to recreate in the Pod.
Containers []ContainerRecreateRequestContainer `json:"containers"`
// +patchMergeKey=name
// +patchStrategy=merge
Containers []ContainerRecreateRequestContainer `json:"containers" patchStrategy:"merge" patchMergeKey:"name"`
// Strategy defines strategies for containers recreation.
Strategy *ContainerRecreateRequestStrategy `json:"strategy,omitempty"`
// ActiveDeadlineSeconds is the deadline duration of this ContainerRecreateRequest.
Expand Down
4 changes: 3 additions & 1 deletion apis/apps/v1alpha1/ephemeraljob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ type EphemeralContainerTemplateSpec struct {
// EphemeralContainers defines ephemeral container list in match pods.
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
EphemeralContainers []v1.EphemeralContainer `json:"ephemeralContainers"`
// +patchMergeKey=name
// +patchStrategy=merge
EphemeralContainers []v1.EphemeralContainer `json:"ephemeralContainers" patchStrategy:"merge" patchMergeKey:"name"`
}

// EphemeralJobStatus defines the observed state of EphemeralJob
Expand Down
8 changes: 6 additions & 2 deletions apis/apps/v1alpha1/pod_probe_marker_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ type PodProbeMarkerSpec struct {
// Probe Result will record in Pod.Status.Conditions, and condition.type=probe.name.
// condition.status=True indicates probe success
// condition.status=False indicates probe fails
Probes []PodContainerProbe `json:"probes"`
// +patchMergeKey=name
// +patchStrategy=merge
Probes []PodContainerProbe `json:"probes" patchStrategy:"merge" patchMergeKey:"name"`
}

type PodContainerProbe struct {
Expand All @@ -44,7 +46,9 @@ type PodContainerProbe struct {
// According to the execution result of ContainerProbe, perform specific actions,
// such as: patch Pod labels, annotations, ReadinessGate Condition
// It cannot be null at the same time as PodConditionType.
MarkerPolicy []ProbeMarkerPolicy `json:"markerPolicy,omitempty"`
// +patchMergeKey=state
// +patchStrategy=merge
MarkerPolicy []ProbeMarkerPolicy `json:"markerPolicy,omitempty" patchStrategy:"merge" patchMergeKey:"state"`
// If it is not empty, the Probe execution result will be recorded on the Pod condition.
// It cannot be null at the same time as MarkerPolicy.
// For example PodConditionType=game.kruise.io/healthy, pod.status.condition.type = game.kruise.io/healthy.
Expand Down
4 changes: 3 additions & 1 deletion apis/apps/v1alpha1/resourcedistribution_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ type ResourceDistributionTargetNamespaces struct {
Pattern string `json:"pattern,omitempty"`
*/

// +patchMergeKey=name
// +patchStrategy=merge
// +optional
List []ResourceDistributionNamespace `json:"list,omitempty"`
List []ResourceDistributionNamespace `json:"list,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

// ResourceDistributionNamespace contains a namespace name
Expand Down
16 changes: 12 additions & 4 deletions apis/apps/v1alpha1/sidecarset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ type SidecarSetSpec struct {
// InitContainers is the list of init containers to be injected into the selected pod
// We will inject those containers by their name in ascending order
// We only inject init containers when a new pod is created, it does not apply to any existing pod
InitContainers []SidecarContainer `json:"initContainers,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
InitContainers []SidecarContainer `json:"initContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

// Containers is the list of sidecar containers to be injected into the selected pod
Containers []SidecarContainer `json:"containers,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Containers []SidecarContainer `json:"containers,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

// List of volumes that can be mounted by sidecar containers
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Volumes []corev1.Volume `json:"volumes,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

// The sidecarset updateStrategy to use to replace existing pods with new ones.
UpdateStrategy SidecarSetUpdateStrategy `json:"updateStrategy,omitempty"`
Expand All @@ -66,7 +72,9 @@ type SidecarSetSpec struct {
InjectionStrategy SidecarSetInjectionStrategy `json:"injectionStrategy,omitempty"`

// List of the names of secrets required by pulling sidecar container images
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// +patchMergeKey=name
// +patchStrategy=merge
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

// RevisionHistoryLimit indicates the maximum quantity of stored revisions about the SidecarSet.
// default value is 10
Expand Down
4 changes: 3 additions & 1 deletion apis/apps/v1alpha1/uniteddeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ type ManualUpdate struct {
type Topology struct {
// Contains the details of each subset. Each element in this array represents one subset
// which will be provisioned and managed by UnitedDeployment.
// +patchMergeKey=name
// +patchStrategy=merge
// +optional
Subsets []Subset `json:"subsets,omitempty"`
Subsets []Subset `json:"subsets,omitempty" patchStrategy:"merge" patchMergeKey:"name"`
}

// Subset defines the detail of a subset.
Expand Down
4 changes: 3 additions & 1 deletion apis/apps/v1alpha1/workloadspread_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type WorkloadSpreadSpec struct {
TargetReference *TargetReference `json:"targetRef"`

// Subsets describes the pods distribution details between each of subsets.
Subsets []WorkloadSpreadSubset `json:"subsets"`
// +patchMergeKey=name
// +patchStrategy=merge
Subsets []WorkloadSpreadSubset `json:"subsets" patchStrategy:"merge" patchMergeKey:"name"`

// ScheduleStrategy indicates the strategy the WorkloadSpread used to preform the schedule between each of subsets.
// +optional
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/sidecarcontrol/history_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (r *realControl) getControllerRevision(set *appsv1alpha1.SidecarSet, revisi

func copySidecarSetSpecRevision(dst, src map[string]interface{}) {
// we will use patch instead of update operation to update pods in the future
// dst["$patch"] = "replace"
dst["$patch"] = "replace"
// only record these revisions
dst["volumes"] = src["volumes"]
dst["containers"] = src["containers"]
Expand Down
1 change: 1 addition & 0 deletions pkg/webhook/pod/mutating/sidecarset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ func TestInjectMetadata(t *testing.T) {
func TestInjectionStrategyRevision(t *testing.T) {
spec := map[string]interface{}{
"spec": map[string]interface{}{
"$patch": "replace",
"initContainers": []appsv1alpha1.SidecarContainer{
{
Container: corev1.Container{
Expand Down

0 comments on commit 154db5f

Please sign in to comment.