Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
49d0f20e
Unverified
Commit
49d0f20e
authored
Mar 04, 2019
by
Darren Shepherd
Committed by
GitHub
Mar 04, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #110 from ibuildthecloud/tokenfile
Add --token-file support
parents
a317cda8
8acc17fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
agent.go
pkg/cli/agent/agent.go
+29
-0
agent.go
pkg/cli/cmds/agent.go
+8
-1
No files found.
pkg/cli/agent/agent.go
View file @
49d0f20e
...
...
@@ -3,7 +3,10 @@ package agent
import
(
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"time"
"github.com/rancher/k3s/pkg/agent"
"github.com/rancher/k3s/pkg/cli/cmds"
...
...
@@ -13,11 +16,37 @@ import (
"github.com/urfave/cli"
)
func
readToken
(
path
string
)
(
string
,
error
)
{
if
path
==
""
{
return
""
,
nil
}
for
{
tokenBytes
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
==
nil
{
return
strings
.
TrimSpace
(
string
(
tokenBytes
)),
nil
}
else
if
os
.
IsNotExist
(
err
)
{
logrus
.
Infof
(
"Waiting for %s to be available
\n
"
,
path
)
time
.
Sleep
(
2
*
time
.
Second
)
}
else
{
return
""
,
err
}
}
}
func
Run
(
ctx
*
cli
.
Context
)
error
{
if
os
.
Getuid
()
!=
0
{
return
fmt
.
Errorf
(
"agent must be ran as root"
)
}
if
cmds
.
AgentConfig
.
TokenFile
!=
""
{
token
,
err
:=
readToken
(
cmds
.
AgentConfig
.
TokenFile
)
if
err
!=
nil
{
return
err
}
cmds
.
AgentConfig
.
Token
=
token
}
if
cmds
.
AgentConfig
.
Token
==
""
&&
cmds
.
AgentConfig
.
ClusterSecret
==
""
{
return
fmt
.
Errorf
(
"--token is required"
)
}
...
...
pkg/cli/cmds/agent.go
View file @
49d0f20e
...
...
@@ -9,7 +9,8 @@ import (
type
Agent
struct
{
Token
string
ServerURL
string
TokenFile
string
ServerURL
string
DataDir
string
NodeIP
string
NodeName
string
...
...
@@ -70,6 +71,12 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
Destination
:
&
AgentConfig
.
Token
,
},
cli
.
StringFlag
{
Name
:
"token-file"
,
Usage
:
"Token file to use for authentication"
,
EnvVar
:
"K3S_TOKEN_FILE"
,
Destination
:
&
AgentConfig
.
TokenFile
,
},
cli
.
StringFlag
{
Name
:
"server,s"
,
Usage
:
"Server to connect to"
,
EnvVar
:
"K3S_URL"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment