Skip to content

Commit

Permalink
refactor(apiserver): remove the insecure flags
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
  • Loading branch information
knight42 committed Dec 8, 2021
1 parent e2206ca commit 9573b4a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
26 changes: 0 additions & 26 deletions cmd/kube-apiserver/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"
"time"

"github.com/spf13/pflag"
utilnet "k8s.io/apimachinery/pkg/util/net"
genericoptions "k8s.io/apiserver/pkg/server/options"
"k8s.io/apiserver/pkg/storage/storagebackend"
Expand All @@ -39,10 +38,6 @@ import (
"k8s.io/kubernetes/pkg/serviceaccount"
)

// InsecurePortFlags are dummy flags, they are kept only for compatibility and will be removed in v1.24.
// TODO: remove these flags in v1.24.
var InsecurePortFlags = []string{"insecure-port", "port"}

// ServerRunOptions runs a kubernetes api server.
type ServerRunOptions struct {
GenericServerRunOptions *genericoptions.ServerRunOptions
Expand Down Expand Up @@ -145,33 +140,12 @@ func NewServerRunOptions() *ServerRunOptions {
return &s
}

// TODO: remove these insecure flags in v1.24
func addDummyInsecureFlags(fs *pflag.FlagSet) {
var (
bindAddr = net.IPv4(127, 0, 0, 1)
bindPort int
)

for _, name := range []string{"insecure-bind-address", "address"} {
fs.IPVar(&bindAddr, name, bindAddr, ""+
"The IP address on which to serve the insecure port (set to 0.0.0.0 or :: for listening in all interfaces and IP families).")
fs.MarkDeprecated(name, "This flag has no effect now and will be removed in v1.24.")
}

for _, name := range InsecurePortFlags {
fs.IntVar(&bindPort, name, bindPort, ""+
"The port on which to serve unsecured, unauthenticated access.")
fs.MarkDeprecated(name, "This flag has no effect now and will be removed in v1.24.")
}
}

// Flags returns flags for a specific APIServer by section name
func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
// Add the generic flags.
s.GenericServerRunOptions.AddUniversalFlags(fss.FlagSet("generic"))
s.Etcd.AddFlags(fss.FlagSet("etcd"))
s.SecureServing.AddFlags(fss.FlagSet("secure serving"))
addDummyInsecureFlags(fss.FlagSet("insecure serving"))
s.Audit.AddFlags(fss.FlagSet("auditing"))
s.Features.AddFlags(fss.FlagSet("features"))
s.Authentication.AddFlags(fss.FlagSet("authentication"))
Expand Down
19 changes: 0 additions & 19 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

extensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
Expand Down Expand Up @@ -81,20 +80,6 @@ import (
"k8s.io/kubernetes/pkg/serviceaccount"
)

// TODO: delete this check after insecure flags removed in v1.24
func checkNonZeroInsecurePort(fs *pflag.FlagSet) error {
for _, name := range options.InsecurePortFlags {
val, err := fs.GetInt(name)
if err != nil {
return err
}
if val != 0 {
return fmt.Errorf("invalid port value %d: only zero is allowed", val)
}
}
return nil
}

// NewAPIServerCommand creates a *cobra.Command object with default parameters
func NewAPIServerCommand() *cobra.Command {
s := options.NewServerRunOptions()
Expand Down Expand Up @@ -124,10 +109,6 @@ cluster's shared state through which all other components interact.`,
}
cliflag.PrintFlags(fs)

err := checkNonZeroInsecurePort(fs)
if err != nil {
return err
}
// set default options
completedOptions, err := Complete(s)
if err != nil {
Expand Down

0 comments on commit 9573b4a

Please sign in to comment.