Skip to content

Commit

Permalink
Backport addition of corev3.ValidateGlobalMetadata (#4800)
Browse files Browse the repository at this point in the history
* Backport addition of corev3.ValidateGlobalMetadata

Signed-off-by: Christian Kruse <[email protected]>

* fix typo

Signed-off-by: Christian Kruse <[email protected]>
  • Loading branch information
c-kruse authored Jul 19, 2022
1 parent 78b123d commit f6f6a2c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/core/v3/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ func ValidateMetadata(meta *corev2.ObjectMeta) error {
}
return nil
}

// ValidateGlobalMetadata validates ObjectMeta for global (unnamespaced)
// resources. To be used on Resources implementing GlobalResource
func ValidateGlobalMetadata(meta *corev2.ObjectMeta) error {
if meta == nil {
return errors.New("nil metadata")
}
if meta.Namespace != "" {
return fmt.Errorf(
"global resources must have empty namespace: got %s",
meta.Namespace,
)
}
return nil
}

0 comments on commit f6f6a2c

Please sign in to comment.