Skip to content

Commit

Permalink
fix create command not support namespace in yaml file (#962)
Browse files Browse the repository at this point in the history
Signed-off-by: zhaozhiqiang <zhaozhiqiang@lixiang.com>
  • Loading branch information
zhaoyun006 authored Mar 17, 2021
1 parent 6a98e65 commit 5f1c185
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/kubectl-argo-rollouts/cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ func unmarshal(fileBytes []byte, obj interface{}) error {
}
}

func (c *CreateOptions) getNamespace(un unstructured.Unstructured) string {
ns := c.ArgoRolloutsOptions.Namespace()
if md, ok := un.Object["metadata"]; ok {
if md == nil {
return ns
}
metadata := md.(map[string]interface{})
if internalns, ok := metadata["namespace"]; ok {
ns = internalns.(string)
}
}
return ns
}

func (c *CreateOptions) createResource(path string) (runtime.Object, error) {
ctx := context.TODO()
fileBytes, err := ioutil.ReadFile(path)
Expand All @@ -149,7 +163,7 @@ func (c *CreateOptions) createResource(path string) (runtime.Object, error) {
return nil, err
}
gvk := un.GroupVersionKind()
ns := c.ArgoRolloutsOptions.Namespace()
ns := c.getNamespace(un)
switch {
case gvk.Group == rollouts.Group && gvk.Kind == rollouts.ExperimentKind:
var exp v1alpha1.Experiment
Expand Down

0 comments on commit 5f1c185

Please sign in to comment.