polishing and fixes
This commit is contained in:
		
							parent
							
								
									d246e8492b
								
							
						
					
					
						commit
						c4ee9f9225
					
				| 
						 | 
					@ -0,0 +1,67 @@
 | 
				
			||||||
 | 
					apiVersion: apiextensions.k8s.io/v1beta1
 | 
				
			||||||
 | 
					kind: CustomResourceDefinition
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: postgresteams.acid.zalan.do
 | 
				
			||||||
 | 
					  labels:
 | 
				
			||||||
 | 
					    app.kubernetes.io/name: postgres-operator
 | 
				
			||||||
 | 
					  annotations:
 | 
				
			||||||
 | 
					    "helm.sh/hook": crd-install
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  group: acid.zalan.do
 | 
				
			||||||
 | 
					  names:
 | 
				
			||||||
 | 
					    kind: PostgresTeam
 | 
				
			||||||
 | 
					    listKind: PostgresTeamList
 | 
				
			||||||
 | 
					    plural: postgresteams
 | 
				
			||||||
 | 
					    singular: postgresteam
 | 
				
			||||||
 | 
					    shortNames:
 | 
				
			||||||
 | 
					    - pgteam
 | 
				
			||||||
 | 
					  scope: Namespaced
 | 
				
			||||||
 | 
					  subresources:
 | 
				
			||||||
 | 
					    status: {}
 | 
				
			||||||
 | 
					  version: v1
 | 
				
			||||||
 | 
					  validation:
 | 
				
			||||||
 | 
					    openAPIV3Schema:
 | 
				
			||||||
 | 
					      type: object
 | 
				
			||||||
 | 
					      required:
 | 
				
			||||||
 | 
					        - kind
 | 
				
			||||||
 | 
					        - apiVersion
 | 
				
			||||||
 | 
					        - spec
 | 
				
			||||||
 | 
					      properties:
 | 
				
			||||||
 | 
					        kind:
 | 
				
			||||||
 | 
					          type: string
 | 
				
			||||||
 | 
					          enum:
 | 
				
			||||||
 | 
					            - PostgresTeam
 | 
				
			||||||
 | 
					        apiVersion:
 | 
				
			||||||
 | 
					          type: string
 | 
				
			||||||
 | 
					          enum:
 | 
				
			||||||
 | 
					            - acid.zalan.do/v1
 | 
				
			||||||
 | 
					        spec:
 | 
				
			||||||
 | 
					          type: object
 | 
				
			||||||
 | 
					          properties:
 | 
				
			||||||
 | 
					            additionalSuperuserTeams:
 | 
				
			||||||
 | 
					              type: object
 | 
				
			||||||
 | 
					              description: "Map for teamId and associted additional admin teams"
 | 
				
			||||||
 | 
					              additionalProperties:
 | 
				
			||||||
 | 
					                type: array
 | 
				
			||||||
 | 
					                nullable: true
 | 
				
			||||||
 | 
					                description: "List of teams to become Postgres admins"
 | 
				
			||||||
 | 
					                items:
 | 
				
			||||||
 | 
					                  type: string
 | 
				
			||||||
 | 
					            additionalTeams:
 | 
				
			||||||
 | 
					              type: object
 | 
				
			||||||
 | 
					              description: "Map for teamId and associted additional teams"
 | 
				
			||||||
 | 
					              additionalProperties:
 | 
				
			||||||
 | 
					                type: array
 | 
				
			||||||
 | 
					                nullable: true
 | 
				
			||||||
 | 
					                description: "List of teams whose members will also be added to the Postgres cluster"
 | 
				
			||||||
 | 
					                items:
 | 
				
			||||||
 | 
					                  type: string
 | 
				
			||||||
 | 
					            additionalMembers:
 | 
				
			||||||
 | 
					              type: object
 | 
				
			||||||
 | 
					              description: "Map for teamId and associted additional users"
 | 
				
			||||||
 | 
					              additionalProperties:
 | 
				
			||||||
 | 
					                type: array
 | 
				
			||||||
 | 
					                nullable: true
 | 
				
			||||||
 | 
					                description: "List of users who will also be added to the Postgres cluster"
 | 
				
			||||||
 | 
					                items:
 | 
				
			||||||
 | 
					                  type: string
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,7 @@ rules:
 | 
				
			||||||
  resources:
 | 
					  resources:
 | 
				
			||||||
  - postgresqls
 | 
					  - postgresqls
 | 
				
			||||||
  - postgresqls/status
 | 
					  - postgresqls/status
 | 
				
			||||||
 | 
					  - postgresteams
 | 
				
			||||||
  - operatorconfigurations
 | 
					  - operatorconfigurations
 | 
				
			||||||
  verbs:
 | 
					  verbs:
 | 
				
			||||||
  - create
 | 
					  - create
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					apiVersion: "acid.zalan.do/v1"
 | 
				
			||||||
 | 
					kind: PostgresTeam
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: custom-team-membership
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  additionalSuperuserTeams:
 | 
				
			||||||
 | 
					    acid:
 | 
				
			||||||
 | 
					    - "postgres_superusers"
 | 
				
			||||||
 | 
					  additionalTeams:
 | 
				
			||||||
 | 
					    acid: []
 | 
				
			||||||
 | 
					  additionalMembers:
 | 
				
			||||||
 | 
					    acid:
 | 
				
			||||||
 | 
					    - "elephant"
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,7 @@ rules:
 | 
				
			||||||
  resources:
 | 
					  resources:
 | 
				
			||||||
  - postgresqls
 | 
					  - postgresqls
 | 
				
			||||||
  - postgresqls/status
 | 
					  - postgresqls/status
 | 
				
			||||||
 | 
					  - postgresteams
 | 
				
			||||||
  - operatorconfigurations
 | 
					  - operatorconfigurations
 | 
				
			||||||
  verbs:
 | 
					  verbs:
 | 
				
			||||||
  - create
 | 
					  - create
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ spec:
 | 
				
			||||||
        kind:
 | 
					        kind:
 | 
				
			||||||
          type: string
 | 
					          type: string
 | 
				
			||||||
          enum:
 | 
					          enum:
 | 
				
			||||||
            - postgresteam
 | 
					            - PostgresTeam
 | 
				
			||||||
        apiVersion:
 | 
					        apiVersion:
 | 
				
			||||||
          type: string
 | 
					          type: string
 | 
				
			||||||
          enum:
 | 
					          enum:
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,7 @@ spec:
 | 
				
			||||||
                description: "List of teams whose members will also be added to the Postgres cluster"
 | 
					                description: "List of teams whose members will also be added to the Postgres cluster"
 | 
				
			||||||
                items:
 | 
					                items:
 | 
				
			||||||
                  type: string
 | 
					                  type: string
 | 
				
			||||||
            additionalUsers:
 | 
					            additionalMembers:
 | 
				
			||||||
              type: object
 | 
					              type: object
 | 
				
			||||||
              description: "Map for teamId and associted additional users"
 | 
					              description: "Map for teamId and associted additional users"
 | 
				
			||||||
              additionalProperties:
 | 
					              additionalProperties:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,10 @@
 | 
				
			||||||
package v1
 | 
					package v1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						acidzalando "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
						"k8s.io/apimachinery/pkg/runtime"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/runtime/schema"
 | 
						"k8s.io/apimachinery/pkg/runtime/schema"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// APIVersion of the `postgresql` and `operator` CRDs
 | 
					// APIVersion of the `postgresql` and `operator` CRDs
 | 
				
			||||||
| 
						 | 
					@ -44,6 +43,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
 | 
				
			||||||
	// TODO: User uppercase CRDResourceKind of our types in the next major API version
 | 
						// TODO: User uppercase CRDResourceKind of our types in the next major API version
 | 
				
			||||||
	scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("postgresql"), &Postgresql{})
 | 
						scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("postgresql"), &Postgresql{})
 | 
				
			||||||
	scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("postgresqlList"), &PostgresqlList{})
 | 
						scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("postgresqlList"), &PostgresqlList{})
 | 
				
			||||||
 | 
						scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("PostgresTeam"), &PostgresTeam{})
 | 
				
			||||||
 | 
						scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("PostgresTeamList"), &PostgresTeamList{})
 | 
				
			||||||
	scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("OperatorConfiguration"),
 | 
						scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("OperatorConfiguration"),
 | 
				
			||||||
		&OperatorConfiguration{})
 | 
							&OperatorConfiguration{})
 | 
				
			||||||
	scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("OperatorConfigurationList"),
 | 
						scheme.AddKnownTypeWithName(SchemeGroupVersion.WithKind("OperatorConfigurationList"),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -242,14 +242,7 @@ func (c *Cluster) getTeamMembers(teamID string) ([]string, error) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, member := range teamInfo.Members {
 | 
						for _, member := range teamInfo.Members {
 | 
				
			||||||
		contains := false
 | 
							if !(util.SliceContains(members, member)) {
 | 
				
			||||||
		for _, additionalMember := range members {
 | 
					 | 
				
			||||||
			if member == additionalMember {
 | 
					 | 
				
			||||||
				contains = true
 | 
					 | 
				
			||||||
				break
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if !(contains) {
 | 
					 | 
				
			||||||
			members = append(members, member)
 | 
								members = append(members, member)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -396,7 +396,7 @@ func (c *Controller) getInfrastructureRole(
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Controller) loadPostgresTeams(obj interface{}) {
 | 
					func (c *Controller) loadPostgresTeams(obj interface{}) {
 | 
				
			||||||
	var pgTeamMap teams.PostgresTeamMap
 | 
						pgTeamMap := teams.PostgresTeamMap{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pgTeam, ok := obj.(*acidv1.PostgresTeam)
 | 
						pgTeam, ok := obj.(*acidv1.PostgresTeam)
 | 
				
			||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
| 
						 | 
					@ -412,6 +412,7 @@ func (c *Controller) loadPostgresTeams(obj interface{}) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Controller) updatePostgresTeams(prev, obj interface{}) {
 | 
					func (c *Controller) updatePostgresTeams(prev, obj interface{}) {
 | 
				
			||||||
 | 
						c.logger.Debugf("reloading postgres team CRDs and overwriting cached map")
 | 
				
			||||||
	c.loadPostgresTeams(obj)
 | 
						c.loadPostgresTeams(obj)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue