intermediate garbage
This commit is contained in:
		
							parent
							
								
									e6db1892dc
								
							
						
					
					
						commit
						cf67d610dd
					
				| 
						 | 
					@ -332,8 +332,7 @@ func (c *Controller) initController() {
 | 
				
			||||||
	if c.opConfig.EnablePostgresTeamCRD {
 | 
						if c.opConfig.EnablePostgresTeamCRD {
 | 
				
			||||||
		c.loadPostgresTeams()
 | 
							c.loadPostgresTeams()
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		teamMap := make(teams.PostgresTeamMap, 0)
 | 
							c.pgTeamMap.Reset()
 | 
				
			||||||
		c.pgTeamMap = &teamMap
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if c.opConfig.DebugLogging {
 | 
						if c.opConfig.DebugLogging {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,6 @@ import (
 | 
				
			||||||
	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/cluster"
 | 
						"github.com/zalando/postgres-operator/pkg/cluster"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/spec"
 | 
						"github.com/zalando/postgres-operator/pkg/spec"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/teams"
 | 
					 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util"
 | 
						"github.com/zalando/postgres-operator/pkg/util"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/config"
 | 
						"github.com/zalando/postgres-operator/pkg/util/config"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
						"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
				
			||||||
| 
						 | 
					@ -396,8 +395,7 @@ func (c *Controller) getInfrastructureRole(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Controller) loadPostgresTeams() {
 | 
					func (c *Controller) loadPostgresTeams() {
 | 
				
			||||||
	// reset team map
 | 
						// reset team map
 | 
				
			||||||
	teamMap := make(teams.PostgresTeamMap, 0)
 | 
						c.pgTeamMap.Reset()
 | 
				
			||||||
	c.pgTeamMap = &teamMap
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pgTeams, err := c.KubeClient.PostgresTeamsGetter.PostgresTeams(c.opConfig.WatchedNamespace).List(context.TODO(), metav1.ListOptions{})
 | 
						pgTeams, err := c.KubeClient.PostgresTeamsGetter.PostgresTeams(c.opConfig.WatchedNamespace).List(context.TODO(), metav1.ListOptions{})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,9 +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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type postgresTeamMembership struct {
 | 
					var emptyTeamMap = make(PostgresTeamMap, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PostgresTeamMembership struct {
 | 
				
			||||||
	AdditionalSuperuserTeams []string
 | 
						AdditionalSuperuserTeams []string
 | 
				
			||||||
	AdditionalTeams          []string
 | 
						AdditionalTeams          []string
 | 
				
			||||||
	AdditionalMembers        []string
 | 
						AdditionalMembers        []string
 | 
				
			||||||
| 
						 | 
					@ -94,6 +96,10 @@ func (ptm *PostgresTeamMap) GetAdditionalSuperuserTeams(team string, transitive
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Load function to import data from PostgresTeam CRD
 | 
					// Load function to import data from PostgresTeam CRD
 | 
				
			||||||
func (ptm *PostgresTeamMap) Load(pgTeams *acidv1.PostgresTeamList) {
 | 
					func (ptm *PostgresTeamMap) Load(pgTeams *acidv1.PostgresTeamList) {
 | 
				
			||||||
 | 
						if ptm == nil {
 | 
				
			||||||
 | 
							ptm = &emptyTeamMap
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	superuserTeamSet := teamHashSet{}
 | 
						superuserTeamSet := teamHashSet{}
 | 
				
			||||||
	teamSet := teamHashSet{}
 | 
						teamSet := teamHashSet{}
 | 
				
			||||||
	teamMemberSet := teamHashSet{}
 | 
						teamMemberSet := teamHashSet{}
 | 
				
			||||||
| 
						 | 
					@ -109,10 +115,17 @@ 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() {
 | 
				
			||||||
 | 
						if ptm != nil {
 | 
				
			||||||
 | 
							*ptm = emptyTeamMap
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ 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"
 | 
				
			||||||
| 
						 | 
					@ -46,9 +47,36 @@ var (
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						pgTeamMap = PostgresTeamMap{
 | 
				
			||||||
 | 
							"teamA": {
 | 
				
			||||||
 | 
								AdditionalSuperuserTeams: []string{"teamB", "team24x7"},
 | 
				
			||||||
 | 
								AdditionalTeams:          []string{"teamC"},
 | 
				
			||||||
 | 
								AdditionalMembers:        []string{},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							"teamB": {
 | 
				
			||||||
 | 
								AdditionalSuperuserTeams: []string{"teamA", "teamC", "team24x7"},
 | 
				
			||||||
 | 
								AdditionalTeams:          []string{},
 | 
				
			||||||
 | 
								AdditionalMembers:        []string{"drno"},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							"teamC": {
 | 
				
			||||||
 | 
								AdditionalSuperuserTeams: []string{"team24x7"},
 | 
				
			||||||
 | 
								AdditionalTeams:          []string{"teamA", "teamB", "acid"},
 | 
				
			||||||
 | 
								AdditionalMembers:        []string{},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							"team24x7": {
 | 
				
			||||||
 | 
								AdditionalSuperuserTeams: []string{},
 | 
				
			||||||
 | 
								AdditionalTeams:          []string{},
 | 
				
			||||||
 | 
								AdditionalMembers:        []string{"optimusprime"},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							"acid": {
 | 
				
			||||||
 | 
								AdditionalSuperuserTeams: []string{},
 | 
				
			||||||
 | 
								AdditionalTeams:          []string{},
 | 
				
			||||||
 | 
								AdditionalMembers:        []string{"batman"},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
 | 
					// TestLoadingPostgresTeamCRD PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs
 | 
				
			||||||
func TestLoadingPostgresTeamCRD(t *testing.T) {
 | 
					func TestLoadingPostgresTeamCRD(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		name  string
 | 
							name  string
 | 
				
			||||||
| 
						 | 
					@ -59,33 +87,7 @@ func TestLoadingPostgresTeamCRD(t *testing.T) {
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"Check that CRD is imported correctly into the internal format",
 | 
								"Check that CRD is imported correctly into the internal format",
 | 
				
			||||||
			pgTeamList,
 | 
								pgTeamList,
 | 
				
			||||||
			PostgresTeamMap{
 | 
								pgTeamMap,
 | 
				
			||||||
				"teamA": {
 | 
					 | 
				
			||||||
					AdditionalSuperuserTeams: []string{"teamB", "team24x7"},
 | 
					 | 
				
			||||||
					AdditionalTeams:          []string{"teamC"},
 | 
					 | 
				
			||||||
					AdditionalMembers:        []string{},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				"teamB": {
 | 
					 | 
				
			||||||
					AdditionalSuperuserTeams: []string{"teamA", "teamC", "team24x7"},
 | 
					 | 
				
			||||||
					AdditionalTeams:          []string{},
 | 
					 | 
				
			||||||
					AdditionalMembers:        []string{"drno"},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				"teamC": {
 | 
					 | 
				
			||||||
					AdditionalSuperuserTeams: []string{"team24x7"},
 | 
					 | 
				
			||||||
					AdditionalTeams:          []string{"teamA", "teamB", "acid"},
 | 
					 | 
				
			||||||
					AdditionalMembers:        []string{},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				"team24x7": {
 | 
					 | 
				
			||||||
					AdditionalSuperuserTeams: []string{},
 | 
					 | 
				
			||||||
					AdditionalTeams:          []string{},
 | 
					 | 
				
			||||||
					AdditionalMembers:        []string{"optimusprime"},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
				"acid": {
 | 
					 | 
				
			||||||
					AdditionalSuperuserTeams: []string{},
 | 
					 | 
				
			||||||
					AdditionalTeams:          []string{},
 | 
					 | 
				
			||||||
					AdditionalMembers:        []string{"batman"},
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
			"Mismatch between PostgresTeam CRD and internal map",
 | 
								"Mismatch between PostgresTeam CRD and internal map",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -107,6 +109,14 @@ 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