Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
cli
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
cli
Commits
b81916c3
Commit
b81916c3
authored
4 months ago
by
Timo Furrer
Committed by
Gary Holtz
4 months ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: add token id reference to agent secret
parent
a70f0fc7
No related branches found
No related tags found
1 merge request
!1718
feat: add token id reference to agent secret
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
commands/cluster/agent/bootstrap/kubectl.go
+14
-2
14 additions, 2 deletions
commands/cluster/agent/bootstrap/kubectl.go
commands/cluster/agent/bootstrap/kubectl_test.go
+5
-3
5 additions, 3 deletions
commands/cluster/agent/bootstrap/kubectl_test.go
with
19 additions
and
5 deletions
commands/cluster/agent/bootstrap/kubectl.go
+
14
−
2
View file @
b81916c3
...
...
@@ -41,7 +41,7 @@ func (k *localKubectlWrapper) createAgentTokenSecret(tokenID int, token string)
}
}
// create the secret again with the next token
// create the secret
(
again
)
with the next token
_
,
err
=
k
.
cmd
.
RunWithOutput
(
k
.
binary
,
"create"
,
...
...
@@ -51,7 +51,19 @@ func (k *localKubectlWrapper) createAgentTokenSecret(tokenID int, token string)
namespaceFlag
,
"--type=Opaque"
,
fmt
.
Sprintf
(
"--from-literal=token=%s"
,
token
),
fmt
.
Sprintf
(
"--from-literal=token-id=%d"
,
tokenID
),
)
if
err
!=
nil
{
return
err
}
// annotate the secret with some metadata
_
,
err
=
k
.
cmd
.
RunWithOutput
(
k
.
binary
,
"annotate"
,
"secrets"
,
k
.
gitlabAgentTokenSecretName
,
namespaceFlag
,
fmt
.
Sprintf
(
"gitlab.com/agent-token-id=%d"
,
tokenID
),
)
if
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
commands/cluster/agent/bootstrap/kubectl_test.go
+
5
−
3
View file @
b81916c3
...
...
@@ -14,7 +14,8 @@ func TestKubectl_createAgentSecretToken_NewNamespace(t *testing.T) {
gomock
.
InOrder
(
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"namespace"
,
"gitlab-agent"
),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"secret"
,
"generic"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"--type=Opaque"
,
"--from-literal=token=any-token"
,
"--from-literal=token-id=42"
),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"secret"
,
"generic"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"--type=Opaque"
,
"--from-literal=token=any-token"
),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"annotate"
,
"secrets"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"gitlab.com/agent-token-id=42"
),
)
// WHEN
...
...
@@ -31,7 +32,8 @@ func TestKubectl_createAgentSecretToken_NamespaceAlreadyExists(t *testing.T) {
gomock
.
InOrder
(
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"namespace"
,
"gitlab-agent"
)
.
Return
([]
byte
(
"already exists"
),
errors
.
New
(
"test"
)),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"delete"
,
"secret"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
)
.
Return
([]
byte
(
"not found"
),
errors
.
New
(
"test"
)),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"secret"
,
"generic"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"--type=Opaque"
,
"--from-literal=token=any-token"
,
"--from-literal=token-id=42"
),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"secret"
,
"generic"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"--type=Opaque"
,
"--from-literal=token=any-token"
),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"annotate"
,
"secrets"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"gitlab.com/agent-token-id=42"
),
)
// WHEN
...
...
@@ -76,7 +78,7 @@ func TestKubectl_createAgentSecretToken_SecretCreationFails(t *testing.T) {
gomock
.
InOrder
(
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"namespace"
,
"gitlab-agent"
),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"secret"
,
"generic"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"--type=Opaque"
,
"--from-literal=token=any-token"
,
"--from-literal=token-id=42"
)
.
Return
([]
byte
(
"unknown error"
),
errors
.
New
(
"test"
)),
mockCmd
.
EXPECT
()
.
RunWithOutput
(
"kubectl"
,
"create"
,
"secret"
,
"generic"
,
"gitlab-agent-token"
,
"-n=gitlab-agent"
,
"--type=Opaque"
,
"--from-literal=token=any-token"
)
.
Return
([]
byte
(
"unknown error"
),
errors
.
New
(
"test"
)),
)
// WHEN
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment