Skip to content

Commit

Permalink
fix the mca override cma configs issues (open-cluster-management-io#126)
Browse files Browse the repository at this point in the history
Signed-off-by: haoqing0110 <qhao@redhat.com>
  • Loading branch information
haoqing0110 authored Oct 18, 2024
1 parent 5b72e65 commit 3a749f8
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ func TestAddonConfigReconcile(t *testing.T) {
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
}}, nil, nil),
addontesting.NewAddon("test", "cluster2"),
// cluster3 already has configs synced to status before spec hash is updated
newManagedClusterAddon("test", "cluster3", []addonv1alpha1.AddOnConfig{{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
}}, []addonv1alpha1.ConfigReference{
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
SpecHash: "",
},
LastObservedGeneration: 0,
},
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "",
},
LastObservedGeneration: 0,
},
}, nil),
},
placements: []runtime.Object{
&clusterv1beta1.Placement{ObjectMeta: metav1.ObjectMeta{Name: "test-placement", Namespace: "default"}},
Expand All @@ -176,7 +200,7 @@ func TestAddonConfigReconcile(t *testing.T) {
},
},
Status: clusterv1beta1.PlacementDecisionStatus{
Decisions: []clusterv1beta1.ClusterDecision{{ClusterName: "cluster1"}, {ClusterName: "cluster2"}},
Decisions: []clusterv1beta1.ClusterDecision{{ClusterName: "cluster1"}, {ClusterName: "cluster2"}, {ClusterName: "cluster3"}},
},
},
},
Expand All @@ -187,7 +211,7 @@ func TestAddonConfigReconcile(t *testing.T) {
ConfigGroupResource: v1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
DesiredConfig: &v1alpha1.ConfigSpecHash{
ConfigReferent: v1alpha1.ConfigReferent{Name: "test"},
SpecHash: "hash",
SpecHash: "<core-foo-test-hash>",
},
}).WithPlacementStrategy(addonv1alpha1.PlacementStrategy{
PlacementRef: addonv1alpha1.PlacementRef{Name: "test-placement", Namespace: "default"},
Expand All @@ -199,32 +223,81 @@ func TestAddonConfigReconcile(t *testing.T) {
ConfigGroupResource: v1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
DesiredConfig: &v1alpha1.ConfigSpecHash{
ConfigReferent: v1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "hash1",
SpecHash: "<core-foo-test1-hash>",
},
},
{
ConfigGroupResource: v1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"},
DesiredConfig: &v1alpha1.ConfigSpecHash{
ConfigReferent: v1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "<core-bar-test1-hash>",
},
},
},
}).Build(),
validateAddonActions: func(t *testing.T, actions []clienttesting.Action) {
addontesting.AssertActions(t, actions, "patch", "patch")
addontesting.AssertActions(t, actions, "patch", "patch", "patch")
sort.Sort(byPatchName(actions))
expectPatchConfigurationAction(t, actions[0], []addonv1alpha1.ConfigReference{{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
SpecHash: "",
expectPatchConfigurationAction(t, actions[0], []addonv1alpha1.ConfigReference{
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
SpecHash: "",
},
LastObservedGeneration: 0,
},
LastObservedGeneration: 0,
}})
expectPatchConfigurationAction(t, actions[1], []addonv1alpha1.ConfigReference{{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "hash1",
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "<core-bar-test1-hash>",
},
LastObservedGeneration: 0,
},
LastObservedGeneration: 0,
}})
})
expectPatchConfigurationAction(t, actions[1], []addonv1alpha1.ConfigReference{
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "<core-foo-test1-hash>",
},
LastObservedGeneration: 0,
},
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "<core-bar-test1-hash>",
},
LastObservedGeneration: 0,
},
})
expectPatchConfigurationAction(t, actions[2], []addonv1alpha1.ConfigReference{
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test2"},
SpecHash: "",
},
LastObservedGeneration: 0,
},
{
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"},
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"},
SpecHash: "<core-bar-test1-hash>",
},
LastObservedGeneration: 0,
},
})
},
},
{
Expand Down
9 changes: 8 additions & 1 deletion pkg/addon/controllers/addonconfiguration/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,25 @@ func (n *installStrategyNode) addNode(addon *addonv1alpha1.ManagedClusterAddOn)
n.children[addon.Namespace].desiredConfigs = n.children[addon.Namespace].desiredConfigs.copy()
// TODO we should also filter out the configs which are not supported configs.
for _, config := range addon.Spec.Configs {
// go through mca spec configs update the desired configs
n.children[addon.Namespace].desiredConfigs[config.ConfigGroupResource] = addonv1alpha1.ConfigReference{
ConfigGroupResource: config.ConfigGroupResource,
ConfigReferent: config.ConfigReferent,
DesiredConfig: &addonv1alpha1.ConfigSpecHash{
ConfigReferent: config.ConfigReferent,
},
}
// copy the spechash from mca status

// go through mca spec configs and status, and copy the specHash if they match
for _, configRef := range addon.Status.ConfigReferences {
if configRef.DesiredConfig == nil {
continue
}
// compare the ConfigGroupResource and ConfigReferent
if configRef.ConfigGroupResource != config.ConfigGroupResource || configRef.DesiredConfig.ConfigReferent != config.ConfigReferent {
continue
}
// copy the spec hash to desired configs
nodeDesiredConfig, ok := n.children[addon.Namespace].desiredConfigs[configRef.ConfigGroupResource]
if ok && (nodeDesiredConfig.DesiredConfig.ConfigReferent == configRef.DesiredConfig.ConfigReferent) {
nodeDesiredConfig.DesiredConfig.SpecHash = configRef.DesiredConfig.SpecHash
Expand Down

0 comments on commit 3a749f8

Please sign in to comment.