revert sync configmaps
This commit is contained in:
		
							parent
							
								
									22b6abcf95
								
							
						
					
					
						commit
						b40188f0df
					
				|  | @ -1499,12 +1499,9 @@ func (c *Cluster) GetStatus() *ClusterStatus { | ||||||
| 		Error: fmt.Errorf("error: %s", c.Error), | 		Error: fmt.Errorf("error: %s", c.Error), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if c.patroniKubernetesUseConfigMaps() { | 	if !c.patroniKubernetesUseConfigMaps() { | ||||||
| 		status.MasterEndpoint = c.GetEndpointMaster() | 		status.MasterEndpoint = c.GetEndpointMaster() | ||||||
| 		status.ReplicaEndpoint = c.GetEndpointReplica() | 		status.ReplicaEndpoint = c.GetEndpointReplica() | ||||||
| 	} else { |  | ||||||
| 		status.MasterConfigMap = c.GetConfigMapMaster() |  | ||||||
| 		status.ReplicaConfigMap = c.GetConfigMapReplica() |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return status | 	return status | ||||||
|  |  | ||||||
|  | @ -76,11 +76,8 @@ func (c *Cluster) statefulSetName() string { | ||||||
| 	return c.Name | 	return c.Name | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) configMapName(role PostgresRole) string { | func (c *Cluster) endpointName(role PostgresRole) string { | ||||||
| 	name := c.Name | 	name := c.Name | ||||||
| 	if role == Master { |  | ||||||
| 		name = name + "-leader" |  | ||||||
| 	} |  | ||||||
| 	if role == Replica { | 	if role == Replica { | ||||||
| 		name = name + "-repl" | 		name = name + "-repl" | ||||||
| 	} | 	} | ||||||
|  | @ -88,10 +85,6 @@ func (c *Cluster) configMapName(role PostgresRole) string { | ||||||
| 	return name | 	return name | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) endpointName(role PostgresRole) string { |  | ||||||
| 	return c.serviceName(role) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (c *Cluster) serviceName(role PostgresRole) string { | func (c *Cluster) serviceName(role PostgresRole) string { | ||||||
| 	name := c.Name | 	name := c.Name | ||||||
| 	if role == Replica { | 	if role == Replica { | ||||||
|  | @ -1828,16 +1821,6 @@ func (c *Cluster) generateEndpoint(role PostgresRole, subsets []v1.EndpointSubse | ||||||
| 	return endpoints | 	return endpoints | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) generateConfigMap(role PostgresRole) *v1.ConfigMap { |  | ||||||
| 	return &v1.ConfigMap{ |  | ||||||
| 		ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 			Name:      c.configMapName(role), |  | ||||||
| 			Namespace: c.Namespace, |  | ||||||
| 			Labels:    c.roleLabelsSet(true, role), |  | ||||||
| 		}, |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (c *Cluster) generateCloneEnvironment(description *acidv1.CloneDescription) []v1.EnvVar { | func (c *Cluster) generateCloneEnvironment(description *acidv1.CloneDescription) []v1.EnvVar { | ||||||
| 	result := make([]v1.EnvVar, 0) | 	result := make([]v1.EnvVar, 0) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -35,11 +35,7 @@ func (c *Cluster) listResources() error { | ||||||
| 		c.logger.Infof("found secret: %q (uid: %q) namesapce: %s", util.NameFromMeta(obj.ObjectMeta), obj.UID, obj.ObjectMeta.Namespace) | 		c.logger.Infof("found secret: %q (uid: %q) namesapce: %s", util.NameFromMeta(obj.ObjectMeta), obj.UID, obj.ObjectMeta.Namespace) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if c.patroniKubernetesUseConfigMaps() { | 	if !c.patroniKubernetesUseConfigMaps() { | ||||||
| 		for role, configMap := range c.ConfigMaps { |  | ||||||
| 			c.logger.Infof("found %s config map: %q (uid: %q)", role, util.NameFromMeta(configMap.ObjectMeta), configMap.UID) |  | ||||||
| 		} |  | ||||||
| 	} else { |  | ||||||
| 		for role, endpoint := range c.Endpoints { | 		for role, endpoint := range c.Endpoints { | ||||||
| 			c.logger.Infof("found %s endpoint: %q (uid: %q)", role, util.NameFromMeta(endpoint.ObjectMeta), endpoint.UID) | 			c.logger.Infof("found %s endpoint: %q (uid: %q)", role, util.NameFromMeta(endpoint.ObjectMeta), endpoint.UID) | ||||||
| 		} | 		} | ||||||
|  | @ -408,20 +404,6 @@ func (c *Cluster) generateEndpointSubsets(role PostgresRole) []v1.EndpointSubset | ||||||
| 	return result | 	return result | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) createConfigMap(role PostgresRole) (*v1.ConfigMap, error) { |  | ||||||
| 	c.setProcessName("creating config map") |  | ||||||
| 	configMapSpec := c.generateConfigMap(role) |  | ||||||
| 
 |  | ||||||
| 	configMap, err := c.KubeClient.ConfigMaps(configMapSpec.Namespace).Create(context.TODO(), configMapSpec, metav1.CreateOptions{}) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return nil, fmt.Errorf("could not create %s config map: %v", role, err) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	c.ConfigMaps[role] = configMap |  | ||||||
| 
 |  | ||||||
| 	return configMap, nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (c *Cluster) createPodDisruptionBudget() (*policybeta1.PodDisruptionBudget, error) { | func (c *Cluster) createPodDisruptionBudget() (*policybeta1.PodDisruptionBudget, error) { | ||||||
| 	podDisruptionBudgetSpec := c.generatePodDisruptionBudget() | 	podDisruptionBudgetSpec := c.generatePodDisruptionBudget() | ||||||
| 	podDisruptionBudget, err := c.KubeClient. | 	podDisruptionBudget, err := c.KubeClient. | ||||||
|  | @ -614,16 +596,6 @@ func (c *Cluster) GetEndpointReplica() *v1.Endpoints { | ||||||
| 	return c.Endpoints[Replica] | 	return c.Endpoints[Replica] | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // GetConfigMapMaster returns cluster's kubernetes master ConfigMap
 |  | ||||||
| func (c *Cluster) GetConfigMapMaster() *v1.ConfigMap { |  | ||||||
| 	return c.ConfigMaps[Master] |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // GetConfigMapReplica returns cluster's kubernetes replica ConfigMap
 |  | ||||||
| func (c *Cluster) GetConfigMapReplica() *v1.ConfigMap { |  | ||||||
| 	return c.ConfigMaps[Replica] |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // GetStatefulSet returns cluster's kubernetes StatefulSet
 | // GetStatefulSet returns cluster's kubernetes StatefulSet
 | ||||||
| func (c *Cluster) GetStatefulSet() *appsv1.StatefulSet { | func (c *Cluster) GetStatefulSet() *appsv1.StatefulSet { | ||||||
| 	return c.Statefulset | 	return c.Statefulset | ||||||
|  |  | ||||||
|  | @ -144,11 +144,7 @@ func (c *Cluster) syncServices() error { | ||||||
| 	for _, role := range []PostgresRole{Master, Replica} { | 	for _, role := range []PostgresRole{Master, Replica} { | ||||||
| 		c.logger.Debugf("syncing %s service", role) | 		c.logger.Debugf("syncing %s service", role) | ||||||
| 
 | 
 | ||||||
| 		if c.patroniKubernetesUseConfigMaps() { | 		if !c.patroniKubernetesUseConfigMaps() { | ||||||
| 			if err := c.syncConfigMap(role); err != nil { |  | ||||||
| 				return fmt.Errorf("could not sync %s config map: %v", role, err) |  | ||||||
| 			} |  | ||||||
| 		} else { |  | ||||||
| 			if err := c.syncEndpoint(role); err != nil { | 			if err := c.syncEndpoint(role); err != nil { | ||||||
| 				return fmt.Errorf("could not sync %s endpoint: %v", role, err) | 				return fmt.Errorf("could not sync %s endpoint: %v", role, err) | ||||||
| 			} | 			} | ||||||
|  | @ -238,40 +234,6 @@ func (c *Cluster) syncEndpoint(role PostgresRole) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) syncConfigMap(role PostgresRole) error { |  | ||||||
| 	var ( |  | ||||||
| 		cm  *v1.ConfigMap |  | ||||||
| 		err error |  | ||||||
| 	) |  | ||||||
| 	c.setProcessName("syncing %s config map", role) |  | ||||||
| 
 |  | ||||||
| 	if cm, err = c.KubeClient.ConfigMaps(c.Namespace).Get(context.TODO(), c.configMapName(role), metav1.GetOptions{}); err == nil { |  | ||||||
| 		// TODO: No syncing of config map here, is this covered completely by updateService?
 |  | ||||||
| 		c.ConfigMaps[role] = cm |  | ||||||
| 		return nil |  | ||||||
| 	} |  | ||||||
| 	if !k8sutil.ResourceNotFound(err) { |  | ||||||
| 		return fmt.Errorf("could not get %s config map: %v", role, err) |  | ||||||
| 	} |  | ||||||
| 	// no existing config map, create new one
 |  | ||||||
| 	c.ConfigMaps[role] = nil |  | ||||||
| 	c.logger.Infof("could not find the cluster's %s config map", role) |  | ||||||
| 
 |  | ||||||
| 	if cm, err = c.createConfigMap(role); err == nil { |  | ||||||
| 		c.logger.Infof("created missing %s config map %q", role, util.NameFromMeta(cm.ObjectMeta)) |  | ||||||
| 	} else { |  | ||||||
| 		if !k8sutil.ResourceAlreadyExists(err) { |  | ||||||
| 			return fmt.Errorf("could not create missing %s config map: %v", role, err) |  | ||||||
| 		} |  | ||||||
| 		c.logger.Infof("%s config map %q already exists", role, util.NameFromMeta(cm.ObjectMeta)) |  | ||||||
| 		if cm, err = c.KubeClient.ConfigMaps(c.Namespace).Get(context.TODO(), c.configMapName(role), metav1.GetOptions{}); err != nil { |  | ||||||
| 			return fmt.Errorf("could not fetch existing %s config map: %v", role, err) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	c.ConfigMaps[role] = cm |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (c *Cluster) syncPodDisruptionBudget(isUpdate bool) error { | func (c *Cluster) syncPodDisruptionBudget(isUpdate bool) error { | ||||||
| 	var ( | 	var ( | ||||||
| 		pdb *policybeta1.PodDisruptionBudget | 		pdb *policybeta1.PodDisruptionBudget | ||||||
|  |  | ||||||
|  | @ -63,8 +63,6 @@ type ClusterStatus struct { | ||||||
| 	ReplicaService      *v1.Service | 	ReplicaService      *v1.Service | ||||||
| 	MasterEndpoint      *v1.Endpoints | 	MasterEndpoint      *v1.Endpoints | ||||||
| 	ReplicaEndpoint     *v1.Endpoints | 	ReplicaEndpoint     *v1.Endpoints | ||||||
| 	MasterConfigMap     *v1.ConfigMap |  | ||||||
| 	ReplicaConfigMap    *v1.ConfigMap |  | ||||||
| 	StatefulSet         *appsv1.StatefulSet | 	StatefulSet         *appsv1.StatefulSet | ||||||
| 	PodDisruptionBudget *policybeta1.PodDisruptionBudget | 	PodDisruptionBudget *policybeta1.PodDisruptionBudget | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue