mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
new snapd_refresh config to control snapd refresh frequency (#141)
* add snapd_refresh config and handlers to k8s-master and -worker * lint readmes * add snapd_refresh doc to the readme; make "max" less specific * adjust wording to note snapd_refresh only affects store snaps
This commit is contained in:
parent
1b6268b616
commit
800d016dd4
@ -40,6 +40,38 @@ firewall rules may not be able to contact the Charm Store. In these network
|
|||||||
restricted environments the resource can be uploaded to the model by the Juju
|
restricted environments the resource can be uploaded to the model by the Juju
|
||||||
operator.
|
operator.
|
||||||
|
|
||||||
|
#### Snap Refresh
|
||||||
|
|
||||||
|
The kubernetes resources used by this charm are snap packages. When not
|
||||||
|
specified during deployment, these resources come from the public store. By
|
||||||
|
default, the `snapd` daemon will refresh all snaps installed from the store
|
||||||
|
four (4) times per day. A charm configuration option is provided for operators
|
||||||
|
to control this refresh frequency.
|
||||||
|
|
||||||
|
>NOTE: this is a global configuration option and will affect the refresh
|
||||||
|
time for all snaps installed on a system.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
## refresh kubernetes-master snaps every tuesday
|
||||||
|
juju config kubernetes-master snapd_refresh="tue"
|
||||||
|
|
||||||
|
## refresh snaps at 11pm on the last (5th) friday of the month
|
||||||
|
juju config kubernetes-master snapd_refresh="fri5,23:00"
|
||||||
|
|
||||||
|
## delay the refresh as long as possible
|
||||||
|
juju config kubernetes-master snapd_refresh="max"
|
||||||
|
|
||||||
|
## use the system default refresh timer
|
||||||
|
juju config kubernetes-master snapd_refresh=""
|
||||||
|
```
|
||||||
|
|
||||||
|
For more information on the possible values for `snapd_refresh`, see the
|
||||||
|
*refresh.timer* section in the [system options][] documentation.
|
||||||
|
|
||||||
|
[system options]: https://forum.snapcraft.io/t/system-options/87
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
This charm supports some configuration options to set up a Kubernetes cluster
|
This charm supports some configuration options to set up a Kubernetes cluster
|
||||||
|
@ -147,6 +147,15 @@ options:
|
|||||||
default: true
|
default: true
|
||||||
description: |
|
description: |
|
||||||
If true the metrics server for Kubernetes will be deployed onto the cluster.
|
If true the metrics server for Kubernetes will be deployed onto the cluster.
|
||||||
|
snapd_refresh:
|
||||||
|
default: "max"
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
How often snapd handles updates for installed snaps. Setting an empty
|
||||||
|
string will check 4x per day. Set to "max" to delay the refresh as long
|
||||||
|
as possible. You may also set a custom string as described in the
|
||||||
|
'refresh.timer' section here:
|
||||||
|
https://forum.snapcraft.io/t/system-options/87
|
||||||
default-storage:
|
default-storage:
|
||||||
type: string
|
type: string
|
||||||
default: "auto"
|
default: "auto"
|
||||||
|
@ -427,6 +427,38 @@ def set_app_version():
|
|||||||
hookenv.application_version_set(version.split(b' v')[-1].rstrip())
|
hookenv.application_version_set(version.split(b' v')[-1].rstrip())
|
||||||
|
|
||||||
|
|
||||||
|
@when('kubernetes-master.snaps.installed')
|
||||||
|
@when('snap.refresh.set')
|
||||||
|
@when('leadership.is_leader')
|
||||||
|
def process_snapd_timer():
|
||||||
|
''' Set the snapd refresh timer on the leader so all cluster members
|
||||||
|
(present and future) will refresh near the same time. '''
|
||||||
|
# Get the current snapd refresh timer; we know layer-snap has set this
|
||||||
|
# when the 'snap.refresh.set' flag is present.
|
||||||
|
timer = snap.get(snapname='core', key='refresh.timer').decode('utf-8')
|
||||||
|
|
||||||
|
# The first time through, data_changed will be true. Subsequent calls
|
||||||
|
# should only update leader data if something changed.
|
||||||
|
if data_changed('master_snapd_refresh', timer):
|
||||||
|
hookenv.log('setting snapd_refresh timer to: {}'.format(timer))
|
||||||
|
leader_set({'snapd_refresh': timer})
|
||||||
|
|
||||||
|
|
||||||
|
@when('kubernetes-master.snaps.installed')
|
||||||
|
@when('snap.refresh.set')
|
||||||
|
@when('leadership.changed.snapd_refresh')
|
||||||
|
@when_not('leadership.is_leader')
|
||||||
|
def set_snapd_timer():
|
||||||
|
''' Set the snapd refresh.timer on non-leader cluster members. '''
|
||||||
|
# NB: This method should only be run when 'snap.refresh.set' is present.
|
||||||
|
# Layer-snap will always set a core refresh.timer, which may not be the
|
||||||
|
# same as our leader. Gating with 'snap.refresh.set' ensures layer-snap
|
||||||
|
# has finished and we are free to set our config to the leader's timer.
|
||||||
|
timer = leader_get('snapd_refresh')
|
||||||
|
hookenv.log('setting snapd_refresh timer to: {}'.format(timer))
|
||||||
|
snap.set_refresh_timer(timer)
|
||||||
|
|
||||||
|
|
||||||
@hookenv.atexit
|
@hookenv.atexit
|
||||||
def set_final_status():
|
def set_final_status():
|
||||||
''' Set the final status of the charm as we leave hook execution '''
|
''' Set the final status of the charm as we leave hook execution '''
|
||||||
|
@ -27,6 +27,38 @@ To add additional compute capacity to your Kubernetes workers, you may
|
|||||||
join any related kubernetes-master, and enlist themselves as ready once the
|
join any related kubernetes-master, and enlist themselves as ready once the
|
||||||
deployment is complete.
|
deployment is complete.
|
||||||
|
|
||||||
|
## Snap Configuration
|
||||||
|
|
||||||
|
The kubernetes resources used by this charm are snap packages. When not
|
||||||
|
specified during deployment, these resources come from the public store. By
|
||||||
|
default, the `snapd` daemon will refresh all snaps installed from the store
|
||||||
|
four (4) times per day. A charm configuration option is provided for operators
|
||||||
|
to control this refresh frequency.
|
||||||
|
|
||||||
|
>NOTE: this is a global configuration option and will affect the refresh
|
||||||
|
time for all snaps installed on a system.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
## refresh kubernetes-worker snaps every tuesday
|
||||||
|
juju config kubernetes-worker snapd_refresh="tue"
|
||||||
|
|
||||||
|
## refresh snaps at 11pm on the last (5th) friday of the month
|
||||||
|
juju config kubernetes-worker snapd_refresh="fri5,23:00"
|
||||||
|
|
||||||
|
## delay the refresh as long as possible
|
||||||
|
juju config kubernetes-worker snapd_refresh="max"
|
||||||
|
|
||||||
|
## use the system default refresh timer
|
||||||
|
juju config kubernetes-worker snapd_refresh=""
|
||||||
|
```
|
||||||
|
|
||||||
|
For more information on the possible values for `snapd_refresh`, see the
|
||||||
|
*refresh.timer* section in the [system options][] documentation.
|
||||||
|
|
||||||
|
[system options]: https://forum.snapcraft.io/t/system-options/87
|
||||||
|
|
||||||
## Operational actions
|
## Operational actions
|
||||||
|
|
||||||
The kubernetes-worker charm supports the following Operational Actions:
|
The kubernetes-worker charm supports the following Operational Actions:
|
||||||
@ -97,4 +129,3 @@ follow the same steps inversely.
|
|||||||
```
|
```
|
||||||
juju run --application kubernetes-worker close-port 30510
|
juju run --application kubernetes-worker close-port 30510
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -80,3 +80,12 @@ options:
|
|||||||
description: |
|
description: |
|
||||||
Docker image to use for the default backend. Auto will select an image
|
Docker image to use for the default backend. Auto will select an image
|
||||||
based on architecture.
|
based on architecture.
|
||||||
|
snapd_refresh:
|
||||||
|
default: "max"
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
How often snapd handles updates for installed snaps. Setting an empty
|
||||||
|
string will check 4x per day. Set to "max" to delay the refresh as long
|
||||||
|
as possible. You may also set a custom string as described in the
|
||||||
|
'refresh.timer' section here:
|
||||||
|
https://forum.snapcraft.io/t/system-options/87
|
||||||
|
@ -22,6 +22,8 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from charms.leadership import leader_get, leader_set
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shlex import split
|
from shlex import split
|
||||||
from subprocess import check_call, check_output
|
from subprocess import check_call, check_output
|
||||||
@ -289,6 +291,38 @@ def set_app_version():
|
|||||||
hookenv.application_version_set(version.split(b' v')[-1].rstrip())
|
hookenv.application_version_set(version.split(b' v')[-1].rstrip())
|
||||||
|
|
||||||
|
|
||||||
|
@when('kubernetes-worker.snaps.installed')
|
||||||
|
@when('snap.refresh.set')
|
||||||
|
@when('leadership.is_leader')
|
||||||
|
def process_snapd_timer():
|
||||||
|
''' Set the snapd refresh timer on the leader so all cluster members
|
||||||
|
(present and future) will refresh near the same time. '''
|
||||||
|
# Get the current snapd refresh timer; we know layer-snap has set this
|
||||||
|
# when the 'snap.refresh.set' flag is present.
|
||||||
|
timer = snap.get(snapname='core', key='refresh.timer').decode('utf-8')
|
||||||
|
|
||||||
|
# The first time through, data_changed will be true. Subsequent calls
|
||||||
|
# should only update leader data if something changed.
|
||||||
|
if data_changed('worker_snapd_refresh', timer):
|
||||||
|
hookenv.log('setting snapd_refresh timer to: {}'.format(timer))
|
||||||
|
leader_set({'snapd_refresh': timer})
|
||||||
|
|
||||||
|
|
||||||
|
@when('kubernetes-worker.snaps.installed')
|
||||||
|
@when('snap.refresh.set')
|
||||||
|
@when('leadership.changed.snapd_refresh')
|
||||||
|
@when_not('leadership.is_leader')
|
||||||
|
def set_snapd_timer():
|
||||||
|
''' Set the snapd refresh.timer on non-leader cluster members. '''
|
||||||
|
# NB: This method should only be run when 'snap.refresh.set' is present.
|
||||||
|
# Layer-snap will always set a core refresh.timer, which may not be the
|
||||||
|
# same as our leader. Gating with 'snap.refresh.set' ensures layer-snap
|
||||||
|
# has finished and we are free to set our config to the leader's timer.
|
||||||
|
timer = leader_get('snapd_refresh')
|
||||||
|
hookenv.log('setting snapd_refresh timer to: {}'.format(timer))
|
||||||
|
snap.set_refresh_timer(timer)
|
||||||
|
|
||||||
|
|
||||||
@when('kubernetes-worker.snaps.installed')
|
@when('kubernetes-worker.snaps.installed')
|
||||||
@when_not('kube-control.dns.available')
|
@when_not('kube-control.dns.available')
|
||||||
def notify_user_transient_status():
|
def notify_user_transient_status():
|
||||||
|
Loading…
Reference in New Issue
Block a user