diff --git a/go.mod b/go.mod index 1a99b2aac..e2bdc8029 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( k8s.io/klog/v2 v2.110.1 k8s.io/kube-aggregator v0.29.0 k8s.io/utils v0.0.0-20240102154912-e7106e64919e - open-cluster-management.io/addon-framework v0.8.1-0.20240102072130-44852ea0722f + open-cluster-management.io/addon-framework v0.8.1-0.20240119025526-d2afcef1ff66 open-cluster-management.io/api v0.12.1-0.20240115071352-3d94ce8f3499 open-cluster-management.io/sdk-go v0.0.0-20240117083639-69270b03020c sigs.k8s.io/controller-runtime v0.16.2 diff --git a/go.sum b/go.sum index 50bbc15a1..c20f27371 100644 --- a/go.sum +++ b/go.sum @@ -450,8 +450,8 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -open-cluster-management.io/addon-framework v0.8.1-0.20240102072130-44852ea0722f h1:R5IbFdM4g+kDyONZ1/q67/czRwgDkq9Q7ETZ3RhGaAg= -open-cluster-management.io/addon-framework v0.8.1-0.20240102072130-44852ea0722f/go.mod h1:aj97pgpGJ0/LpQzBVtU2oDFqqIiZLOPnsjLKG/sVkFw= +open-cluster-management.io/addon-framework v0.8.1-0.20240119025526-d2afcef1ff66 h1:d6vkhLLdam7/DLmZ4onPSbsRNHP3Rze0/0OkmjJgVjk= +open-cluster-management.io/addon-framework v0.8.1-0.20240119025526-d2afcef1ff66/go.mod h1:aj97pgpGJ0/LpQzBVtU2oDFqqIiZLOPnsjLKG/sVkFw= open-cluster-management.io/api v0.12.1-0.20240115071352-3d94ce8f3499 h1:Odh200i57Z9V44eJak98VqdKMCAlj3m9dtnUp8285nE= open-cluster-management.io/api v0.12.1-0.20240115071352-3d94ce8f3499/go.mod h1:K3Rza3qN/W1+E1a+wbLtFatvdI8UlQWkSqBlpeRHMPw= open-cluster-management.io/sdk-go v0.0.0-20240117083639-69270b03020c h1:0/Y9YSSLT6+D6kc3ZNiHKK53tsxJJyrfSo0U3NUfB2U= diff --git a/pkg/addon/templateagent/template_agent.go b/pkg/addon/templateagent/template_agent.go index e844aaf5e..1bbefcd30 100644 --- a/pkg/addon/templateagent/template_agent.go +++ b/pkg/addon/templateagent/template_agent.go @@ -110,6 +110,7 @@ func (a *CRDTemplateAgentAddon) GetAgentAddonOptions() agent.AgentAddonOptions { for gvr := range utils.BuiltInAddOnConfigGVRs { supportedConfigGVRs = append(supportedConfigGVRs, gvr) } + agentAddonOptions := agent.AgentAddonOptions{ AddonName: a.addonName, InstallStrategy: nil, @@ -125,7 +126,11 @@ func (a *CRDTemplateAgentAddon) GetAgentAddonOptions() agent.AgentAddonOptions { AgentInstallNamespace: utils.AgentInstallNamespaceFromDeploymentConfigFunc( utils.NewAddOnDeploymentConfigGetter(a.addonClient)), }, - AgentDeployTriggerClusterFilter: utils.ClusterImageRegistriesAnnotationChanged, + AgentDeployTriggerClusterFilter: func(old, new *clusterv1.ManagedCluster) bool { + return utils.ClusterImageRegistriesAnnotationChanged(old, new) || + // if the cluster changes from unknow to true, recheck the health of the addon immediately + utils.ClusterAvailableConditionChanged(old, new) + }, } template, err := a.GetDesiredAddOnTemplate(nil, "", a.addonName) diff --git a/vendor/modules.txt b/vendor/modules.txt index 37d4c9896..e00f2ef16 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1487,7 +1487,7 @@ k8s.io/utils/pointer k8s.io/utils/ptr k8s.io/utils/strings/slices k8s.io/utils/trace -# open-cluster-management.io/addon-framework v0.8.1-0.20240102072130-44852ea0722f +# open-cluster-management.io/addon-framework v0.8.1-0.20240119025526-d2afcef1ff66 ## explicit; go 1.20 open-cluster-management.io/addon-framework/pkg/addonfactory open-cluster-management.io/addon-framework/pkg/addonmanager diff --git a/vendor/open-cluster-management.io/addon-framework/pkg/utils/helpers.go b/vendor/open-cluster-management.io/addon-framework/pkg/utils/helpers.go index 2a4b8e273..611ee1669 100644 --- a/vendor/open-cluster-management.io/addon-framework/pkg/utils/helpers.go +++ b/vendor/open-cluster-management.io/addon-framework/pkg/utils/helpers.go @@ -386,8 +386,36 @@ func MapValueChanged(old, new map[string]string, key string) bool { // ClusterImageRegistriesAnnotationChanged returns true if the value of the ClusterImageRegistriesAnnotationKey // in the new managed cluster annotation is different from the old managed cluster annotation func ClusterImageRegistriesAnnotationChanged(old, new *clusterv1.ManagedCluster) bool { + return ClusterAnnotationChanged(old, new, clusterv1.ClusterImageRegistriesAnnotationKey) +} + +// ClusterAnnotationChanged returns true if the value of the specified annotation in the new managed cluster annotation +// is different from the old managed cluster annotation +func ClusterAnnotationChanged(old, new *clusterv1.ManagedCluster, annotation string) bool { if new == nil || old == nil { return false } - return MapValueChanged(old.Annotations, new.Annotations, clusterv1.ClusterImageRegistriesAnnotationKey) + return MapValueChanged(old.Annotations, new.Annotations, annotation) +} + +// ClusterAvailableConditionChanged returns true if the value of the Available condition in the new managed cluster +// is different from the old managed cluster +func ClusterAvailableConditionChanged(old, new *clusterv1.ManagedCluster) bool { + return ClusterConditionChanged(old, new, clusterv1.ManagedClusterConditionAvailable) +} + +// ClusterAvailableConditionChanged returns true if the value of the specified conditionType in the new managed cluster +// is different from the old managed cluster +func ClusterConditionChanged(old, new *clusterv1.ManagedCluster, conditionType string) bool { + if new == nil || old == nil { + return false + } + + oldAvailableCondition := meta.FindStatusCondition(old.Status.Conditions, conditionType) + newAvailableCondition := meta.FindStatusCondition(new.Status.Conditions, conditionType) + + return (oldAvailableCondition == nil && newAvailableCondition != nil) || + (oldAvailableCondition != nil && newAvailableCondition == nil) || + (oldAvailableCondition != nil && newAvailableCondition != nil && + oldAvailableCondition.Status != newAvailableCondition.Status) }