add namespace param for fn and env (#2556)
This PR moves fission CLI as closer as possible to kubectl command behaviour. We have improved namespace handling behaviour across CLI. * add namespace param for fn and env * use common fn for ns check * update validation * default namespace for httpTrigger, env and package, config and triggers * use default ns * add namespace filter to spec * add forceNamespace flag * set current namespace * add default namespace in config * add namespace specific destroy * add all namespace in the list of resources * add namespace as global tag * use %s instead of %v * add test cases for namespace * use ns in get all functions
This commit is contained in:
@@ -33,7 +33,7 @@ func Commands() *cobra.Command {
|
||||
Required: []flag.Flag{flag.PkgEnvironment},
|
||||
Optional: []flag.Flag{flag.PkgName, flag.PkgCode, flag.PkgSrcArchive, flag.PkgDeployArchive,
|
||||
flag.PkgSrcChecksum, flag.PkgDeployChecksum, flag.PkgInsecure, flag.PkgBuildCmd,
|
||||
flag.NamespacePackage, flag.NamespaceEnvironment, flag.SpecSave, flag.SpecDry},
|
||||
flag.NamespacePackage, flag.SpecSave, flag.SpecDry},
|
||||
})
|
||||
|
||||
getSrcCmd := &cobra.Command{
|
||||
@@ -84,7 +84,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.PkgOrphan, flag.PkgStatus, flag.NamespacePackage},
|
||||
Optional: []flag.Flag{flag.PkgOrphan, flag.PkgStatus, flag.NamespacePackage, flag.AllNamespaces},
|
||||
})
|
||||
|
||||
infoCmd := &cobra.Command{
|
||||
|
||||
@@ -63,9 +63,13 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
}
|
||||
}
|
||||
|
||||
pkgNamespace := input.String(flagkey.NamespacePackage)
|
||||
envName := input.String(flagkey.PkgEnvironment)
|
||||
envNamespace := input.String(flagkey.NamespaceEnvironment)
|
||||
|
||||
userProvidedNS, pkgNamespace, err := util.GetResourceNamespace(input, flagkey.NamespacePackage)
|
||||
if err != nil {
|
||||
return fv1.AggregateValidationErrors("Environment", err)
|
||||
}
|
||||
|
||||
srcArchiveFiles := input.StringSlice(flagkey.PkgSrcArchive)
|
||||
deployArchiveFiles := input.StringSlice(flagkey.PkgDeployArchive)
|
||||
buildcmd := input.String(flagkey.PkgBuildCmd)
|
||||
@@ -100,30 +104,30 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
exists, err := fr.ExistsInSpecs(fv1.Environment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: envName,
|
||||
Namespace: envNamespace,
|
||||
Namespace: userProvidedNS,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists {
|
||||
console.Warn(fmt.Sprintf("Package '%v' references unknown Environment '%v', please create it before applying spec",
|
||||
pkgName, envName))
|
||||
console.Warn(fmt.Sprintf("Package '%s' references unknown Environment '%s' in Namespace '%s', please create it before applying spec",
|
||||
pkgName, envName, userProvidedNS))
|
||||
}
|
||||
|
||||
specDir = util.GetSpecDir(input)
|
||||
specFile = fmt.Sprintf("package-%v.yaml", pkgName)
|
||||
specFile = fmt.Sprintf("package-%s.yaml", pkgName)
|
||||
}
|
||||
|
||||
_, err := CreatePackage(input, opts.Client(), pkgName, pkgNamespace, envName, envNamespace,
|
||||
srcArchiveFiles, deployArchiveFiles, buildcmd, specDir, specFile, noZip)
|
||||
_, err = CreatePackage(input, opts.Client(), pkgName, pkgNamespace, envName,
|
||||
srcArchiveFiles, deployArchiveFiles, buildcmd, specDir, specFile, noZip, userProvidedNS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: get all necessary value from CLI input directly
|
||||
func CreatePackage(input cli.Input, client client.Interface, pkgName string, pkgNamespace string, envName string, envNamespace string,
|
||||
srcArchiveFiles []string, deployArchiveFiles []string, buildcmd string, specDir string, specFile string, noZip bool) (*metav1.ObjectMeta, error) {
|
||||
func CreatePackage(input cli.Input, client client.Interface, pkgName string, pkgNamespace string, envName string,
|
||||
srcArchiveFiles []string, deployArchiveFiles []string, buildcmd string, specDir string, specFile string, noZip bool, userProvidedNS string) (*metav1.ObjectMeta, error) {
|
||||
|
||||
insecure := input.Bool(flagkey.PkgInsecure)
|
||||
deployChecksum := input.String(flagkey.PkgDeployChecksum)
|
||||
@@ -131,10 +135,19 @@ func CreatePackage(input cli.Input, client client.Interface, pkgName string, pkg
|
||||
|
||||
pkgSpec := fv1.PackageSpec{
|
||||
Environment: fv1.EnvironmentReference{
|
||||
Namespace: envNamespace,
|
||||
Namespace: pkgNamespace,
|
||||
Name: envName,
|
||||
},
|
||||
}
|
||||
if input.Bool(flagkey.SpecSave) || input.Bool(flagkey.SpecDry) {
|
||||
pkgSpec = fv1.PackageSpec{
|
||||
Environment: fv1.EnvironmentReference{
|
||||
Namespace: userProvidedNS,
|
||||
Name: envName,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var pkgStatus fv1.BuildStatus = fv1.BuildStatusSucceeded
|
||||
|
||||
if len(deployArchiveFiles) > 0 {
|
||||
@@ -177,7 +190,7 @@ func CreatePackage(input cli.Input, client client.Interface, pkgName string, pkg
|
||||
pkg := &fv1.Package{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: pkgName,
|
||||
Namespace: pkgNamespace,
|
||||
Namespace: userProvidedNS,
|
||||
},
|
||||
Spec: pkgSpec,
|
||||
Status: fv1.PackageStatus{
|
||||
@@ -210,6 +223,7 @@ func CreatePackage(input cli.Input, client client.Interface, pkgName string, pkg
|
||||
}
|
||||
return &pkg.ObjectMeta, nil
|
||||
} else {
|
||||
pkg.ObjectMeta.Namespace = pkgNamespace
|
||||
pkgMetadata, err := client.V1().Package().Create(pkg)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error creating package")
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
@@ -49,9 +50,13 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) complete(input cli.Input) error {
|
||||
func (opts *DeleteSubCommand) complete(input cli.Input) (err error) {
|
||||
opts.name = input.String(flagkey.PkgName)
|
||||
opts.namespace = input.String(flagkey.NamespacePackage)
|
||||
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespacePackage)
|
||||
if err != nil {
|
||||
return fv1.AggregateValidationErrors("Environment", err)
|
||||
}
|
||||
|
||||
opts.deleteOrphans = input.Bool(flagkey.PkgOrphan)
|
||||
opts.force = input.Bool(flagkey.PkgForce)
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -58,9 +59,12 @@ func (opts *GetSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) complete(input cli.Input) error {
|
||||
func (opts *GetSubCommand) complete(input cli.Input) (err error) {
|
||||
opts.name = input.String(flagkey.PkgName)
|
||||
opts.namespace = input.String(flagkey.NamespacePackage)
|
||||
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespacePackage)
|
||||
if err != nil {
|
||||
return fv1.AggregateValidationErrors("Environment", err)
|
||||
}
|
||||
opts.output = input.String(flagkey.PkgOutput)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -22,10 +22,12 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type InfoSubCommand struct {
|
||||
@@ -46,9 +48,13 @@ func (opts *InfoSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *InfoSubCommand) complete(input cli.Input) error {
|
||||
func (opts *InfoSubCommand) complete(input cli.Input) (err error) {
|
||||
opts.name = input.String(flagkey.PkgName)
|
||||
opts.namespace = input.String(flagkey.NamespacePackage)
|
||||
|
||||
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespacePackage)
|
||||
if err != nil {
|
||||
return fv1.AggregateValidationErrors("Environment", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,11 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type ListSubCommand struct {
|
||||
@@ -49,16 +51,25 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) complete(input cli.Input) error {
|
||||
func (opts *ListSubCommand) complete(input cli.Input) (err error) {
|
||||
// option for the user to list all orphan packages (not referenced by any function)
|
||||
opts.listOrphans = input.Bool(flagkey.PkgOrphan)
|
||||
opts.status = input.String(flagkey.PkgStatus)
|
||||
opts.pkgNamespace = input.String(flagkey.NamespacePackage)
|
||||
_, opts.pkgNamespace, err = util.GetResourceNamespace(input, flagkey.NamespacePackage)
|
||||
if err != nil {
|
||||
return fv1.AggregateValidationErrors("Environment", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
pkgList, err := opts.Client().V1().Package().List(opts.pkgNamespace)
|
||||
func (opts *ListSubCommand) run(input cli.Input) (err error) {
|
||||
|
||||
var pkgList []fv1.Package
|
||||
if input.Bool(flagkey.AllNamespaces) {
|
||||
pkgList, err = opts.Client().V1().Package().List("")
|
||||
} else {
|
||||
pkgList, err = opts.Client().V1().Package().List(opts.pkgNamespace)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -69,7 +80,7 @@ func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
})
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\n", "NAME", "BUILD_STATUS", "ENV", "LASTUPDATEDAT")
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", "NAME", "BUILD_STATUS", "ENV", "LASTUPDATEDAT", "NAMESPACE")
|
||||
|
||||
for _, pkg := range pkgList {
|
||||
show := true
|
||||
@@ -87,7 +98,7 @@ func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
show = false
|
||||
}
|
||||
if show {
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\n", pkg.ObjectMeta.Name, pkg.Status.BuildStatus, pkg.Spec.Environment.Name, pkg.Status.LastUpdateTimestamp.Format(time.RFC822))
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", pkg.ObjectMeta.Name, pkg.Status.BuildStatus, pkg.Spec.Environment.Name, pkg.Status.LastUpdateTimestamp.Format(time.RFC822), pkg.ObjectMeta.Namespace)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type RebuildSubCommand struct {
|
||||
@@ -46,9 +47,12 @@ func (opts *RebuildSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *RebuildSubCommand) complete(input cli.Input) error {
|
||||
func (opts *RebuildSubCommand) complete(input cli.Input) (err error) {
|
||||
opts.name = input.String(flagkey.PkgName)
|
||||
opts.namespace = input.String(flagkey.NamespacePackage)
|
||||
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespacePackage)
|
||||
if err != nil {
|
||||
return fv1.AggregateValidationErrors("Environment", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type UpdateSubCommand struct {
|
||||
@@ -50,9 +51,12 @@ func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) (err error) {
|
||||
opts.pkgName = input.String(flagkey.PkgName)
|
||||
opts.pkgNamespace = input.String(flagkey.NamespacePackage)
|
||||
_, opts.pkgNamespace, err = util.GetResourceNamespace(input, flagkey.NamespacePackage)
|
||||
if err != nil {
|
||||
return fv1.AggregateValidationErrors("Environment", err)
|
||||
}
|
||||
opts.force = input.Bool(flagkey.PkgForce)
|
||||
return nil
|
||||
}
|
||||
@@ -94,7 +98,6 @@ func (opts *UpdateSubCommand) run(input cli.Input) error {
|
||||
|
||||
func UpdatePackage(input cli.Input, client client.Interface, pkg *fv1.Package) (*metav1.ObjectMeta, error) {
|
||||
envName := input.String(flagkey.PkgEnvironment)
|
||||
envNamespace := input.String(flagkey.NamespaceEnvironment)
|
||||
srcArchiveFiles := input.StringSlice(flagkey.PkgSrcArchive)
|
||||
deployArchiveFiles := input.StringSlice(flagkey.PkgDeployArchive)
|
||||
buildcmd := input.String(flagkey.PkgBuildCmd)
|
||||
@@ -119,12 +122,6 @@ func UpdatePackage(input cli.Input, client client.Interface, pkg *fv1.Package) (
|
||||
needToUpdate = true
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.NamespaceEnvironment) {
|
||||
pkg.Spec.Environment.Namespace = envNamespace
|
||||
needToRebuild = true
|
||||
needToUpdate = true
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.PkgBuildCmd) {
|
||||
pkg.Spec.BuildCommand = buildcmd
|
||||
needToRebuild = true
|
||||
|
||||
Reference in New Issue
Block a user