Remove deprecated flags in v1.26 (#6574)

* Remove NoFlannel
* Remove cluster-secret
* Remove no-deploy
* Remove disable-selinux
* Convert wireguard to fatal error
* Remove reference to no-op K3S_CLUSTER_SECRET

Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
Derek Nola 2022-12-05 14:01:01 -08:00 committed by GitHub
parent 457e5e7379
commit d723775792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 20 additions and 97 deletions

View File

@ -123,7 +123,7 @@ sudo kubectl get nodes
`K3S_TOKEN` is created at `/var/lib/rancher/k3s/server/node-token` on your server. `K3S_TOKEN` is created at `/var/lib/rancher/k3s/server/node-token` on your server.
To install on worker nodes, pass `K3S_URL` along with To install on worker nodes, pass `K3S_URL` along with
`K3S_TOKEN` or `K3S_CLUSTER_SECRET` environment variables, for example: `K3S_TOKEN` environment variables, for example:
```bash ```bash
curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=XXX sh - curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=XXX sh -

View File

@ -18,7 +18,7 @@ set -o noglob
# Environment variables which begin with K3S_ will be preserved for the # Environment variables which begin with K3S_ will be preserved for the
# systemd service to use. Setting K3S_URL without explicitly setting # systemd service to use. Setting K3S_URL without explicitly setting
# a systemd exec command will default the command to "agent", and we # a systemd exec command will default the command to "agent", and we
# enforce that K3S_TOKEN or K3S_CLUSTER_SECRET is also set. # enforce that K3S_TOKEN is also set.
# #
# - INSTALL_K3S_SKIP_DOWNLOAD # - INSTALL_K3S_SKIP_DOWNLOAD
# If set to true will not download k3s hash or binary. # If set to true will not download k3s hash or binary.
@ -170,8 +170,8 @@ setup_env() {
if [ -z "${K3S_URL}" ]; then if [ -z "${K3S_URL}" ]; then
CMD_K3S=server CMD_K3S=server
else else
if [ -z "${K3S_TOKEN}" ] && [ -z "${K3S_TOKEN_FILE}" ] && [ -z "${K3S_CLUSTER_SECRET}" ]; then if [ -z "${K3S_TOKEN}" ] && [ -z "${K3S_TOKEN_FILE}" ]; then
fatal "Defaulted k3s exec command to 'agent' because K3S_URL is defined, but K3S_TOKEN, K3S_TOKEN_FILE or K3S_CLUSTER_SECRET is not defined." fatal "Defaulted k3s exec command to 'agent' because K3S_URL is defined, but K3S_TOKEN or K3S_TOKEN_FILE is not defined."
fi fi
CMD_K3S=agent CMD_K3S=agent
fi fi

View File

@ -17,7 +17,7 @@ set -e
# Environment variables which begin with K3S_ will be preserved for the # Environment variables which begin with K3S_ will be preserved for the
# systemd service to use. Setting K3S_URL without explicitly setting # systemd service to use. Setting K3S_URL without explicitly setting
# a systemd exec command will default the command to "agent", and we # a systemd exec command will default the command to "agent", and we
# enforce that K3S_TOKEN or K3S_CLUSTER_SECRET is also set. # enforce that K3S_TOKEN is also set.
# #
# - INSTALL_K3S_SKIP_DOWNLOAD # - INSTALL_K3S_SKIP_DOWNLOAD
# If set to true will not download k3s hash or binary. # If set to true will not download k3s hash or binary.
@ -166,8 +166,8 @@ setup_env() {
if [ -z "${K3S_URL}" ]; then if [ -z "${K3S_URL}" ]; then
CMD_K3S=server CMD_K3S=server
else else
if [ -z "${K3S_TOKEN}" ] && [ -z "${K3S_CLUSTER_SECRET}" ]; then if [ -z "${K3S_TOKEN}" ]; then
fatal "Defaulted k3s exec command to 'agent' because K3S_URL is defined, but K3S_TOKEN or K3S_CLUSTER_SECRET is not defined." fatal "Defaulted k3s exec command to 'agent' because K3S_URL is defined, but K3S_TOKEN is not defined."
fi fi
CMD_K3S=agent CMD_K3S=agent
fi fi

View File

@ -340,7 +340,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
} }
var flannelIface *net.Interface var flannelIface *net.Interface
if !envInfo.NoFlannel && len(envInfo.FlannelIface) > 0 { if controlConfig.FlannelBackend != config.FlannelBackendNone && len(envInfo.FlannelIface) > 0 {
flannelIface, err = net.InterfaceByName(envInfo.FlannelIface) flannelIface, err = net.InterfaceByName(envInfo.FlannelIface)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "unable to find interface") return nil, errors.Wrapf(err, "unable to find interface")
@ -512,14 +512,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
nodeConfig.AgentConfig.NodeExternalIP = nodeExternalIP.String() nodeConfig.AgentConfig.NodeExternalIP = nodeExternalIP.String()
} }
if nodeConfig.FlannelBackend == config.FlannelBackendNone { nodeConfig.NoFlannel = nodeConfig.FlannelBackend == config.FlannelBackendNone
nodeConfig.NoFlannel = true
} else if envInfo.NoFlannel {
logrus.Fatal("no-flannel is deprecated. Use --flannel-backend=none instead.")
} else {
nodeConfig.NoFlannel = envInfo.NoFlannel
}
if !nodeConfig.NoFlannel { if !nodeConfig.NoFlannel {
hostLocal, err := exec.LookPath("host-local") hostLocal, err := exec.LookPath("host-local")
if err != nil { if err != nil {

View File

@ -69,15 +69,6 @@ const (
"PSK": "%psk%" "PSK": "%psk%"
}` }`
wireguardBackend = `{
"Type": "extension",
"PreStartupCommand": "wg genkey | tee %flannelConfDir%/privatekey | wg pubkey",
"PostStartupCommand": "export SUBNET_IP=$(echo $SUBNET | cut -d'/' -f 1); ip link del flannel.1 2>/dev/null; echo $PATH >&2; wg-add.sh flannel.1 && wg set flannel.1 listen-port 51820 private-key %flannelConfDir%/privatekey && ip addr add $SUBNET_IP/32 dev flannel.1 && ip link set flannel.1 up && ip route add $NETWORK dev flannel.1",
"ShutdownCommand": "ip link del flannel.1",
"SubnetAddCommand": "read PUBLICKEY; wg set flannel.1 peer $PUBLICKEY endpoint $PUBLIC_IP:51820 allowed-ips $SUBNET persistent-keepalive 25",
"SubnetRemoveCommand": "read PUBLICKEY; wg set flannel.1 peer $PUBLICKEY remove"
}`
wireguardNativeBackend = `{ wireguardNativeBackend = `{
"Type": "wireguard", "Type": "wireguard",
"PersistentKeepaliveInterval": %PersistentKeepaliveInterval%, "PersistentKeepaliveInterval": %PersistentKeepaliveInterval%,
@ -234,8 +225,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
} }
logrus.Warnf("The ipsec backend is deprecated and will be removed in k3s v1.27; please switch to wireguard-native. Check our docs for information on how to migrate.") logrus.Warnf("The ipsec backend is deprecated and will be removed in k3s v1.27; please switch to wireguard-native. Check our docs for information on how to migrate.")
case config.FlannelBackendWireguard: case config.FlannelBackendWireguard:
backendConf = strings.ReplaceAll(wireguardBackend, "%flannelConfDir%", filepath.Dir(nodeConfig.FlannelConfFile)) logrus.Fatalf("The wireguard backend was deprecated in K3s v1.26, please switch to wireguard-native. Check our docs at docs.k3s.io/installation/network-options for information about how to migrate.")
logrus.Warnf("The wireguard backend is deprecated and will be removed in k3s v1.26, please switch to wireguard-native. Check our docs for information about how to migrate.")
case config.FlannelBackendWireguardNative: case config.FlannelBackendWireguardNative:
mode, ok := backendOptions["Mode"] mode, ok := backendOptions["Mode"]
if !ok { if !ok {

View File

@ -62,7 +62,7 @@ func Test_createFlannelConf(t *testing.T) {
var agent = config.Agent{} var agent = config.Agent{}
agent.ClusterCIDR = stringToCIDR(tt.args)[0] agent.ClusterCIDR = stringToCIDR(tt.args)[0]
agent.ClusterCIDRs = stringToCIDR(tt.args) agent.ClusterCIDRs = stringToCIDR(tt.args)
var nodeConfig = &config.Node{Docker: false, ContainerRuntimeEndpoint: "", NoFlannel: false, SELinux: false, FlannelBackend: "vxlan", FlannelConfFile: "test_file", FlannelConfOverride: false, FlannelIface: nil, Containerd: containerd, Images: "", AgentConfig: agent, Token: "", Certificate: nil, ServerHTTPSPort: 0} var nodeConfig = &config.Node{Docker: false, ContainerRuntimeEndpoint: "", SELinux: false, FlannelBackend: "vxlan", FlannelConfFile: "test_file", FlannelConfOverride: false, FlannelIface: nil, Containerd: containerd, Images: "", AgentConfig: agent, Token: "", Certificate: nil, ServerHTTPSPort: 0}
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if err := createFlannelConf(nodeConfig); (err != nil) != tt.wantErr { if err := createFlannelConf(nodeConfig); (err != nil) != tt.wantErr {

View File

@ -45,10 +45,6 @@ func Run(ctx *cli.Context) error {
cmds.AgentConfig.Token = token cmds.AgentConfig.Token = token
} }
if cmds.AgentConfig.Token == "" && cmds.AgentConfig.ClusterSecret != "" {
logrus.Fatal("cluster-secret is deprecated. Use --token instead.")
}
if cmds.AgentConfig.Token == "" { if cmds.AgentConfig.Token == "" {
return fmt.Errorf("--token is required") return fmt.Errorf("--token is required")
} }

View File

@ -5,7 +5,6 @@ import (
"path/filepath" "path/filepath"
"github.com/k3s-io/k3s/pkg/version" "github.com/k3s-io/k3s/pkg/version"
"github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -28,7 +27,6 @@ type Agent struct {
Snapshotter string Snapshotter string
Docker bool Docker bool
ContainerRuntimeEndpoint string ContainerRuntimeEndpoint string
NoFlannel bool
FlannelIface string FlannelIface string
FlannelConf string FlannelConf string
FlannelCniConfFile string FlannelCniConfFile string
@ -191,35 +189,13 @@ var (
Destination: &AgentConfig.ImageCredProvConfig, Destination: &AgentConfig.ImageCredProvConfig,
Value: "/var/lib/rancher/credentialprovider/config.yaml", Value: "/var/lib/rancher/credentialprovider/config.yaml",
} }
DisableSELinuxFlag = cli.BoolTFlag{
Name: "disable-selinux",
Usage: "(deprecated) Use --selinux to explicitly enable SELinux",
Hidden: true,
}
FlannelFlag = cli.BoolFlag{
Hidden: true,
Name: "no-flannel",
Usage: "(deprecated) use --flannel-backend=none",
Destination: &AgentConfig.NoFlannel,
}
) )
func CheckSELinuxFlags(ctx *cli.Context) error {
disable, enable := DisableSELinuxFlag.Name, SELinuxFlag.Name
switch {
case ctx.IsSet(disable) && ctx.IsSet(enable):
return errors.Errorf("--%s is deprecated in favor of --%s to affirmatively enable it in containerd", disable, enable)
case ctx.IsSet(disable):
AgentConfig.EnableSELinux = !ctx.Bool(disable)
}
return nil
}
func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command { func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
return cli.Command{ return cli.Command{
Name: "agent", Name: "agent",
Usage: "Run node agent", Usage: "Run node agent",
UsageText: appName + " agent [OPTIONS]", UsageText: appName + " agent [OPTIONS]",
Before: CheckSELinuxFlags,
Action: action, Action: action,
Flags: []cli.Flag{ Flags: []cli.Flag{
ConfigFlag, ConfigFlag,
@ -277,16 +253,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
}, },
PreferBundledBin, PreferBundledBin,
// Deprecated/hidden below // Deprecated/hidden below
&DisableSELinuxFlag,
DockerFlag, DockerFlag,
FlannelFlag,
cli.StringFlag{
Name: "cluster-secret",
Usage: "(deprecated) use --token",
Destination: &AgentConfig.ClusterSecret,
EnvVar: version.ProgramUpper + "_CLUSTER_SECRET",
Hidden: true,
},
}, },
} }
} }

View File

@ -249,7 +249,7 @@ var ServerFlags = []cli.Flag{
ServerToken, ServerToken,
cli.StringFlag{ cli.StringFlag{
Name: "token-file", Name: "token-file",
Usage: "(cluster) File containing the cluster-secret/token", Usage: "(cluster) File containing the token",
Destination: &ServerConfig.TokenFile, Destination: &ServerConfig.TokenFile,
EnvVar: version.ProgramUpper + "_TOKEN_FILE", EnvVar: version.ProgramUpper + "_TOKEN_FILE",
}, },
@ -520,20 +520,6 @@ var ServerFlags = []cli.Flag{
// Hidden/Deprecated flags below // Hidden/Deprecated flags below
&DisableSELinuxFlag,
FlannelFlag,
cli.StringSliceFlag{
Name: "no-deploy",
Usage: "(deprecated) Do not deploy packaged components (valid items: " + DisableItems + ")",
Hidden: true,
},
cli.StringFlag{
Name: "cluster-secret",
Usage: "(deprecated) use --token",
Destination: &ServerConfig.ClusterSecret,
EnvVar: version.ProgramUpper + "_CLUSTER_SECRET",
Hidden: true,
},
cli.BoolFlag{ cli.BoolFlag{
Name: "disable-agent", Name: "disable-agent",
Usage: "Do not run a local agent and register a local kubelet", Usage: "Do not run a local agent and register a local kubelet",
@ -559,7 +545,6 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
Name: "server", Name: "server",
Usage: "Run management server", Usage: "Run management server",
UsageText: appName + " server [OPTIONS]", UsageText: appName + " server [OPTIONS]",
Before: CheckSELinuxFlags,
Action: action, Action: action,
Flags: ServerFlags, Flags: ServerFlags,
} }

View File

@ -91,10 +91,6 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
} }
} }
if cfg.Token == "" && cfg.ClusterSecret != "" {
logrus.Fatal("cluster-secret is deprecated. Use --token instead.")
}
agentReady := make(chan struct{}) agentReady := make(chan struct{})
serverConfig := server.Config{} serverConfig := server.Config{}
@ -352,9 +348,6 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
} }
serverConfig.ControlConfig.Skips = map[string]bool{} serverConfig.ControlConfig.Skips = map[string]bool{}
if noDeploy := app.StringSlice("no-deploy"); len(noDeploy) > 0 {
logrus.Fatal("no-deploy flag is deprecated. Use --disable instead.")
}
serverConfig.ControlConfig.Disables = map[string]bool{} serverConfig.ControlConfig.Disables = map[string]bool{}
for _, disable := range app.StringSlice("disable") { for _, disable := range app.StringSlice("disable") {
for _, v := range strings.Split(disable, ",") { for _, v := range strings.Split(disable, ",") {

View File

@ -129,7 +129,6 @@ func isSecret(key string) bool {
"-t", "-t",
"--agent-token", "--agent-token",
"--datastore-endpoint", "--datastore-endpoint",
"--cluster-secret",
"--etcd-s3-access-key", "--etcd-s3-access-key",
"--etcd-s3-secret-key", "--etcd-s3-secret-key",
} }

View File

@ -28,16 +28,16 @@ var FakeNodeWithAnnotation = &corev1.Node{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "fakeNode-with-annotation", Name: "fakeNode-with-annotation",
Annotations: map[string]string{ Annotations: map[string]string{
NodeArgsAnnotation: `["server","--no-flannel"]`, NodeArgsAnnotation: `["server","--flannel-backend=none"]`,
NodeEnvAnnotation: `{"` + TestEnvName + `":"fakeNode-with-annotation"}`, NodeEnvAnnotation: `{"` + TestEnvName + `":"fakeNode-with-annotation"}`,
NodeConfigHashAnnotation: "LNQOAOIMOQIBRMEMACW7LYHXUNPZADF6RFGOSPIHJCOS47UVUJAA====", NodeConfigHashAnnotation: "5E6GSWFRVCOEB3BFFVXKWVD7IQEVJFJAALHPOTCLV7SL33N6SIYA====",
}, },
}, },
} }
func Test_UnitSetExistingNodeConfigAnnotations(t *testing.T) { func Test_UnitSetExistingNodeConfigAnnotations(t *testing.T) {
// adding same config // adding same config
os.Args = []string{version.Program, "server", "--no-flannel"} os.Args = []string{version.Program, "server", "--flannel-backend=none"}
os.Setenv(version.ProgramUpper+"_NODE_NAME", "fakeNode-with-annotation") os.Setenv(version.ProgramUpper+"_NODE_NAME", "fakeNode-with-annotation")
nodeUpdated, err := SetNodeConfigAnnotations(FakeNodeWithAnnotation) nodeUpdated, err := SetNodeConfigAnnotations(FakeNodeWithAnnotation)
if err != nil { if err != nil {
@ -73,21 +73,21 @@ func Test_UnitSetNodeConfigAnnotations(t *testing.T) {
name: "Set empty NodeConfigAnnotations", name: "Set empty NodeConfigAnnotations",
args: args{ args: args{
node: FakeNodeWithAnnotation, node: FakeNodeWithAnnotation,
osArgs: []string{version.Program, "server", "--no-flannel"}, osArgs: []string{version.Program, "server", "--flannel-backend=none"},
}, },
want: true, want: true,
wantNodeArgs: `["server","--no-flannel"]`, wantNodeArgs: `["server","--flannel-backend","none"]`,
wantNodeEnv: `{"` + TestEnvName + `":"fakeNode-with-no-annotation"}`, wantNodeEnv: `{"` + TestEnvName + `":"fakeNode-with-no-annotation"}`,
wantNodeConfigHash: "FBV4UQYLF2N7NH7EK42GKOTU5YA24TXB4WAYZHA5ZOFNGZHC4ZPA====", wantNodeConfigHash: "DRWW63TXZZGSKLARSFZLNSJ3RZ6VR7LQ46WPKZMSLTSGNI2J42WA====",
}, },
{ {
name: "Set args with equal", name: "Set args with equal",
args: args{ args: args{
node: FakeNodeWithNoAnnotation, node: FakeNodeWithNoAnnotation,
osArgs: []string{version.Program, "server", "--no-flannel", "--write-kubeconfig-mode=777"}, osArgs: []string{version.Program, "server", "--flannel-backend=none", "--write-kubeconfig-mode=777"},
}, },
want: true, want: true,
wantNodeArgs: `["server","--no-flannel","--write-kubeconfig-mode","777"]`, wantNodeArgs: `["server","--flannel-backend","none","--write-kubeconfig-mode","777"]`,
wantNodeEnv: `{"` + TestEnvName + `":"fakeNode-with-no-annotation"}`, wantNodeEnv: `{"` + TestEnvName + `":"fakeNode-with-no-annotation"}`,
}, },
} }