func()

in pkg/dns/config/sync.go [98:145]


func (sync *kubeSync) processUpdate(result syncResult, buildUnchangedConfig bool) (config *Config, changed bool, err error) {
	klog.V(4).Infof("processUpdate %+v", result)

	if result.Version != sync.latestVersion {
		klog.V(3).Infof("Updating config to version %v (was %v)",
			result.Version, sync.latestVersion)
		changed = true
		sync.latestVersion = result.Version
	} else {
		klog.V(4).Infof("Config was unchanged (version %v)", sync.latestVersion)
		// short-circuit if we haven't been asked to build an unchanged config object
		if !buildUnchangedConfig {
			return
		}
	}

	if result.Version == "" && len(result.Data) == 0 {
		config = NewDefaultConfig()
		return
	}

	config = &Config{}

	for key, updateFn := range map[string]fieldUpdateFn{
		"federations":         updateFederations,
		"stubDomains":         updateStubDomains,
		"upstreamNameservers": updateUpstreamNameservers,
	} {
		value, ok := result.Data[key]
		if !ok {
			klog.V(3).Infof("No %v present", key)
			continue
		}

		if err = updateFn(key, value, config); err != nil {
			klog.Errorf("Invalid configuration for %v, ignoring update: %v", key, err)
			return
		}
	}

	if err = config.Validate(); err != nil {
		klog.Errorf("Invalid configuration: %v (value was %+v), ignoring update", err, config)
		config = nil
		return
	}

	return
}