Define sidecars in the operator configuration.
Right now only the name and the docker image can be defined, but with the help of the pod_environment_configmap parameter arbitrary environment variables can be passed to the sidecars.
This commit is contained in:
		
							parent
							
								
									2a32eb4129
								
							
						
					
					
						commit
						1e4f046797
					
				|  | @ -15,6 +15,11 @@ words. | |||
|   your own Spilo image from the [github | ||||
|   repository](https://github.com/zalando/spilo). | ||||
| 
 | ||||
| * **sidecars** | ||||
|   a map of sidecar names to docker images for the containers to run alongside | ||||
|   Spilo. In case of the name conflict with the definition in the cluster | ||||
|   manifest the cluster-specific one is preferred. | ||||
| 
 | ||||
| * **workers** | ||||
|   number of working routines the operator spawns to process requests to | ||||
|   create/update/delete/sync clusters concurrently. The default is `4`. | ||||
|  |  | |||
|  | @ -318,7 +318,7 @@ func (c *Cluster) generatePodTemplate( | |||
| 	patroniParameters *spec.Patroni, | ||||
| 	cloneDescription *spec.CloneDescription, | ||||
| 	dockerImage *string, | ||||
| 	sidecars *[]spec.Sidecar, | ||||
| 	sidecars []spec.Sidecar, | ||||
| 	customPodEnvVars map[string]string, | ||||
| ) (*v1.PodTemplateSpec, error) { | ||||
| 	spiloConfiguration := c.generateSpiloJSONConfiguration(pgParameters, patroniParameters) | ||||
|  | @ -526,8 +526,8 @@ func (c *Cluster) generatePodTemplate( | |||
| 		) | ||||
| 	} | ||||
| 
 | ||||
| 	if sidecars != nil && len(*sidecars) > 0 { | ||||
| 		for index, sidecar := range *sidecars { | ||||
| 	if sidecars != nil && len(sidecars) > 0 { | ||||
| 		for index, sidecar := range sidecars { | ||||
| 			sc, err := c.getSidecarContainer(sidecar, index, volumeMounts) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
|  | @ -659,7 +659,10 @@ func (c *Cluster) generateStatefulSet(spec *spec.PostgresSpec) (*v1beta1.Statefu | |||
| 			customPodEnvVars = cm.Data | ||||
| 		} | ||||
| 	} | ||||
| 	podTemplate, err := c.generatePodTemplate(c.Postgresql.GetUID(), resourceRequirements, resourceRequirementsScalyrSidecar, &spec.Tolerations, &spec.PostgresqlParam, &spec.Patroni, &spec.Clone, &spec.DockerImage, &spec.Sidecars, customPodEnvVars) | ||||
| 
 | ||||
| 	mergedSidecars := c.mergeSidecars(spec.Sidecars) | ||||
| 
 | ||||
| 	podTemplate, err := c.generatePodTemplate(c.Postgresql.GetUID(), resourceRequirements, resourceRequirementsScalyrSidecar, &spec.Tolerations, &spec.PostgresqlParam, &spec.Patroni, &spec.Clone, &spec.DockerImage, mergedSidecars, customPodEnvVars) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("could not generate pod template: %v", err) | ||||
| 	} | ||||
|  | @ -689,6 +692,31 @@ func (c *Cluster) generateStatefulSet(spec *spec.PostgresSpec) (*v1beta1.Statefu | |||
| 	return statefulSet, nil | ||||
| } | ||||
| 
 | ||||
| // mergeSidecar merges globally-defined sidecars with those defined in the cluster manifest
 | ||||
| func (c *Cluster) mergeSidecars(sidecars []spec.Sidecar) []spec.Sidecar { | ||||
| 	globalSidecarsToSkip := map[string]bool{} | ||||
| 	result := make([]spec.Sidecar, 0) | ||||
| 
 | ||||
| 	for i, sidecar := range sidecars { | ||||
| 		dockerImage, ok := c.OpConfig.Sidecars[sidecar.Name] | ||||
| 		if ok { | ||||
| 			if dockerImage != sidecar.DockerImage { | ||||
| 				c.logger.Warningf("merging definitions for sidecar %q: "+ | ||||
| 					"ignoring %q in the global scope in favor of %q defined in the cluster", | ||||
| 					sidecar.Name, dockerImage, sidecar.DockerImage) | ||||
| 			} | ||||
| 			globalSidecarsToSkip[sidecar.Name] = true | ||||
| 		} | ||||
| 		result = append(result, sidecars[i]) | ||||
| 	} | ||||
| 	for name, dockerImage := range c.OpConfig.Sidecars { | ||||
| 		if !globalSidecarsToSkip[name] { | ||||
| 			result = append(result, spec.Sidecar{Name: name, DockerImage: dockerImage}) | ||||
| 		} | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
| 
 | ||||
| func (c *Cluster) getNumberOfInstances(spec *spec.PostgresSpec) (newcur int32) { | ||||
| 	min := c.OpConfig.MinInstances | ||||
| 	max := c.OpConfig.MaxInstances | ||||
|  |  | |||
|  | @ -68,9 +68,10 @@ type Config struct { | |||
| 	Auth | ||||
| 	Scalyr | ||||
| 
 | ||||
| 	WatchedNamespace string `name:"watched_namespace"`    // special values: "*" means 'watch all namespaces', the empty string "" means 'watch a namespace where operator is deployed to'
 | ||||
| 	EtcdHost         string `name:"etcd_host" default:""` // special values: the empty string "" means Patroni will use k8s as a DCS
 | ||||
| 	DockerImage      string `name:"docker_image" default:"registry.opensource.zalan.do/acid/spilo-cdp-10:1.4-p8"` | ||||
| 	WatchedNamespace string            `name:"watched_namespace"`    // special values: "*" means 'watch all namespaces', the empty string "" means 'watch a namespace where operator is deployed to'
 | ||||
| 	EtcdHost         string            `name:"etcd_host" default:""` // special values: the empty string "" means Patroni will use k8s as a DCS
 | ||||
| 	DockerImage      string            `name:"docker_image" default:"registry.opensource.zalan.do/acid/spilo-cdp-10:1.4-p8"` | ||||
| 	Sidecars         map[string]string `name:"sidecars"` | ||||
| 	// default name `operator` enables backward compatibility with the older ServiceAccountName field
 | ||||
| 	PodServiceAccountName string `name:"pod_service_account_name" default:"operator"` | ||||
| 	// value of this string must be valid JSON or YAML; see initPodServiceAccount
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue