Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelawyu committed Nov 12, 2024
1 parent 381e56e commit 3f0b91f
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/controllers/clusterresourceplacement/placement_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ func (r *Reconciler) setResourcePlacementStatusPerCluster(crp *fleetv1beta1.Clus
case condition.AppliedCondition, condition.AvailableCondition:
if bindingCond.Status == metav1.ConditionFalse {
status.FailedPlacements = binding.Status.FailedPlacements
status.DiffedPlacements = binding.Status.DiffedPlacements
status.DriftedPlacements = binding.Status.DriftedPlacements
}
}
cond := metav1.Condition{
Expand Down
201 changes: 201 additions & 0 deletions pkg/controllers/clusterresourceplacement/placement_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4081,6 +4081,207 @@ func TestSetResourcePlacementStatusPerCluster(t *testing.T) {
},
},
},
{
name: "drifts and configuration diffs",
binding: &fleetv1beta1.ClusterResourceBinding{
ObjectMeta: metav1.ObjectMeta{
Name: bindingName,
Generation: 1,
},
Spec: fleetv1beta1.ResourceBindingSpec{
ResourceSnapshotName: resourceSnapshotName,
ResourceOverrideSnapshots: []fleetv1beta1.NamespacedName{},
ClusterResourceOverrideSnapshots: []string{},
SchedulingPolicySnapshotName: fmt.Sprintf(fleetv1beta1.PolicySnapshotNameFmt, testName, 0),
TargetCluster: cluster,
},
Status: fleetv1beta1.ResourceBindingStatus{
FailedPlacements: []fleetv1beta1.FailedResourcePlacement{
{
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
Group: "",
Version: "v1",
Kind: "ConfigMap",
Name: "cm-1",
Namespace: "ns-1",
},
Condition: metav1.Condition{
Type: fleetv1beta1.WorkConditionTypeApplied,
Status: metav1.ConditionFalse,
},
},
},
DriftedPlacements: []fleetv1beta1.DriftedResourcePlacement{
{
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
Group: "",
Version: "v1",
Kind: "ConfigMap",
Name: "cm-1",
Namespace: "ns-1",
},
ObservationTime: metav1.Time{Time: time.Now()},
TargetClusterObservedGeneration: 1,
FirstDriftedObservedTime: metav1.Time{Time: time.Now()},
ObservedDrifts: []fleetv1beta1.PatchDetail{
{
Path: "/data",
ValueInMember: "k=1",
ValueInHub: "k=2",
},
},
},
},
DiffedPlacements: []fleetv1beta1.DiffedResourcePlacement{
{
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
Group: "apps",
Version: "v1",
Kind: "Deployment",
Name: "app-1",
Namespace: "ns-1",
},
ObservationTime: metav1.Time{Time: time.Now()},
TargetClusterObservedGeneration: 2,
FirstDiffedObservedTime: metav1.Time{Time: time.Now()},
ObservedDiffs: []fleetv1beta1.PatchDetail{
{
Path: "/spec/replicas",
ValueInMember: "1",
ValueInHub: "2",
},
},
},
},
Conditions: []metav1.Condition{
{
Status: metav1.ConditionTrue,
Type: string(fleetv1beta1.ResourceBindingRolloutStarted),
Reason: condition.RolloutStartedReason,
ObservedGeneration: 1,
},
{
Status: metav1.ConditionTrue,
Type: string(fleetv1beta1.ResourceBindingOverridden),
Reason: condition.OverriddenSucceededReason,
ObservedGeneration: 1,
},
{
Status: metav1.ConditionTrue,
Type: string(fleetv1beta1.ResourceBindingWorkSynchronized),
Reason: condition.WorkSynchronizedReason,
ObservedGeneration: 1,
},
{
Status: metav1.ConditionFalse,
Type: string(fleetv1beta1.ResourceBindingApplied),
Reason: condition.ApplySucceededReason,
ObservedGeneration: 1,
},
{
Status: metav1.ConditionFalse,
Type: string(fleetv1beta1.ResourceBindingAvailable),
Reason: condition.NotAvailableYetReason,
ObservedGeneration: 1,
},
},
},
},
want: []metav1.ConditionStatus{
metav1.ConditionTrue,
metav1.ConditionTrue,
metav1.ConditionTrue,
metav1.ConditionFalse,
},
wantStatus: fleetv1beta1.ResourcePlacementStatus{
ClusterName: cluster,
ApplicableResourceOverrides: []fleetv1beta1.NamespacedName{},
ApplicableClusterResourceOverrides: []string{},
FailedPlacements: []fleetv1beta1.FailedResourcePlacement{
{
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
Group: "",
Version: "v1",
Kind: "ConfigMap",
Name: "cm-1",
Namespace: "ns-1",
},
Condition: metav1.Condition{
Type: fleetv1beta1.WorkConditionTypeApplied,
Status: metav1.ConditionFalse,
},
},
},
DriftedPlacements: []fleetv1beta1.DriftedResourcePlacement{
{
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
Group: "",
Version: "v1",
Kind: "ConfigMap",
Name: "cm-1",
Namespace: "ns-1",
},
ObservationTime: metav1.Time{Time: time.Now()},
TargetClusterObservedGeneration: 1,
FirstDriftedObservedTime: metav1.Time{Time: time.Now()},
ObservedDrifts: []fleetv1beta1.PatchDetail{
{
Path: "/data",
ValueInMember: "k=1",
ValueInHub: "k=2",
},
},
},
},
DiffedPlacements: []fleetv1beta1.DiffedResourcePlacement{
{
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
Group: "apps",
Version: "v1",
Kind: "Deployment",
Name: "app-1",
Namespace: "ns-1",
},
ObservationTime: metav1.Time{Time: time.Now()},
TargetClusterObservedGeneration: 2,
FirstDiffedObservedTime: metav1.Time{Time: time.Now()},
ObservedDiffs: []fleetv1beta1.PatchDetail{
{
Path: "/spec/replicas",
ValueInMember: "1",
ValueInHub: "2",
},
},
},
},
Conditions: []metav1.Condition{
{
Status: metav1.ConditionTrue,
Type: string(fleetv1beta1.ResourceBindingRolloutStarted),
Reason: condition.RolloutStartedReason,
ObservedGeneration: crpGeneration,
},
{
Status: metav1.ConditionTrue,
Type: string(fleetv1beta1.ResourceBindingOverridden),
Reason: condition.OverriddenSucceededReason,
ObservedGeneration: crpGeneration,
},
{
Status: metav1.ConditionTrue,
Type: string(fleetv1beta1.ResourceBindingWorkSynchronized),
Reason: condition.WorkSynchronizedReason,
ObservedGeneration: crpGeneration,
},
{
Status: metav1.ConditionFalse,
Type: string(fleetv1beta1.ResourceBindingApplied),
Reason: condition.ApplySucceededReason,
ObservedGeneration: crpGeneration,
},
},
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 3f0b91f

Please sign in to comment.