From 6cf15f6cec3749b2d728c110d037093fbd492bc7 Mon Sep 17 00:00:00 2001 From: sofsms <107399417+sofsms@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:58:02 +0000 Subject: [PATCH] Update create.go to handle namespace isolation (#3130) --- pkg/fission-cli/cmd/environment/create.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/fission-cli/cmd/environment/create.go b/pkg/fission-cli/cmd/environment/create.go index caa6a552..f465e451 100644 --- a/pkg/fission-cli/cmd/environment/create.go +++ b/pkg/fission-cli/cmd/environment/create.go @@ -64,16 +64,6 @@ func (opts *CreateSubCommand) complete(input cli.Input) error { // run write the resource to a spec file or create a fission CRD with remote fission server. // It also prints warning/error if necessary. func (opts *CreateSubCommand) run(input cli.Input) (err error) { - m := opts.env.ObjectMeta - - envList, err := opts.Client().FissionClientSet.CoreV1().Environments(m.Namespace).List(input.Context(), metav1.ListOptions{}) - if err != nil { - return err - } else if len(envList.Items) > 0 { - console.Verbose(2, "%d environment(s) are present in the %s namespace. "+ - "These environments are not isolated from each other; use separate namespaces if you need isolation.", - len(envList.Items), m.Namespace) - } userDefinedNS, currentNS, err := opts.GetResourceNamespace(input, flagkey.NamespaceEnvironment) if err != nil { @@ -82,6 +72,15 @@ func (opts *CreateSubCommand) run(input cli.Input) (err error) { // we use user provided NS in spec. While creating actual record we use the current context's NS. opts.env.ObjectMeta.Namespace = userDefinedNS + envList, err := opts.Client().FissionClientSet.CoreV1().Environments(opts.env.ObjectMeta.Namespace).List(input.Context(), metav1.ListOptions{}) + if err != nil { + return err + } else if len(envList.Items) > 0 { + console.Verbose(2, "%d environment(s) are present in the %s namespace. "+ + "These environments are not isolated from each other; use separate namespaces if you need isolation.", + len(envList.Items), opts.env.ObjectMeta.Namespace) + } + // if we're writing a spec, don't call the API // save to spec file or display the spec to console if input.Bool(flagkey.SpecDry) { @@ -99,7 +98,7 @@ func (opts *CreateSubCommand) run(input cli.Input) (err error) { return fv1.AggregateValidationErrors("Environment", err) } - specFile := fmt.Sprintf("env-%v.yaml", m.Name) + specFile := fmt.Sprintf("env-%v.yaml", opts.env.ObjectMeta.Name) err = spec.SpecSave(*opts.env, specFile, false) if err != nil { return errors.Wrap(err, "error saving environment spec") @@ -114,7 +113,7 @@ func (opts *CreateSubCommand) run(input cli.Input) (err error) { return errors.Wrap(err, "error creating resource") } - fmt.Printf("environment '%v' created\n", m.Name) + fmt.Printf("environment '%v' created\n", opts.env.ObjectMeta.Name) return nil }