Skip to content

Commit

Permalink
Merge branch 'bugfix/2579-fix-immutable-field-change-for-prometheus-o…
Browse files Browse the repository at this point in the history
…perator-grafana' into q/2.5
  • Loading branch information
bert-e committed May 29, 2020
2 parents 5567668 + ca69227 commit 2e190f0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions buildchain/buildchain/salt_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ def _get_parts(self) -> Iterator[str]:
Path('salt/metalk8s/addons/prometheus-operator/deployed/',
'service-configuration.sls'),
Path('salt/metalk8s/addons/prometheus-operator/deployed/storageclass.sls'),
Path('salt/metalk8s/addons/prometheus-operator/pre-downgrade.sls'),
Path('salt/metalk8s/addons/prometheus-operator/pre-upgrade.sls'),

Path('salt/metalk8s/addons/ui/deployed/dependencies.sls'),
Path('salt/metalk8s/addons/ui/deployed/ingress.sls'),
Expand Down
26 changes: 26 additions & 0 deletions salt/metalk8s/addons/prometheus-operator/pre-downgrade.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{%- set dest_version = pillar.metalk8s.cluster_version %}

{#- In MetalK8s-2.5.1 the upstream Prometheus-operator chart changed the
MatchLabels selector for prometheus-operator-grafana Deployment
but `selector` are immutable field so, in this case, we cannot replace
the object we need to first remove the current one and then deploy the
desired one. #}
{#- Only do it `if dest_version < 2.5.1` #}
{%- if salt.pkg.version_cmp(dest_version, '2.5.1') == -1 %}

Delete old prometheus-operator-grafana deployment:
metalk8s_kubernetes.object_absent:
- name: prometheus-operator-grafana
- namespace: metalk8s-monitoring
- kind: Deployment
- apiVersion: apps/v1
- wait:
attempts: 10
sleep: 10

{%- else %}

Prometheus-operator-grafana deployment already ready for downgrade:
test.succeed_without_changes: []

{%- endif %}
42 changes: 42 additions & 0 deletions salt/metalk8s/addons/prometheus-operator/pre-upgrade.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{%- set dest_version = pillar.metalk8s.cluster_version %}

{#- In MetalK8s-2.5.1 the upstream Prometheus-operator chart changed the
MatchLabels selector for prometheus-operator-grafana Deployment
but `selector` are immutable field so, in this case, we cannot replace
the object we need to first remove the current one and then deploy the
desired one. #}
{%- set grafana_deployment = salt.metalk8s_kubernetes.get_object(
kind='Deployment',
apiVersion='apps/v1',
name='prometheus-operator-grafana',
namespace='metalk8s-monitoring'
) %}

{#- Only do it `if current_version < 2.5.1` #}
{#- NOTE: If no version consider it's a 2.4.0 or 2.4.1 as version label was
added just after. #}

{%- if grafana_deployment and
salt.pkg.version_cmp(
grafana_deployment.get('metadata', {}).get('labels', {}).get(
'metalk8s.scality.com/version', '2.4.1'
),
'2.5.1'
) == -1 %}

Delete old prometheus-operator-grafana deployment:
metalk8s_kubernetes.object_absent:
- name: prometheus-operator-grafana
- namespace: metalk8s-monitoring
- kind: Deployment
- apiVersion: apps/v1
- wait:
attempts: 10
sleep: 10

{%- else %}

Prometheus-operator-grafana deployment already ready for upgrade:
test.succeed_without_changes: []

{%- endif %}
1 change: 1 addition & 0 deletions salt/metalk8s/orchestrate/downgrade/pre.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
include:
- metalk8s.addons.nginx-ingress.pre-downgrade
- metalk8s.addons.nginx-ingress-control-plane.pre-downgrade
- metalk8s.addons.prometheus-operator.pre-downgrade
1 change: 1 addition & 0 deletions salt/metalk8s/orchestrate/upgrade/pre.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
include:
- metalk8s.addons.nginx-ingress.pre-upgrade
- metalk8s.addons.nginx-ingress-control-plane.pre-upgrade
- metalk8s.addons.prometheus-operator.pre-upgrade
- metalk8s.kubernetes.apiserver.pre-upgrade

0 comments on commit 2e190f0

Please sign in to comment.