Skip to content

Commit

Permalink
Handle special case of namespace creation
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
  • Loading branch information
pablochacin committed Oct 4, 2022
1 parent d917713 commit ef935a8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,24 @@ func (c *Client) Create(obj map[string]interface{}) (map[string]interface{}, err
if namespace == "" {
namespace = "default"
}
resource, err := knownKinds(gvk.Kind)
gvr, err := knownKinds(gvk.Kind)
if err != nil {
return nil, err
}

resp, err := c.dynamic.Resource(resource).
Namespace(namespace).
Create(
c.ctx,
uObj,
metav1.CreateOptions{},
)
// Namesapces cannot be created in a namespaced resource interface, handle as special case
var resource dynamic.ResourceInterface
if gvk.Kind == "Namespace" {
resource = c.dynamic.Resource(gvr)
} else {
resource = c.dynamic.Resource(gvr).Namespace(namespace)
}

resp, err := resource.Create(
c.ctx,
uObj,
metav1.CreateOptions{},
)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ef935a8

Please sign in to comment.