unittest with non default label
This commit is contained in:
parent
b433066577
commit
1410daa1aa
|
|
@ -35,6 +35,7 @@ const (
|
|||
adminUserName = "admin"
|
||||
exampleSpiloConfig = `{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_connections":"100","max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`
|
||||
spiloConfigDiff = `{"postgresql":{"bin_dir":"/usr/lib/postgresql/12/bin","parameters":{"autovacuum_analyze_scale_factor":"0.1"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"]},"bootstrap":{"initdb":[{"auth-host":"md5"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"dcs":{"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"postgresql":{"parameters":{"max_locks_per_transaction":"64","max_worker_processes":"4"}}}}}`
|
||||
leaderLabelValue = "primary"
|
||||
)
|
||||
|
||||
var logger = logrus.New().WithField("test", "cluster")
|
||||
|
|
@ -55,7 +56,7 @@ var cl = New(
|
|||
},
|
||||
Resources: config.Resources{
|
||||
DownscalerAnnotations: []string{"downscaler/*"},
|
||||
PodLeaderLabelValue: "master",
|
||||
PodLeaderLabelValue: leaderLabelValue,
|
||||
},
|
||||
ConnectionPooler: config.ConnectionPooler{
|
||||
User: poolerUserName,
|
||||
|
|
@ -127,7 +128,7 @@ func TestCreate(t *testing.T) {
|
|||
Labels: map[string]string{
|
||||
"application": "spilo",
|
||||
"cluster-name": clusterName,
|
||||
"spilo-role": "master",
|
||||
"spilo-role": leaderLabelValue,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -148,7 +149,7 @@ func TestCreate(t *testing.T) {
|
|||
DefaultMemoryRequest: "300Mi",
|
||||
DefaultMemoryLimit: "300Mi",
|
||||
PodRoleLabel: "spilo-role",
|
||||
PodLeaderLabelValue: "master",
|
||||
PodLeaderLabelValue: leaderLabelValue,
|
||||
ResourceCheckInterval: time.Duration(3),
|
||||
ResourceCheckTimeout: time.Duration(10),
|
||||
},
|
||||
|
|
@ -665,7 +666,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
//MASTER
|
||||
{
|
||||
about: "Master with no annotations and EnableMasterLoadBalancer disabled on spec and OperatorConfig",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerSpec: &disabled,
|
||||
enableMasterLoadBalancerOC: false,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
|
|
@ -675,7 +676,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with no annotations and EnableMasterLoadBalancer enabled on spec",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerSpec: &enabled,
|
||||
enableMasterLoadBalancerOC: false,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
|
|
@ -688,7 +689,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with no annotations and EnableMasterLoadBalancer enabled only on operator config",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerSpec: &disabled,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
|
|
@ -698,7 +699,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with no annotations and EnableMasterLoadBalancer defined only on operator config",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
operatorAnnotations: make(map[string]string),
|
||||
|
|
@ -710,7 +711,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with cluster annotations and load balancer enabled",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
operatorAnnotations: make(map[string]string),
|
||||
|
|
@ -723,7 +724,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with cluster annotations and load balancer disabled",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerSpec: &disabled,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
|
|
@ -733,7 +734,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with operator annotations and load balancer enabled",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
operatorAnnotations: map[string]string{"foo": "bar"},
|
||||
|
|
@ -746,7 +747,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with operator annotations override default annotations",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
operatorAnnotations: map[string]string{
|
||||
|
|
@ -760,7 +761,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with cluster annotations override default annotations",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
operatorAnnotations: make(map[string]string),
|
||||
|
|
@ -774,7 +775,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with cluster annotations do not override external-dns annotations",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
operatorAnnotations: make(map[string]string),
|
||||
|
|
@ -788,7 +789,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with cluster name teamId prefix enabled",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: true,
|
||||
serviceAnnotations: make(map[string]string),
|
||||
|
|
@ -800,7 +801,7 @@ func TestServiceAnnotations(t *testing.T) {
|
|||
},
|
||||
{
|
||||
about: "Master with master service annotations override service annotations",
|
||||
role: "master",
|
||||
role: leaderLabelValue,
|
||||
enableMasterLoadBalancerOC: true,
|
||||
enableTeamIdClusterPrefix: false,
|
||||
operatorAnnotations: make(map[string]string),
|
||||
|
|
|
|||
|
|
@ -424,7 +424,7 @@ func TestConnectionPoolerSync(t *testing.T) {
|
|||
DefaultMemoryRequest: "300Mi",
|
||||
DefaultMemoryLimit: "300Mi",
|
||||
PodRoleLabel: "spilo-role",
|
||||
PodLeaderLabelValue: "master",
|
||||
PodLeaderLabelValue: leaderLabelValue,
|
||||
},
|
||||
},
|
||||
}, client, pg, logger, eventRecorder)
|
||||
|
|
|
|||
|
|
@ -2359,7 +2359,7 @@ func TestGeneratePodDisruptionBudget(t *testing.T) {
|
|||
}
|
||||
if !masterLabelSelectorDisabled &&
|
||||
!reflect.DeepEqual(podDisruptionBudget.Spec.Selector, &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"spilo-role": "master", "cluster-name": "myapp-database"}}) {
|
||||
MatchLabels: map[string]string{"spilo-role": leaderLabelValue, "cluster-name": "myapp-database"}}) {
|
||||
|
||||
return fmt.Errorf("MatchLabels incorrect.")
|
||||
}
|
||||
|
|
@ -2389,7 +2389,7 @@ func TestGeneratePodDisruptionBudget(t *testing.T) {
|
|||
{
|
||||
scenario: "With multiple instances",
|
||||
spec: New(
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: "master"}, PDBNameFormat: "postgres-{cluster}-pdb"}},
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: leaderLabelValue}, PDBNameFormat: "postgres-{cluster}-pdb"}},
|
||||
k8sutil.KubernetesClient{},
|
||||
acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"},
|
||||
|
|
@ -2406,7 +2406,7 @@ func TestGeneratePodDisruptionBudget(t *testing.T) {
|
|||
{
|
||||
scenario: "With zero instances",
|
||||
spec: New(
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: "master"}, PDBNameFormat: "postgres-{cluster}-pdb"}},
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: leaderLabelValue}, PDBNameFormat: "postgres-{cluster}-pdb"}},
|
||||
k8sutil.KubernetesClient{},
|
||||
acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"},
|
||||
|
|
@ -2423,7 +2423,7 @@ func TestGeneratePodDisruptionBudget(t *testing.T) {
|
|||
{
|
||||
scenario: "With PodDisruptionBudget disabled",
|
||||
spec: New(
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: "master"}, PDBNameFormat: "postgres-{cluster}-pdb", EnablePodDisruptionBudget: util.False()}},
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: leaderLabelValue}, PDBNameFormat: "postgres-{cluster}-pdb", EnablePodDisruptionBudget: util.False()}},
|
||||
k8sutil.KubernetesClient{},
|
||||
acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"},
|
||||
|
|
@ -2440,7 +2440,7 @@ func TestGeneratePodDisruptionBudget(t *testing.T) {
|
|||
{
|
||||
scenario: "With non-default PDBNameFormat and PodDisruptionBudget explicitly enabled",
|
||||
spec: New(
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: "master"}, PDBNameFormat: "postgres-{cluster}-databass-budget", EnablePodDisruptionBudget: util.True()}},
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: leaderLabelValue}, PDBNameFormat: "postgres-{cluster}-databass-budget", EnablePodDisruptionBudget: util.True()}},
|
||||
k8sutil.KubernetesClient{},
|
||||
acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"},
|
||||
|
|
@ -2457,7 +2457,7 @@ func TestGeneratePodDisruptionBudget(t *testing.T) {
|
|||
{
|
||||
scenario: "With PDBMasterLabelSelector disabled",
|
||||
spec: New(
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: "master"}, PDBNameFormat: "postgres-{cluster}-pdb", EnablePodDisruptionBudget: util.True(), PDBMasterLabelSelector: util.False()}},
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: leaderLabelValue}, PDBNameFormat: "postgres-{cluster}-pdb", EnablePodDisruptionBudget: util.True(), PDBMasterLabelSelector: util.False()}},
|
||||
k8sutil.KubernetesClient{},
|
||||
acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"},
|
||||
|
|
@ -2474,7 +2474,7 @@ func TestGeneratePodDisruptionBudget(t *testing.T) {
|
|||
{
|
||||
scenario: "With OwnerReference enabled",
|
||||
spec: New(
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: "master", EnableOwnerReferences: util.True()}, PDBNameFormat: "postgres-{cluster}-pdb", EnablePodDisruptionBudget: util.True()}},
|
||||
Config{OpConfig: config.Config{Resources: config.Resources{ClusterNameLabel: "cluster-name", PodRoleLabel: "spilo-role", PodLeaderLabelValue: leaderLabelValue, EnableOwnerReferences: util.True()}, PDBNameFormat: "postgres-{cluster}-pdb", EnablePodDisruptionBudget: util.True()}},
|
||||
k8sutil.KubernetesClient{},
|
||||
acidv1.Postgresql{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "myapp-database", Namespace: "myapp"},
|
||||
|
|
@ -2550,7 +2550,7 @@ func TestGenerateService(t *testing.T) {
|
|||
DefaultMemoryRequest: "0.7Gi",
|
||||
MaxMemoryRequest: "1.0Gi",
|
||||
DefaultMemoryLimit: "1.3Gi",
|
||||
PodLeaderLabelValue: "master",
|
||||
PodLeaderLabelValue: leaderLabelValue,
|
||||
},
|
||||
SidecarImages: map[string]string{
|
||||
"deprecated-global-sidecar": "image:123",
|
||||
|
|
|
|||
|
|
@ -556,7 +556,7 @@ func TestSyncStandbyClusterConfiguration(t *testing.T) {
|
|||
podLabels := map[string]string{
|
||||
"cluster-name": clusterName,
|
||||
"application": applicationLabel,
|
||||
"spilo-role": "master",
|
||||
"spilo-role": leaderLabelValue,
|
||||
}
|
||||
mockPod.Labels = podLabels
|
||||
client.PodsGetter.Pods(namespace).Create(context.TODO(), mockPod, metav1.CreateOptions{})
|
||||
|
|
|
|||
Loading…
Reference in New Issue