@@ -29,6 +29,10 @@ import (
29
29
const (
30
30
ServiceAccountTokenSecretNameKey = "openshift.io/token-secret.name"
31
31
MaxRetriesBeforeResync = 5
32
+
33
+ // ServiceAccountTokenValueAnnotation stores the actual value of the token so that a dockercfg secret can be
34
+ // made without having a value dockerURL
35
+ ServiceAccountTokenValueAnnotation = "openshift.io/token-secret.value"
32
36
)
33
37
34
38
// DockercfgControllerOptions contains options for the DockercfgController
@@ -37,14 +41,16 @@ type DockercfgControllerOptions struct {
37
41
// If zero, re-list will be delayed as long as possible
38
42
Resync time.Duration
39
43
40
- DefaultDockerURL string
44
+ // DockerURLsIntialized is used to send a signal to this controller that it has the correct set of docker urls
45
+ DockerURLsIntialized chan struct {}
41
46
}
42
47
43
48
// NewDockercfgController returns a new *DockercfgController.
44
49
func NewDockercfgController (cl client.Interface , options DockercfgControllerOptions ) * DockercfgController {
45
50
e := & DockercfgController {
46
- client : cl ,
47
- queue : workqueue .NewRateLimitingQueue (workqueue .DefaultControllerRateLimiter ()),
51
+ client : cl ,
52
+ queue : workqueue .NewRateLimitingQueue (workqueue .DefaultControllerRateLimiter ()),
53
+ dockerURLsIntialized : options .DockerURLsIntialized ,
48
54
}
49
55
50
56
var serviceAccountCache cache.Store
@@ -76,7 +82,6 @@ func NewDockercfgController(cl client.Interface, options DockercfgControllerOpti
76
82
77
83
e .serviceAccountCache = NewEtcdMutationCache (serviceAccountCache )
78
84
e .syncHandler = e .syncServiceAccount
79
- e .dockerURL = options .DefaultDockerURL
80
85
81
86
return e
82
87
}
@@ -85,8 +90,9 @@ func NewDockercfgController(cl client.Interface, options DockercfgControllerOpti
85
90
type DockercfgController struct {
86
91
client client.Interface
87
92
88
- dockerURL string
89
- dockerURLLock sync.Mutex
93
+ dockerURLs []string
94
+ dockerURLLock sync.Mutex
95
+ dockerURLsIntialized chan struct {}
90
96
91
97
serviceAccountCache MutationCache
92
98
serviceAccountController * framework.Controller
@@ -99,16 +105,30 @@ type DockercfgController struct {
99
105
100
106
func (e * DockercfgController ) Run (workers int , stopCh <- chan struct {}) {
101
107
defer utilruntime .HandleCrash ()
102
- go e .serviceAccountController .Run (stopCh )
103
- for i := 0 ; i < workers ; i ++ {
104
- go wait .Until (e .worker , time .Second , stopCh )
105
- }
108
+ go e .waitForDockerURLs (workers , stopCh )
106
109
107
110
<- stopCh
108
111
glog .Infof ("Shutting down dockercfg secret controller" )
109
112
e .queue .ShutDown ()
110
113
}
111
114
115
+ // waitForDockerURLs blocks until the dockerURLs are ready for use. Otherwise, we'll create a bunch of useless dockercfg secrets
116
+ func (e * DockercfgController ) waitForDockerURLs (workers int , stopCh <- chan struct {}) {
117
+ defer utilruntime .HandleCrash ()
118
+
119
+ // wait for the initialization to complete to be informed of a stop
120
+ select {
121
+ case <- e .dockerURLsIntialized :
122
+ case <- stopCh :
123
+ return
124
+ }
125
+
126
+ go e .serviceAccountController .Run (stopCh )
127
+ for i := 0 ; i < workers ; i ++ {
128
+ go wait .Until (e .worker , time .Second , stopCh )
129
+ }
130
+ }
131
+
112
132
func (e * DockercfgController ) enqueueServiceAccount (serviceAccount * api.ServiceAccount ) {
113
133
if ! needsDockercfgSecret (serviceAccount ) {
114
134
return
@@ -160,14 +180,15 @@ func (e *DockercfgController) worker_inner() bool {
160
180
return true
161
181
}
162
182
163
- func (e * DockercfgController ) SetDockerURL ( newDockerURL string ) {
183
+ func (e * DockercfgController ) SetDockerURLs ( newDockerURLs ... string ) {
164
184
e .dockerURLLock .Lock ()
165
185
defer e .dockerURLLock .Unlock ()
166
186
167
- e .dockerURL = newDockerURL
187
+ e .dockerURLs = newDockerURLs
168
188
}
169
189
170
190
func needsDockercfgSecret (serviceAccount * api.ServiceAccount ) bool {
191
+
171
192
mountableDockercfgSecrets , imageDockercfgPullSecrets := getGeneratedDockercfgSecretNames (serviceAccount )
172
193
173
194
// look for an ImagePullSecret in the form
@@ -328,9 +349,10 @@ func (e *DockercfgController) createDockerPullSecret(serviceAccount *api.Service
328
349
Name : secret .Strategy .GenerateName (osautil .GetDockercfgSecretNamePrefix (serviceAccount )),
329
350
Namespace : tokenSecret .Namespace ,
330
351
Annotations : map [string ]string {
331
- api .ServiceAccountNameKey : serviceAccount .Name ,
332
- api .ServiceAccountUIDKey : string (serviceAccount .UID ),
333
- ServiceAccountTokenSecretNameKey : string (tokenSecret .Name ),
352
+ api .ServiceAccountNameKey : serviceAccount .Name ,
353
+ api .ServiceAccountUIDKey : string (serviceAccount .UID ),
354
+ ServiceAccountTokenSecretNameKey : string (tokenSecret .Name ),
355
+ ServiceAccountTokenValueAnnotation : string (tokenSecret .Data [api .ServiceAccountTokenKey ]),
334
356
},
335
357
},
336
358
Type : api .SecretTypeDockercfg ,
@@ -341,14 +363,15 @@ func (e *DockercfgController) createDockerPullSecret(serviceAccount *api.Service
341
363
e .dockerURLLock .Lock ()
342
364
defer e .dockerURLLock .Unlock ()
343
365
344
- dockercfg := & credentialprovider.DockerConfig {
345
- e .dockerURL : credentialprovider.DockerConfigEntry {
366
+ dockercfg := credentialprovider.DockerConfig {}
367
+ for _ , dockerURL := range e .dockerURLs {
368
+ dockercfg [dockerURL ] = credentialprovider.DockerConfigEntry {
346
369
Username : "serviceaccount" ,
347
370
Password : string (tokenSecret .Data [api .ServiceAccountTokenKey ]),
348
371
349
- },
372
+ }
350
373
}
351
- dockercfgContent , err := json .Marshal (dockercfg )
374
+ dockercfgContent , err := json .Marshal (& dockercfg )
352
375
if err != nil {
353
376
return nil , err
354
377
}
0 commit comments