Skip to content

Commit

Permalink
chore(namespace_filter): Remove namespace filter
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 13, 2024
1 parent ceeb12a commit d65e0f3
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 178 deletions.
3 changes: 0 additions & 3 deletions cmd/dump/dump.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package dump

import (
"context"
"os"

"github.com/clevyr/kubedb/internal/actions/dump"
"github.com/clevyr/kubedb/internal/config/flags"
"github.com/clevyr/kubedb/internal/config/namespace_filter"
"github.com/clevyr/kubedb/internal/consts"
"github.com/clevyr/kubedb/internal/util"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,7 +51,6 @@ the generated filename might look like "` + dump.HelpFilename() + `"`,
flags.RemoteGzip(cmd)
flags.Spinner(cmd, &action.Spinner)

cmd.SetContext(namespace_filter.NewContext(context.Background(), namespace_filter.ReadOnly))
return cmd
}

Expand Down
4 changes: 0 additions & 4 deletions cmd/exec/exec.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package exec

import (
"context"

"github.com/clevyr/kubedb/internal/actions/exec"
"github.com/clevyr/kubedb/internal/config/flags"
"github.com/clevyr/kubedb/internal/config/namespace_filter"
"github.com/clevyr/kubedb/internal/consts"
"github.com/clevyr/kubedb/internal/util"
"github.com/spf13/cobra"
Expand All @@ -32,7 +29,6 @@ func New() *cobra.Command {
flags.Password(cmd)
cmd.Flags().StringVarP(&action.Command, consts.CommandFlag, "c", "", "Run a single command and exit")

cmd.SetContext(namespace_filter.NewContext(context.Background(), namespace_filter.ReadWrite))
return cmd
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/port_forward/port_forward.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package port_forward

import (
"context"
"strconv"

"github.com/clevyr/kubedb/internal/actions/port_forward"
"github.com/clevyr/kubedb/internal/config/flags"
"github.com/clevyr/kubedb/internal/config/namespace_filter"
"github.com/clevyr/kubedb/internal/consts"
"github.com/clevyr/kubedb/internal/util"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -57,7 +55,6 @@ func New() *cobra.Command {
panic(err)
}

cmd.SetContext(namespace_filter.NewContext(context.Background(), namespace_filter.ReadWrite))
return cmd
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/restore/restore.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package restore

import (
"context"
"errors"
"os"

"github.com/AlecAivazis/survey/v2"
"github.com/clevyr/kubedb/internal/actions/restore"
"github.com/clevyr/kubedb/internal/config/flags"
"github.com/clevyr/kubedb/internal/config/namespace_filter"
"github.com/clevyr/kubedb/internal/consts"
"github.com/clevyr/kubedb/internal/util"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,7 +53,6 @@ Supported Input Filetypes:
flags.Spinner(cmd, &action.Spinner)
cmd.Flags().BoolVarP(&action.Force, consts.ForceFlag, "f", false, "Do not prompt before restore")

cmd.SetContext(namespace_filter.NewContext(context.Background(), namespace_filter.ReadWrite))
return cmd
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/status/status.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package status

import (
"context"
"errors"
"fmt"
"os"
Expand All @@ -10,7 +9,6 @@ import (

"github.com/clevyr/kubedb/internal/config"
"github.com/clevyr/kubedb/internal/config/flags"
"github.com/clevyr/kubedb/internal/config/namespace_filter"
"github.com/clevyr/kubedb/internal/database"
"github.com/clevyr/kubedb/internal/kubernetes"
"github.com/clevyr/kubedb/internal/util"
Expand All @@ -34,7 +32,6 @@ func New() *cobra.Command {
flags.Username(cmd)
flags.Password(cmd)

cmd.SetContext(namespace_filter.NewContext(context.Background(), namespace_filter.ReadOnly))
return cmd
}

Expand Down
6 changes: 1 addition & 5 deletions internal/config/flags/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"path/filepath"

"github.com/clevyr/kubedb/internal/config/namespace_filter"
"github.com/clevyr/kubedb/internal/consts"
"github.com/clevyr/kubedb/internal/kubernetes"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -68,11 +67,8 @@ func Namespace(cmd *cobra.Command) {
return nil, cobra.ShellCompDirectiveError
}
names := make([]string, 0, len(namespaces.Items))
access := namespace_filter.NewFromContext(cmd.Context())
for _, namespace := range namespaces.Items {
if access.Match(namespace.Name) {
names = append(names, namespace.Name)
}
names = append(names, namespace.Name)
}
return names, cobra.ShellCompDirectiveNoFileComp
})
Expand Down
62 changes: 0 additions & 62 deletions internal/config/namespace_filter/namespace_filter.go

This file was deleted.

76 changes: 0 additions & 76 deletions internal/config/namespace_filter/namespace_filter_test.go

This file was deleted.

23 changes: 10 additions & 13 deletions internal/consts/viper.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package consts

const (
AnalyzeKey = "restore.analyze"
SpinnerKey = "spinner.name"
KubeconfigKey = "kubernetes.kubeconfig"
JobPodLabelsKey = "kubernetes.job-pod-labels"
NoJobKey = "kubernetes.no-job"
LogLevelKey = "log.level"
LogFormatKey = "log.format"
LogRedactKey = "log.redact"
RemoteGzipKey = "remote-gzip"
NamespaceFilterKey = "namespace.filter"
NamespaceFilterROKey = "namespace.ro"
NamespaceFilterRWKey = "namespace.rw"
PortForwardAddrKey = "port-forward.address"
AnalyzeKey = "restore.analyze"
SpinnerKey = "spinner.name"
KubeconfigKey = "kubernetes.kubeconfig"
JobPodLabelsKey = "kubernetes.job-pod-labels"
NoJobKey = "kubernetes.no-job"
LogLevelKey = "log.level"
LogFormatKey = "log.format"
LogRedactKey = "log.redact"
RemoteGzipKey = "remote-gzip"
PortForwardAddrKey = "port-forward.address"
)
6 changes: 0 additions & 6 deletions internal/util/cmd_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/clevyr/kubedb/internal/config"
"github.com/clevyr/kubedb/internal/config/namespace_filter"
"github.com/clevyr/kubedb/internal/consts"
"github.com/clevyr/kubedb/internal/database"
"github.com/clevyr/kubedb/internal/kubernetes"
Expand Down Expand Up @@ -53,11 +52,6 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e
conf.Context = conf.Client.Context
conf.Namespace = conf.Client.Namespace

access := namespace_filter.NewFromContext(ctx)
if !access.Match(conf.Client.Namespace) {
return errors.New("The current action is disabled for namespace " + conf.Client.Namespace)
}

if _, err := conf.Client.Namespaces().Get(ctx, conf.Namespace, metav1.GetOptions{}); err != nil {
log.WithError(err).Warn("namespace may not exist")
}
Expand Down

0 comments on commit d65e0f3

Please sign in to comment.