extend inherited annotations unit test to include logical backup cron job (#2723)
* extend inherited annotations test to logical backup cron job * sync on updated when enabled, not only on schedule changes
This commit is contained in:
		
							parent
							
								
									a87307e56b
								
							
						
					
					
						commit
						31f92a1aa0
					
				|  | @ -1067,11 +1067,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error { | ||||||
| 
 | 
 | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// apply schedule changes
 | 		if oldSpec.Spec.EnableLogicalBackup && newSpec.Spec.EnableLogicalBackup { | ||||||
| 		// this is the only parameter of logical backups a user can overwrite in the cluster manifest
 |  | ||||||
| 		if (oldSpec.Spec.EnableLogicalBackup && newSpec.Spec.EnableLogicalBackup) && |  | ||||||
| 			(newSpec.Spec.LogicalBackupSchedule != oldSpec.Spec.LogicalBackupSchedule) { |  | ||||||
| 			c.logger.Debugf("updating schedule of the backup cron job") |  | ||||||
| 			if err := c.syncLogicalBackupJob(); err != nil { | 			if err := c.syncLogicalBackupJob(); err != nil { | ||||||
| 				c.logger.Errorf("could not sync logical backup jobs: %v", err) | 				c.logger.Errorf("could not sync logical backup jobs: %v", err) | ||||||
| 				updateFailed = true | 				updateFailed = true | ||||||
|  |  | ||||||
|  | @ -51,6 +51,7 @@ func newFakeK8sAnnotationsClient() (k8sutil.KubernetesClient, *k8sFake.Clientset | ||||||
| 		EndpointsGetter:              clientSet.CoreV1(), | 		EndpointsGetter:              clientSet.CoreV1(), | ||||||
| 		PodsGetter:                   clientSet.CoreV1(), | 		PodsGetter:                   clientSet.CoreV1(), | ||||||
| 		DeploymentsGetter:            clientSet.AppsV1(), | 		DeploymentsGetter:            clientSet.AppsV1(), | ||||||
|  | 		CronJobsGetter:               clientSet.BatchV1(), | ||||||
| 	}, clientSet | 	}, clientSet | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -176,6 +177,22 @@ func checkResourcesInheritedAnnotations(cluster *Cluster, resultAnnotations map[ | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	checkCronJob := func(annotations map[string]string) error { | ||||||
|  | 		cronJobList, err := cluster.KubeClient.CronJobs(namespace).List(context.TODO(), clusterOptions) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 		for _, cronJob := range cronJobList.Items { | ||||||
|  | 			if err := containsAnnotations(updateAnnotations(annotations), cronJob.Annotations, cronJob.ObjectMeta.Name, "Logical backup cron job"); err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 			if err := containsAnnotations(updateAnnotations(annotations), cronJob.Spec.JobTemplate.Spec.Template.Annotations, cronJob.Name, "Logical backup cron job pod template"); err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	checkSecrets := func(annotations map[string]string) error { | 	checkSecrets := func(annotations map[string]string) error { | ||||||
| 		secretList, err := cluster.KubeClient.Secrets(namespace).List(context.TODO(), clusterOptions) | 		secretList, err := cluster.KubeClient.Secrets(namespace).List(context.TODO(), clusterOptions) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
|  | @ -203,7 +220,7 @@ func checkResourcesInheritedAnnotations(cluster *Cluster, resultAnnotations map[ | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	checkFuncs := []func(map[string]string) error{ | 	checkFuncs := []func(map[string]string) error{ | ||||||
| 		checkSts, checkPods, checkSvc, checkPdb, checkPooler, checkPvc, checkSecrets, checkEndpoints, | 		checkSts, checkPods, checkSvc, checkPdb, checkPooler, checkCronJob, checkPvc, checkSecrets, checkEndpoints, | ||||||
| 	} | 	} | ||||||
| 	for _, f := range checkFuncs { | 	for _, f := range checkFuncs { | ||||||
| 		if err := f(resultAnnotations); err != nil { | 		if err := f(resultAnnotations); err != nil { | ||||||
|  | @ -251,6 +268,7 @@ func newInheritedAnnotationsCluster(client k8sutil.KubernetesClient) (*Cluster, | ||||||
| 		Spec: acidv1.PostgresSpec{ | 		Spec: acidv1.PostgresSpec{ | ||||||
| 			EnableConnectionPooler:        boolToPointer(true), | 			EnableConnectionPooler:        boolToPointer(true), | ||||||
| 			EnableReplicaConnectionPooler: boolToPointer(true), | 			EnableReplicaConnectionPooler: boolToPointer(true), | ||||||
|  | 			EnableLogicalBackup:           true, | ||||||
| 			Volume: acidv1.Volume{ | 			Volume: acidv1.Volume{ | ||||||
| 				Size: "1Gi", | 				Size: "1Gi", | ||||||
| 			}, | 			}, | ||||||
|  | @ -306,6 +324,10 @@ func newInheritedAnnotationsCluster(client k8sutil.KubernetesClient) (*Cluster, | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  | 	err = cluster.createLogicalBackupJob() | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
| 	pvcList := CreatePVCs(namespace, clusterName, cluster.labelsSet(false), 2, "1Gi") | 	pvcList := CreatePVCs(namespace, clusterName, cluster.labelsSet(false), 2, "1Gi") | ||||||
| 	for _, pvc := range pvcList.Items { | 	for _, pvc := range pvcList.Items { | ||||||
| 		_, err = cluster.KubeClient.PersistentVolumeClaims(namespace).Create(context.TODO(), &pvc, metav1.CreateOptions{}) | 		_, err = cluster.KubeClient.PersistentVolumeClaims(namespace).Create(context.TODO(), &pvc, metav1.CreateOptions{}) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue