From 215a74f0b2b4bc81c7e9cc5910b16d2e84e2ddb7 Mon Sep 17 00:00:00 2001 From: Urvashi Mohnani Date: Tue, 19 Feb 2019 14:06:41 -0500 Subject: [PATCH] Add extra filter for checking if registries have changed A resync happens about every 20 minutes, which sends an updated event to the image informer even if nothing in the image CR has changed. Adding and extra filter that checks if there has been any changes to the registries part of the image CR before syncing the image handler again. Signed-off-by: Urvashi Mohnani --- .../container_runtime_config_controller.go | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/controller/container-runtime-config/container_runtime_config_controller.go b/pkg/controller/container-runtime-config/container_runtime_config_controller.go index a2e20e75f4..170258e3dd 100644 --- a/pkg/controller/container-runtime-config/container_runtime_config_controller.go +++ b/pkg/controller/container-runtime-config/container_runtime_config_controller.go @@ -10,6 +10,7 @@ import ( "github.com/golang/glog" "github.com/vincent-petithory/dataurl" "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -536,15 +537,12 @@ func (ctrl *Controller) syncImageConfig(key string) error { return err } for _, pool := range mcpPools { + // To keep track of whether we "actually" got an updated image config + applied := true role := pool.Name // Get MachineConfig managedKey := getManagedKeyReg(pool, imgcfg) if err := retry.RetryOnConflict(updateBackoff, func() error { - mc, err := ctrl.client.Machineconfiguration().MachineConfigs().Get(managedKey, metav1.GetOptions{}) - if err != nil && !errors.IsNotFound(err) { - return fmt.Errorf("could not find MachineConfig: %v", err) - } - isNotFound := errors.IsNotFound(err) // Generate the original registries config _, _, originalRegistriesIgn, err := ctrl.generateOriginalContainerRuntimeConfigs(role) if err != nil { @@ -559,9 +557,19 @@ func (ctrl *Controller) syncImageConfig(key string) error { } registriesTOML, err = updateRegistriesConfig(dataURL.Data, imgcfg.Spec) if err != nil { - return fmt.Errorf("could not update container runtime config with new changes: %v", err) + return fmt.Errorf("could not update registries config with new changes: %v", err) } } + mc, err := ctrl.client.Machineconfiguration().MachineConfigs().Get(managedKey, metav1.GetOptions{}) + if err != nil && !errors.IsNotFound(err) { + return fmt.Errorf("could not find MachineConfig: %v", err) + } + isNotFound := errors.IsNotFound(err) + rci := createNewRegistriesConfigIgnition(registriesTOML) + if !isNotFound && equality.Semantic.DeepEqual(rci, mc.Spec.Config) { + applied = false + return nil + } if isNotFound { mc = mtmpl.MachineConfigFromIgnConfig(role, managedKey, &ignv2_2types.Config{}) } @@ -588,7 +596,9 @@ func (ctrl *Controller) syncImageConfig(key string) error { }); err != nil { return fmt.Errorf("could not Create/Update MachineConfig: %v", err) } - glog.Infof("Applied ImageConfig cluster on MachineConfigPool %v", pool.Name) + if applied { + glog.Infof("Applied ImageConfig cluster on MachineConfigPool %v", pool.Name) + } } return nil