Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reconcile/gql_definitions/common/clusters.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
query Clusters($name: String) {
clusters: clusters_v1(name: $name) {
path
labels
name
description
serverUrl
Expand Down
2 changes: 2 additions & 0 deletions reconcile/gql_definitions/common/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
query Clusters($name: String) {
clusters: clusters_v1(name: $name) {
path
labels
name
description
serverUrl
Expand Down Expand Up @@ -626,6 +627,7 @@ class DisableClusterAutomationsV1(ConfiguredBaseModel):

class ClusterV1(ConfiguredBaseModel):
path: str = Field(..., alias="path")
labels: Optional[Json] = Field(..., alias="labels")
name: str = Field(..., alias="name")
description: Optional[str] = Field(..., alias="description")
server_url: str = Field(..., alias="serverUrl")
Expand Down
13 changes: 13 additions & 0 deletions reconcile/openshift_upgrade_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ def notify_upgrades_start(
state_key=state_key,
state_value=None,
)
if slack and cluster.labels and "notifications" in cluster.labels:
notification_channels = cluster.labels["notifications"].split(",")
for notification_channel in notification_channels:
default_channel = slack.channel
slack.channel = notification_channel
handle_slack_notification(
msg=msg,
slack=slack,
state=state,
state_key=state_key,
state_value=None,
)
slack.channel = default_channel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another notification in notify_cluster_new_version, should it support multiple channels too? Then this channel change should be handled in one level above.



def notify_cluster_new_version(
Expand Down
40 changes: 40 additions & 0 deletions reconcile/test/test_openshift_upgrade_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,46 @@ def test_new_upgrade_notify(
assert state.add.call_count == 1


def test_new_upgrade_notify_multiple_channels(
mocker: MockerFixture,
state: MagicMock,
slack: MagicMock,
ouw_oc_map: MagicMock,
ouw_ocm_map: MagicMock,
upgrade_config: dict[str, Any],
mock_utc_now: MagicMock,
) -> None:
"""There is an UpgradeConfig on the cluster, its upgradeAt is in the past,
there are multiple channels, and we did not already notify"""
mock_utc_now.return_value = upgrade_at + timedelta(hours=1)
gso = mocker.patch(
"reconcile.openshift_upgrade_watcher._get_start_osd", autospec=True
)
gso.return_value = upgrade_at.strftime("%Y-%m-%dT%H:%M:%SZ"), upgrade_version
state.exists.return_value = False
cluster = load_cluster("cluster1.yml")

cluster.labels = {"notifications": "team-a-alert"}
ouw.notify_upgrades_start(
ocm_map=ouw_ocm_map,
oc_map=ouw_oc_map,
clusters=[cluster],
state=state,
slack=slack,
)
assert slack.chat_post_message.call_count == 2

cluster.labels = {"notifications": "team-a-alert,team-b-alert"}
ouw.notify_upgrades_start(
ocm_map=ouw_ocm_map,
oc_map=ouw_oc_map,
clusters=[cluster],
state=state,
slack=slack,
)
assert slack.chat_post_message.call_count == 3


def test_new_upgrade_already_notified(
mocker: MockerFixture,
state: MagicMock,
Expand Down