Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #41 from FabianKramm/allow-space-metadata
Browse files Browse the repository at this point in the history
Allow annotations and labels on space creation
  • Loading branch information
FabianKramm authored Mar 12, 2020
2 parents c53c68e + 536261f commit 4d836f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 0 additions & 7 deletions pkg/apis/tenancy/validation/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ func ValidateName(name string, prefix bool) []string {
// ValidateSpace tests required fields for a Space.
func ValidateSpace(space *tenancy.Space) field.ErrorList {
allErrs := validation.ValidateObjectMeta(&space.ObjectMeta, false, ValidateName, field.NewPath("metadata"))
if len(space.Annotations) > 0 {
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations"), space.Annotations, "field is immutable, try updating the namespace"))
}
if len(space.Labels) > 0 {
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "labels"), space.Labels, "field is immutable, try updating the namespace"))
}

return allErrs
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/apiserver/registry/space/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (r *spaceStorage) Create(ctx context.Context, obj runtime.Object, createVal

// Check if user can access account and create space
var account *configv1alpha1.Account
if canCreate == false {
if canCreate == false || space.Spec.Account != "" {
accounts, err := r.authCache.GetAccountsForUser(user, "get")
if err != nil {
return nil, err
Expand Down Expand Up @@ -256,8 +256,12 @@ func (r *spaceStorage) Create(ctx context.Context, obj runtime.Object, createVal
}

// Apply namespace annotations & labels
space.ObjectMeta.Labels = account.Spec.Space.SpaceTemplate.Labels
space.ObjectMeta.Annotations = account.Spec.Space.SpaceTemplate.Annotations
if account.Spec.Space.SpaceTemplate.Labels != nil {
space.ObjectMeta.Labels = account.Spec.Space.SpaceTemplate.Labels
}
if account.Spec.Space.SpaceTemplate.Annotations != nil {
space.ObjectMeta.Annotations = account.Spec.Space.SpaceTemplate.Annotations
}

canCreate = true
}
Expand Down

0 comments on commit 4d836f5

Please sign in to comment.