diff --git a/pkg/addon/controllers/addonconfiguration/addon_configuration_reconciler_test.go b/pkg/addon/controllers/addonconfiguration/addon_configuration_reconciler_test.go index d075e72a3..df0bf474a 100644 --- a/pkg/addon/controllers/addonconfiguration/addon_configuration_reconciler_test.go +++ b/pkg/addon/controllers/addonconfiguration/addon_configuration_reconciler_test.go @@ -312,6 +312,45 @@ func TestAddonConfigReconcile(t *testing.T) { }, }, 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"}, + }, + { + ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"}, + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test3"}, + }, + }, []addonv1alpha1.ConfigReference{ + { + ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"}, + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, + DesiredConfig: &addonv1alpha1.ConfigSpecHash{ + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, + SpecHash: "", + }, + LastObservedGeneration: 0, + }, + { + 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: "Foo"}, + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test3"}, + DesiredConfig: &addonv1alpha1.ConfigSpecHash{ + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test3"}, + SpecHash: "", + }, + LastObservedGeneration: 0, + }, + }, nil), }, placements: []runtime.Object{ &clusterv1beta1.Placement{ObjectMeta: metav1.ObjectMeta{Name: "test-placement", Namespace: "default"}}, @@ -327,7 +366,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"}}, }, }, }, @@ -343,7 +382,7 @@ func TestAddonConfigReconcile(t *testing.T) { ConfigGroupResource: v1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"}, DesiredConfig: &v1alpha1.ConfigSpecHash{ ConfigReferent: v1alpha1.ConfigReferent{Name: "test"}, - SpecHash: "hash", + SpecHash: "", }, }).WithPlacementStrategy(addonv1alpha1.PlacementStrategy{ PlacementRef: addonv1alpha1.PlacementRef{Name: "test-placement", Namespace: "default"}, @@ -355,20 +394,20 @@ func TestAddonConfigReconcile(t *testing.T) { ConfigGroupResource: v1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"}, DesiredConfig: &v1alpha1.ConfigSpecHash{ ConfigReferent: v1alpha1.ConfigReferent{Name: "test1"}, - SpecHash: "hash1", + SpecHash: "", }, }, { ConfigGroupResource: v1alpha1.ConfigGroupResource{Group: "core", Resource: "Foo"}, DesiredConfig: &v1alpha1.ConfigSpecHash{ ConfigReferent: v1alpha1.ConfigReferent{Name: "test1"}, - SpecHash: "hash1", + SpecHash: "", }, }, }, }).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{ { @@ -376,7 +415,7 @@ func TestAddonConfigReconcile(t *testing.T) { ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, DesiredConfig: &addonv1alpha1.ConfigSpecHash{ ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, - SpecHash: "hash1", + SpecHash: "", }, LastObservedGeneration: 0, }, @@ -405,7 +444,7 @@ func TestAddonConfigReconcile(t *testing.T) { ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, DesiredConfig: &addonv1alpha1.ConfigSpecHash{ ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, - SpecHash: "hash1", + SpecHash: "", }, LastObservedGeneration: 0, }, @@ -414,10 +453,39 @@ func TestAddonConfigReconcile(t *testing.T) { ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, DesiredConfig: &addonv1alpha1.ConfigSpecHash{ ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, - SpecHash: "hash1", + SpecHash: "", }, LastObservedGeneration: 0, }}) + expectPatchConfigurationAction(t, actions[2], []addonv1alpha1.ConfigReference{ + { + ConfigGroupResource: addonv1alpha1.ConfigGroupResource{Group: "core", Resource: "Bar"}, + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, + DesiredConfig: &addonv1alpha1.ConfigSpecHash{ + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test1"}, + SpecHash: "", + }, + LastObservedGeneration: 0, + }, + { + 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: "Foo"}, + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test3"}, + DesiredConfig: &addonv1alpha1.ConfigSpecHash{ + ConfigReferent: addonv1alpha1.ConfigReferent{Name: "test3"}, + SpecHash: "", + }, + LastObservedGeneration: 0, + }, + }) expectPatchConditionAction(t, actions[0], metav1.ConditionTrue) expectPatchConditionAction(t, actions[1], metav1.ConditionTrue) }, diff --git a/pkg/addon/controllers/addonconfiguration/graph.go b/pkg/addon/controllers/addonconfiguration/graph.go index 4344bc32b..c11dd4b54 100644 --- a/pkg/addon/controllers/addonconfiguration/graph.go +++ b/pkg/addon/controllers/addonconfiguration/graph.go @@ -369,12 +369,21 @@ func (n *installStrategyNode) addNode(addon *addonv1alpha1.ManagedClusterAddOn) // TODO we should also filter out the configs which are not supported configs. overrideConfigMapByAddOnConfigs(n.children[addon.Namespace].desiredConfigs, addon.Spec.Configs) - // copy the spechash from mca status - for _, configRef := range addon.Status.ConfigReferences { - if configRef.DesiredConfig == nil { - continue - } - if nodeDesiredConfigArray, ok := n.children[addon.Namespace].desiredConfigs[configRef.ConfigGroupResource]; ok { + // go through mca spec configs and copy the specHash from status if they match + for _, config := range addon.Spec.Configs { + 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 + nodeDesiredConfigArray, ok := n.children[addon.Namespace].desiredConfigs[configRef.ConfigGroupResource] + if !ok { + continue + } for i, nodeDesiredConfig := range nodeDesiredConfigArray { if nodeDesiredConfig.DesiredConfig.ConfigReferent == configRef.DesiredConfig.ConfigReferent { n.children[addon.Namespace].desiredConfigs[configRef.ConfigGroupResource][i].DesiredConfig.SpecHash = configRef.DesiredConfig.SpecHash