mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Add docker-logins config to kubernetes-worker
This commit is contained in:
parent
d0301aa6e8
commit
ca9076cf0f
@ -49,3 +49,12 @@ options:
|
||||
runtime-config=batch/v2alpha1=true profiling=true
|
||||
will result in kube-apiserver being run with the following options:
|
||||
--runtime-config=batch/v2alpha1=true --profiling=true
|
||||
docker-logins:
|
||||
type: string
|
||||
default: "[]"
|
||||
description: |
|
||||
Docker login credentials. Setting this config allows Kubelet to pull images from
|
||||
registries where auth is required.
|
||||
|
||||
The value for this config must be a JSON array of credential objects, like this:
|
||||
[{"server": "my.registry", "username": "myUser", "password": "myPass"}]
|
||||
|
@ -14,6 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
@ -435,6 +436,32 @@ def extra_args_changed():
|
||||
set_state('kubernetes-worker.restart-needed')
|
||||
|
||||
|
||||
@when('config.changed.docker-logins')
|
||||
def docker_logins_changed():
|
||||
config = hookenv.config()
|
||||
previous_logins = config.previous('docker-logins')
|
||||
logins = config['docker-logins']
|
||||
logins = json.loads(logins)
|
||||
|
||||
if previous_logins:
|
||||
previous_logins = json.loads(previous_logins)
|
||||
next_servers = {login['server'] for login in logins}
|
||||
previous_servers = {login['server'] for login in previous_logins}
|
||||
servers_to_logout = previous_servers - next_servers
|
||||
for server in servers_to_logout:
|
||||
cmd = ['docker', 'logout', server]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
for login in logins:
|
||||
server = login['server']
|
||||
username = login['username']
|
||||
password = login['password']
|
||||
cmd = ['docker', 'login', server, '-u', username, '-p', password]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
set_state('kubernetes-worker.restart-needed')
|
||||
|
||||
|
||||
def arch():
|
||||
'''Return the package architecture as a string. Raise an exception if the
|
||||
architecture is not supported by kubernetes.'''
|
||||
|
Loading…
Reference in New Issue
Block a user