Fix tests
This commit is contained in:
		
							parent
							
								
									f9c10b3d00
								
							
						
					
					
						commit
						332db3bbda
					
				|  | @ -3,6 +3,7 @@ package cluster | |||
| import ( | ||||
| 	"reflect" | ||||
| 
 | ||||
| 	u "github.com/zalando-incubator/postgres-operator/pkg/util" | ||||
| 	"k8s.io/client-go/pkg/api/v1" | ||||
| 	"k8s.io/client-go/pkg/apis/apps/v1beta1" | ||||
| ) | ||||
|  | @ -19,11 +20,6 @@ type ResourceCheck struct { | |||
| 	reason               string | ||||
| } | ||||
| 
 | ||||
| func True() *bool { | ||||
| 	b := true | ||||
| 	return &b | ||||
| } | ||||
| 
 | ||||
| type Result struct { | ||||
| 	needUpdate      *bool | ||||
| 	needsRollUpdate *bool | ||||
|  | @ -60,51 +56,51 @@ func (c *Cluster) getStatefulSetChecks() []ResourceCheck { | |||
| 	return []ResourceCheck{ | ||||
| 		c.NewCheck("new statefulset's number of replicas doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { return a.Spec.Replicas != b.Spec.Replicas }, | ||||
| 			Result{needUpdate: True()}), | ||||
| 			Result{needUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's annotations doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { return !reflect.DeepEqual(a.Annotations, b.Annotations) }, | ||||
| 			Result{needUpdate: True()}), | ||||
| 			Result{needUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's serviceAccountName service asccount name doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return len(a.Spec.Template.Spec.Containers) != len(b.Spec.Template.Spec.Containers) | ||||
| 			}, Result{needsRollUpdate: True()}), | ||||
| 			}, Result{needsRollUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's serviceAccountName service asccount name doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return a.Spec.Template.Spec.ServiceAccountName != | ||||
| 					b.Spec.Template.Spec.ServiceAccountName | ||||
| 			}, Result{needsRollUpdate: True(), needsReplace: True()}), | ||||
| 			}, Result{needsRollUpdate: u.True(), needsReplace: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's terminationGracePeriodSeconds  doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return a.Spec.Template.Spec.TerminationGracePeriodSeconds != | ||||
| 					b.Spec.Template.Spec.TerminationGracePeriodSeconds | ||||
| 			}, Result{needsRollUpdate: True(), needsReplace: True()}), | ||||
| 			}, Result{needsRollUpdate: u.True(), needsReplace: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's pod affinity doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return !reflect.DeepEqual(a.Spec.Template.Spec.Affinity, | ||||
| 					b.Spec.Template.Spec.Affinity) | ||||
| 			}, Result{needsRollUpdate: True(), needsReplace: True()}), | ||||
| 			}, Result{needsRollUpdate: u.True(), needsReplace: u.True()}), | ||||
| 
 | ||||
| 		// Some generated fields like creationTimestamp make it not possible to
 | ||||
| 		// use DeepCompare on Spec.Template.ObjectMeta
 | ||||
| 		c.NewCheck("new statefulset's metadata labels doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return !reflect.DeepEqual(a.Spec.Template.Labels, b.Spec.Template.Labels) | ||||
| 			}, Result{needsRollUpdate: True(), needsReplace: True()}), | ||||
| 			}, Result{needsRollUpdate: u.True(), needsReplace: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's pod template metadata annotations doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return !reflect.DeepEqual(a.Spec.Template.Annotations, b.Spec.Template.Annotations) | ||||
| 			}, Result{needUpdate: True(), needsRollUpdate: True(), needsReplace: True()}), | ||||
| 			}, Result{needUpdate: u.True(), needsRollUpdate: u.True(), needsReplace: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's volumeClaimTemplates contains different number of volumes to the old one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return len(a.Spec.VolumeClaimTemplates) != len(b.Spec.VolumeClaimTemplates) | ||||
| 			}, Result{needsReplace: True()}), | ||||
| 			}, Result{needsReplace: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's selector doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
|  | @ -112,7 +108,7 @@ func (c *Cluster) getStatefulSetChecks() []ResourceCheck { | |||
| 					return false | ||||
| 				} | ||||
| 				return !reflect.DeepEqual(a.Spec.Selector.MatchLabels, b.Spec.Selector.MatchLabels) | ||||
| 			}, Result{needsReplace: True()}), | ||||
| 			}, Result{needsReplace: u.True()}), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -120,27 +116,27 @@ func (c *Cluster) getContainerChecks() []ResourceCheck { | |||
| 	return []ResourceCheck{ | ||||
| 		c.NewCheck("new statefulset's container %d name doesn't match the current one", | ||||
| 			func(a, b *v1.Container) bool { return a.Name != b.Name }, | ||||
| 			Result{needsRollUpdate: True()}), | ||||
| 			Result{needsRollUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's container %d image doesn't match the current one", | ||||
| 			func(a, b *v1.Container) bool { return a.Image != b.Image }, | ||||
| 			Result{needsRollUpdate: True()}), | ||||
| 			Result{needsRollUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's container %d ports don't match the current one", | ||||
| 			func(a, b *v1.Container) bool { return !reflect.DeepEqual(a.Ports, b.Ports) }, | ||||
| 			Result{needsRollUpdate: True()}), | ||||
| 			Result{needsRollUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's container %d resources don't match the current ones", | ||||
| 			func(a, b *v1.Container) bool { return !compareResources(&a.Resources, &b.Resources) }, | ||||
| 			Result{needsRollUpdate: True()}), | ||||
| 			Result{needsRollUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's container %d environment doesn't match the current one", | ||||
| 			func(a, b *v1.Container) bool { return !reflect.DeepEqual(a.Env, b.Env) }, | ||||
| 			Result{needsRollUpdate: True()}), | ||||
| 			Result{needsRollUpdate: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's container %d environment sources don't match the current one", | ||||
| 			func(a, b *v1.Container) bool { return !reflect.DeepEqual(a.EnvFrom, b.EnvFrom) }, | ||||
| 			Result{needsRollUpdate: True()}), | ||||
| 			Result{needsRollUpdate: u.True()}), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -148,16 +144,16 @@ func (c *Cluster) getVolumeClaimChecks() []ResourceCheck { | |||
| 	return []ResourceCheck{ | ||||
| 		c.NewCheck("new statefulset's name for volume %d doesn't match the current one", | ||||
| 			func(a, b *v1.PersistentVolumeClaim) bool { return a.Name != b.Name }, | ||||
| 			Result{needsReplace: True()}), | ||||
| 			Result{needsReplace: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's annotations for volume %q doesn't match the current one", | ||||
| 			func(a, b *v1.PersistentVolumeClaim) bool { | ||||
| 				return !reflect.DeepEqual(a.Annotations, b.Annotations) | ||||
| 			}, | ||||
| 			Result{needsReplace: True()}), | ||||
| 			Result{needsReplace: u.True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's volumeClaimTemplates specification for volume %q doesn't match the current one", | ||||
| 			func(a, b *v1.PersistentVolumeClaim) bool { return !reflect.DeepEqual(a.Spec, b.Spec) }, | ||||
| 			Result{needsRollUpdate: True()}), | ||||
| 			Result{needsRollUpdate: u.True()}), | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,21 +2,12 @@ package cluster | |||
| 
 | ||||
| import ( | ||||
| 	"github.com/zalando-incubator/postgres-operator/pkg/spec" | ||||
| 	u "github.com/zalando-incubator/postgres-operator/pkg/util" | ||||
| 	"github.com/zalando-incubator/postgres-operator/pkg/util/config" | ||||
| 	"github.com/zalando-incubator/postgres-operator/pkg/util/k8sutil" | ||||
| 	"testing" | ||||
| ) | ||||
| 
 | ||||
| func True() *bool { | ||||
| 	b := true | ||||
| 	return &b | ||||
| } | ||||
| 
 | ||||
| func False() *bool { | ||||
| 	b := false | ||||
| 	return &b | ||||
| } | ||||
| 
 | ||||
| func TestCreateLoadBalancerLogic(t *testing.T) { | ||||
| 	var cluster = New( | ||||
| 		Config{ | ||||
|  | @ -40,14 +31,14 @@ func TestCreateLoadBalancerLogic(t *testing.T) { | |||
| 		{ | ||||
| 			subtest:  "new format, load balancer is enabled for replica", | ||||
| 			role:     Replica, | ||||
| 			spec:     &spec.PostgresSpec{EnableReplicaLoadBalancer: True()}, | ||||
| 			spec:     &spec.PostgresSpec{EnableReplicaLoadBalancer: u.True()}, | ||||
| 			opConfig: config.Config{}, | ||||
| 			result:   true, | ||||
| 		}, | ||||
| 		{ | ||||
| 			subtest:  "new format, load balancer is disabled for replica", | ||||
| 			role:     Replica, | ||||
| 			spec:     &spec.PostgresSpec{EnableReplicaLoadBalancer: False()}, | ||||
| 			spec:     &spec.PostgresSpec{EnableReplicaLoadBalancer: u.False()}, | ||||
| 			opConfig: config.Config{}, | ||||
| 			result:   false, | ||||
| 		}, | ||||
|  |  | |||
|  | @ -127,6 +127,16 @@ func Coalesce(val, defaultVal string) string { | |||
| 	return val | ||||
| } | ||||
| 
 | ||||
| func True() *bool { | ||||
| 	b := true | ||||
| 	return &b | ||||
| } | ||||
| 
 | ||||
| func False() *bool { | ||||
| 	b := false | ||||
| 	return &b | ||||
| } | ||||
| 
 | ||||
| func IsTrue(value *bool) bool { | ||||
| 	return value != nil && *value | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue