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
09558086
Commit
09558086
authored
Apr 20, 2015
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ServiceAccountTokens controller
parent
53d55f41
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
0 deletions
+113
-0
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+8
-0
types.go
pkg/api/types.go
+2
-0
controller.go
pkg/controller/framework/controller.go
+66
-0
namespace_controller.go
pkg/namespace/namespace_controller.go
+18
-0
doc.go
pkg/serviceaccount/doc.go
+19
-0
tokens_controller.go
pkg/serviceaccount/tokens_controller.go
+0
-0
tokens_controller_test.go
pkg/serviceaccount/tokens_controller_test.go
+0
-0
No files found.
cmd/kube-controller-manager/app/controllermanager.go
View file @
09558086
...
...
@@ -20,6 +20,7 @@ limitations under the License.
package
app
import
(
"fmt"
"net"
"net/http"
"net/http/pprof"
...
...
@@ -40,6 +41,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/namespace"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resourcequota"
"github.com/GoogleCloudPlatform/kubernetes/pkg/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/serviceaccount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volumeclaimbinder"
...
...
@@ -249,6 +251,12 @@ func (s *CMServer) Run(_ []string) error {
pvclaimBinder
.
Run
()
}
// TODO: generate signed token
tokenGenerator
:=
serviceaccount
.
TokenGeneratorFunc
(
func
(
serviceAccount
api
.
ServiceAccount
,
secret
api
.
Secret
)
(
string
,
error
)
{
return
fmt
.
Sprintf
(
"serviceaccount:%s:%s:%s:%s"
,
serviceAccount
.
Namespace
,
serviceAccount
.
Name
,
serviceAccount
.
UID
,
secret
.
Name
),
nil
})
serviceaccount
.
NewTokensController
(
kubeClient
,
serviceaccount
.
DefaultTokenControllerOptions
(
tokenGenerator
))
.
Run
()
select
{}
return
nil
}
pkg/api/types.go
View file @
09558086
...
...
@@ -1843,6 +1843,8 @@ const (
ServiceAccountUIDKey
=
"kubernetes.io/service-account.uid"
// ServiceAccountTokenKey is the key of the required data for SecretTypeServiceAccountToken secrets
ServiceAccountTokenKey
=
"token"
// ServiceAccountKubeconfigKey is the key of the optional kubeconfig data for SecretTypeServiceAccountToken secrets
ServiceAccountKubeconfigKey
=
"kubernetes.kubeconfig"
)
type
SecretList
struct
{
...
...
pkg/controller/framework/controller.go
View file @
09558086
...
...
@@ -228,3 +228,69 @@ func NewInformer(
}
return
clientState
,
New
(
cfg
)
}
// NewIndexerInformer returns a cache.Indexer and a controller for populating the index
// while also providing event notifications. You should only used the returned
// cache.Index for Get/List operations; Add/Modify/Deletes will cause the event
// notifications to be faulty.
//
// Parameters:
// * lw is list and watch functions for the source of the resource you want to
// be informed of.
// * objType is an object of the type that you expect to receive.
// * resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate
// calls, even if nothing changed). Otherwise, re-list will be delayed as
// long as possible (until the upstream source closes the watch or times out,
// or you stop the controller).
// * h is the object you want notifications sent to.
//
func
NewIndexerInformer
(
lw
cache
.
ListerWatcher
,
objType
runtime
.
Object
,
resyncPeriod
time
.
Duration
,
h
ResourceEventHandler
,
indexers
cache
.
Indexers
,
)
(
cache
.
Indexer
,
*
Controller
)
{
// This will hold the client state, as we know it.
clientState
:=
cache
.
NewIndexer
(
DeletionHandlingMetaNamespaceKeyFunc
,
indexers
)
// This will hold incoming changes. Note how we pass clientState in as a
// KeyLister, that way resync operations will result in the correct set
// of update/delete deltas.
fifo
:=
cache
.
NewDeltaFIFO
(
cache
.
MetaNamespaceKeyFunc
,
nil
,
clientState
)
cfg
:=
&
Config
{
Queue
:
fifo
,
ListerWatcher
:
lw
,
ObjectType
:
objType
,
FullResyncPeriod
:
resyncPeriod
,
RetryOnError
:
false
,
Process
:
func
(
obj
interface
{})
error
{
// from oldest to newest
for
_
,
d
:=
range
obj
.
(
cache
.
Deltas
)
{
switch
d
.
Type
{
case
cache
.
Sync
,
cache
.
Added
,
cache
.
Updated
:
if
old
,
exists
,
err
:=
clientState
.
Get
(
d
.
Object
);
err
==
nil
&&
exists
{
if
err
:=
clientState
.
Update
(
d
.
Object
);
err
!=
nil
{
return
err
}
h
.
OnUpdate
(
old
,
d
.
Object
)
}
else
{
if
err
:=
clientState
.
Add
(
d
.
Object
);
err
!=
nil
{
return
err
}
h
.
OnAdd
(
d
.
Object
)
}
case
cache
.
Deleted
:
if
err
:=
clientState
.
Delete
(
d
.
Object
);
err
!=
nil
{
return
err
}
h
.
OnDelete
(
d
.
Object
)
}
}
return
nil
},
}
return
clientState
,
New
(
cfg
)
}
pkg/namespace/namespace_controller.go
View file @
09558086
...
...
@@ -107,6 +107,10 @@ func finalize(kubeClient client.Interface, namespace api.Namespace) (*api.Namesp
// deleteAllContent will delete all content known to the system in a namespace
func
deleteAllContent
(
kubeClient
client
.
Interface
,
namespace
string
)
(
err
error
)
{
err
=
deleteServiceAccounts
(
kubeClient
,
namespace
)
if
err
!=
nil
{
return
err
}
err
=
deleteServices
(
kubeClient
,
namespace
)
if
err
!=
nil
{
return
err
...
...
@@ -217,6 +221,20 @@ func deleteResourceQuotas(kubeClient client.Interface, ns string) error {
return
nil
}
func
deleteServiceAccounts
(
kubeClient
client
.
Interface
,
ns
string
)
error
{
items
,
err
:=
kubeClient
.
ServiceAccounts
(
ns
)
.
List
(
labels
.
Everything
(),
fields
.
Everything
())
if
err
!=
nil
{
return
err
}
for
i
:=
range
items
.
Items
{
err
:=
kubeClient
.
ServiceAccounts
(
ns
)
.
Delete
(
items
.
Items
[
i
]
.
Name
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
func
deleteServices
(
kubeClient
client
.
Interface
,
ns
string
)
error
{
items
,
err
:=
kubeClient
.
Services
(
ns
)
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
...
...
pkg/serviceaccount/doc.go
0 → 100644
View file @
09558086
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package serviceaccount provides implementations
// to manage service accounts and service account tokens
package
serviceaccount
pkg/serviceaccount/tokens_controller.go
0 → 100644
View file @
09558086
This diff is collapsed.
Click to expand it.
pkg/serviceaccount/tokens_controller_test.go
0 → 100644
View file @
09558086
This diff is collapsed.
Click to expand it.
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