func (r *ConfigMapReconciler) reconcileNodes(ctx context.Context, instances *core.ConfigMap) error {
	// Get the list of instances that are expected to be Nodes
	hosts, err := r.parseHosts(instances.Data)
	if err != nil {
		return errors.Wrapf(err, "unable to parse hosts from configmap")
	}

	nodes := &core.NodeList{}
	if err := r.client.List(ctx, nodes); err != nil {
		return errors.Wrap(err, "error listing nodes")
	}

	// For each host, ensure that it is configured into a node. On error of any host joining, return error and requeue.
	// It is better to return early like this, instead of trying to configure as many nodes as possible in a single
	// reconcile call, as it simplifies error collection. The order the map is read from is psuedo-random, so the
	// configuration effort for configurable hosts will not be blocked by a specific host that has issues with
	// configuration.
	for _, host := range hosts {
		err := r.ensureInstanceIsConfigured(host, nodes)
		if err != nil {
			r.recorder.Eventf(instances, core.EventTypeWarning, "InstanceSetupFailure",
				"unable to join instance with address %s to the cluster", host.Address)
			return errors.Wrapf(err, "error configuring host with address %s", host.Address)
		}
	}

	// Ensure that only instances currently specified by the ConfigMap are joined to the cluster as nodes
	if err = r.deconfigureInstances(hosts, nodes); err != nil {
		return errors.Wrap(err, "error removing undesired nodes from cluster")
	}

	// Once all the proper Nodes are in the cluster, configure the prometheus endpoints.
	if err := r.prometheusNodeConfig.Configure(); err != nil {
		return errors.Wrap(err, "unable to configure Prometheus")
	}
	return nil
}
// reconcileNodes corrects the discrepancy between the "expected" hosts slice, and the "actual" nodelist
reconcileNodes corrects the discrepancy between the "expected" hosts slice, and the "actual" nodelist
// reconcileNodes corrects the discrepancy between the " expected " hosts slice and the " actual " nodelist
func (r *ConfigMapReconciler) reconcileNodes(ctx context.Context, instances *core.ConfigMap) error {
	hosts, err := r.parseHosts(instances.Data)
	if err != nil {
		return errors.Wrapf(err, "unable to parse hosts from configmap")
	}
	nodes := &core.NodeList{}
	if err := r.client.List(ctx, nodes); err != nil {
		return errors.Wrap(err, "error listing nodes")
	}
	for _, host := range hosts {
		err := r.ensureInstanceIsConfigured(host, nodes)
		if err != nil {
			r.recorder.Eventf(instances, core.EventTypeWarning, "InstanceSetupFailure",
				"unable to join instance with address %s to the cluster", host.Address)
			return errors.Wrapf(err, "error configuring host with address %s", host.Address)
		}
	}
	if err = r.deconfigureInstances(hosts, nodes); err != nil {
		return errors.Wrap(err, "error removing undesired nodes from cluster")
	}
	if err := r.prometheusNodeConfig.Configure(); err != nil {
		return errors.Wrap(err, "unable to configure Prometheus")
	}
	return nil
}
func ( r * ConfigMapReconciler ) reconcileNodes ( ctx context . Context , instances * core . ConfigMap ) error { hosts , err := r . parseHosts ( instances . Data ) if err != nil { return errors . Wrapf ( err , " " ) } nodes := & core . NodeList { } if err := r . client . List ( ctx , nodes ) ; err != nil { return errors . Wrap ( err , " " ) } for _ , host := range hosts { err := r . ensureInstanceIsConfigured ( host , nodes ) if err != nil { r . recorder . Eventf ( instances , core . EventTypeWarning , " " , " " , host . Address ) return errors . Wrapf ( err , " " , host . Address ) } } if err = r . deconfigureInstances ( hosts , nodes ) ; err != nil { return errors . Wrap ( err , " " ) } if err := r . prometheusNodeConfig . Configure ( ) ; err != nil { return errors . Wrap ( err , " " ) } return nil }
reconcileNodes corrects the discrepancy between the "expected" hosts slice, and the "actual" nodelist
reconcileNodes corrects the discrepancy between the " expected " hosts slice and the " actual " nodelist
// Get the list of instances that are expected to be Nodes // For each host, ensure that it is configured into a node. On error of any host joining, return error and requeue. // It is better to return early like this, instead of trying to configure as many nodes as possible in a single // reconcile call, as it simplifies error collection. The order the map is read from is psuedo-random, so the // configuration effort for configurable hosts will not be blocked by a specific host that has issues with // configuration. // Ensure that only instances currently specified by the ConfigMap are joined to the cluster as nodes // Once all the proper Nodes are in the cluster, configure the prometheus endpoints.