refactoring
This commit is contained in:
		
							parent
							
								
									db568c0ef5
								
							
						
					
					
						commit
						27ec82bd85
					
				| 
						 | 
					@ -1163,12 +1163,14 @@ func (c *Cluster) initHumanUsers() error {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	additionalTeams := c.Config.PgTeamMap.GetAdditionalTeams(c.Spec.TeamID, true)
 | 
						if c.Config.PgTeamMap != nil {
 | 
				
			||||||
	for _, additionalTeam := range additionalTeams {
 | 
							additionalTeams := c.Config.PgTeamMap.GetAdditionalTeams(c.Spec.TeamID, true)
 | 
				
			||||||
		if !(util.SliceContains(superuserTeams, additionalTeam)) {
 | 
							for _, additionalTeam := range additionalTeams {
 | 
				
			||||||
			err := c.initTeamMembers(additionalTeam, false)
 | 
								if !(util.SliceContains(superuserTeams, additionalTeam)) {
 | 
				
			||||||
			if err != nil {
 | 
									err := c.initTeamMembers(additionalTeam, false)
 | 
				
			||||||
				return fmt.Errorf("Cannot initialize members for additional team %q for cluster owned by %q: %v", additionalTeam, c.Spec.TeamID, err)
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return fmt.Errorf("Cannot initialize members for additional team %q for cluster owned by %q: %v", additionalTeam, c.Spec.TeamID, err)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,6 @@ import (
 | 
				
			||||||
	"github.com/sirupsen/logrus"
 | 
						"github.com/sirupsen/logrus"
 | 
				
			||||||
	acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
						acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/spec"
 | 
						"github.com/zalando/postgres-operator/pkg/spec"
 | 
				
			||||||
	pgteams "github.com/zalando/postgres-operator/pkg/teams"
 | 
					 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/config"
 | 
						"github.com/zalando/postgres-operator/pkg/util/config"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/constants"
 | 
						"github.com/zalando/postgres-operator/pkg/util/constants"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
						"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
				
			||||||
| 
						 | 
					@ -24,7 +23,6 @@ const (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var logger = logrus.New().WithField("test", "cluster")
 | 
					var logger = logrus.New().WithField("test", "cluster")
 | 
				
			||||||
var eventRecorder = record.NewFakeRecorder(1)
 | 
					var eventRecorder = record.NewFakeRecorder(1)
 | 
				
			||||||
var teamMap = make(pgteams.PostgresTeamMap, 0)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
var cl = New(
 | 
					var cl = New(
 | 
				
			||||||
	Config{
 | 
						Config{
 | 
				
			||||||
| 
						 | 
					@ -39,7 +37,6 @@ var cl = New(
 | 
				
			||||||
				DownscalerAnnotations: []string{"downscaler/*"},
 | 
									DownscalerAnnotations: []string{"downscaler/*"},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		PgTeamMap: &teamMap,
 | 
					 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	k8sutil.NewMockKubernetesClient(),
 | 
						k8sutil.NewMockKubernetesClient(),
 | 
				
			||||||
	acidv1.Postgresql{ObjectMeta: metav1.ObjectMeta{Name: "acid-test", Namespace: "test", Annotations: map[string]string{"downscaler/downtime_replicas": "0"}}},
 | 
						acidv1.Postgresql{ObjectMeta: metav1.ObjectMeta{Name: "acid-test", Namespace: "test", Annotations: map[string]string{"downscaler/downtime_replicas": "0"}}},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -242,9 +242,11 @@ func (c *Cluster) getTeamMembers(teamID string) ([]string, error) {
 | 
				
			||||||
	members := []string{}
 | 
						members := []string{}
 | 
				
			||||||
	additionalMembers := []string{}
 | 
						additionalMembers := []string{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for team, membership := range *c.Config.PgTeamMap {
 | 
						if c.Config.PgTeamMap != nil {
 | 
				
			||||||
		if team == teamID {
 | 
							for team, membership := range *c.Config.PgTeamMap {
 | 
				
			||||||
			additionalMembers = membership.AdditionalMembers
 | 
								if team == teamID {
 | 
				
			||||||
 | 
									additionalMembers = membership.AdditionalMembers
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -332,7 +332,7 @@ func (c *Controller) initController() {
 | 
				
			||||||
	if c.opConfig.EnablePostgresTeamCRD {
 | 
						if c.opConfig.EnablePostgresTeamCRD {
 | 
				
			||||||
		c.loadPostgresTeams()
 | 
							c.loadPostgresTeams()
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		c.pgTeamMap.Reset()
 | 
							c.pgTeamMap = teams.PostgresTeamMap{}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if c.opConfig.DebugLogging {
 | 
						if c.opConfig.DebugLogging {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,11 +6,11 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
 | 
					// PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
 | 
				
			||||||
type PostgresTeamMap map[string]*PostgresTeamMembership
 | 
					type PostgresTeamMap map[string]*postgresTeamMembership
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var emptyTeamMap = make(PostgresTeamMap, 0)
 | 
					var emptyTeamMap = make(PostgresTeamMap, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type PostgresTeamMembership struct {
 | 
					type postgresTeamMembership struct {
 | 
				
			||||||
	AdditionalSuperuserTeams []string
 | 
						AdditionalSuperuserTeams []string
 | 
				
			||||||
	AdditionalTeams          []string
 | 
						AdditionalTeams          []string
 | 
				
			||||||
	AdditionalMembers        []string
 | 
						AdditionalMembers        []string
 | 
				
			||||||
| 
						 | 
					@ -115,15 +115,10 @@ func (ptm *PostgresTeamMap) Load(pgTeams *acidv1.PostgresTeamList) {
 | 
				
			||||||
	fetchTeams(&teamIDs, teamMemberSet)
 | 
						fetchTeams(&teamIDs, teamMemberSet)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for teamID := range teamIDs {
 | 
						for teamID := range teamIDs {
 | 
				
			||||||
		(*ptm)[teamID] = &PostgresTeamMembership{
 | 
							(*ptm)[teamID] = &postgresTeamMembership{
 | 
				
			||||||
			AdditionalSuperuserTeams: util.CoalesceStrArr(superuserTeamSet.toMap()[teamID], []string{}),
 | 
								AdditionalSuperuserTeams: util.CoalesceStrArr(superuserTeamSet.toMap()[teamID], []string{}),
 | 
				
			||||||
			AdditionalTeams:          util.CoalesceStrArr(teamSet.toMap()[teamID], []string{}),
 | 
								AdditionalTeams:          util.CoalesceStrArr(teamSet.toMap()[teamID], []string{}),
 | 
				
			||||||
			AdditionalMembers:        util.CoalesceStrArr(teamMemberSet.toMap()[teamID], []string{}),
 | 
								AdditionalMembers:        util.CoalesceStrArr(teamMemberSet.toMap()[teamID], []string{}),
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// Reset a PostgresTeamMap
 | 
					 | 
				
			||||||
func (ptm *PostgresTeamMap) Reset() {
 | 
					 | 
				
			||||||
	*ptm = emptyTeamMap
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,6 @@ package teams
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/stretchr/testify/assert"
 | 
					 | 
				
			||||||
	acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
						acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util"
 | 
						"github.com/zalando/postgres-operator/pkg/util"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
| 
						 | 
					@ -109,14 +108,6 @@ func TestLoadingPostgresTeamCRD(t *testing.T) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TestLoadingPostgresTeamCRD PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
 | 
					 | 
				
			||||||
func TestResetPostgresTeamCRD(t *testing.T) {
 | 
					 | 
				
			||||||
	teamMap := &pgTeamMap
 | 
					 | 
				
			||||||
	teamMap.Reset()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	assert.Equal(t, teamMap, &PostgresTeamMap{})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// TestGetAdditionalTeams if returns teams with and without transitive dependencies
 | 
					// TestGetAdditionalTeams if returns teams with and without transitive dependencies
 | 
				
			||||||
func TestGetAdditionalTeams(t *testing.T) {
 | 
					func TestGetAdditionalTeams(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue