From 4cf98b9305c44e32a82b8145c43506384c62fb2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Levilain?= Date: Mon, 13 Nov 2023 18:08:33 +0100 Subject: [PATCH] fix(shulker-operator): fleet labels not added to GameServers from MinecraftServerFleets --- codecov.yml | 7 +++ .../minecraft_server/gameserver.rs | 36 +++++++----- .../minecraft_server_fleet/fleet.rs | 55 +++++++------------ ...r_fleet__fleet__tests__build_snapshot.snap | 5 +- scripts/upload_codecov_files.sh | 1 + 5 files changed, 51 insertions(+), 53 deletions(-) diff --git a/codecov.yml b/codecov.yml index 05c5d9ca..f448cd67 100644 --- a/codecov.yml +++ b/codecov.yml @@ -13,6 +13,9 @@ coverage: google-agones-crds: flags: - google-agones-crds + google-agones-sdk-bindings-rust: + flags: + - google-agones-sdk-bindings-rust google-open-match-sdk-bindings-rust: flags: - google-open-match-sdk-bindings-rust @@ -39,6 +42,10 @@ flags: paths: - packages/google-agones-crds carryforward: true + google-agones-sdk-bindings-rust: + paths: + - packages/google-agones-sdk/bindings/rust + carryforward: true google-open-match-sdk-bindings-rust: paths: - packages/google-open-match-sdk/bindings/rust diff --git a/packages/shulker-operator/src/reconcilers/minecraft_server/gameserver.rs b/packages/shulker-operator/src/reconcilers/minecraft_server/gameserver.rs index 7232929e..9d433ff7 100644 --- a/packages/shulker-operator/src/reconcilers/minecraft_server/gameserver.rs +++ b/packages/shulker-operator/src/reconcilers/minecraft_server/gameserver.rs @@ -270,23 +270,29 @@ impl GameServerBuilder { pod_spec.tolerations = pod_overrides.tolerations.clone(); } + let mut pod_labels = minecraft_server.labels().clone(); + pod_labels.append(&mut MinecraftServerReconciler::get_labels( + minecraft_server, + "minecraft-server".to_string(), + "minecraft-server".to_string(), + )); + + let mut pod_annotations = minecraft_server.annotations().clone(); + pod_annotations.append(&mut BTreeMap::::from([ + ( + "kubectl.kubernetes.io/default-exec-container".to_string(), + "minecraft-server".to_string(), + ), + ( + "minecraftserver.shulkermc.io/tags".to_string(), + minecraft_server.spec.tags.join(","), + ), + ])); + Ok(PodTemplateSpec { metadata: Some(ObjectMeta { - labels: Some(MinecraftServerReconciler::get_labels( - minecraft_server, - "minecraft-server".to_string(), - "minecraft-server".to_string(), - )), - annotations: Some(BTreeMap::::from([ - ( - "kubectl.kubernetes.io/default-exec-container".to_string(), - "minecraft-server".to_string(), - ), - ( - "minecraftserver.shulkermc.io/tags".to_string(), - minecraft_server.spec.tags.join(","), - ), - ])), + labels: Some(pod_labels), + annotations: Some(pod_annotations), ..ObjectMeta::default() }), spec: Some(pod_spec), diff --git a/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/fleet.rs b/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/fleet.rs index 82361ee9..6569879c 100644 --- a/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/fleet.rs +++ b/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/fleet.rs @@ -57,10 +57,29 @@ impl<'a> ResourceBuilder<'a> for FleetBuilder { config_clone.existing_config_map_name = Some(ConfigMapBuilder::name(minecraft_server_fleet)); + let mut template_labels = MinecraftServerFleetReconciler::get_labels( + minecraft_server_fleet, + "minecraft-server".to_string(), + "minecraft-server".to_string(), + ); + let mut template_annotations = BTreeMap::::new(); + + if let Some(metadata) = &minecraft_server_fleet.spec.template.metadata { + if let Some(additional_labels) = metadata.labels.clone() { + template_labels.extend(additional_labels); + } + + if let Some(additional_annotations) = metadata.annotations.clone() { + template_annotations.extend(additional_annotations); + } + } + let fake_mincraft_server = MinecraftServer { metadata: ObjectMeta { namespace: minecraft_server_fleet.namespace(), name: Some(minecraft_server_fleet.name_any()), + labels: Some(template_labels.clone()), + annotations: Some(template_annotations.clone()), ..ObjectMeta::default() }, spec: MinecraftServerSpec { @@ -86,42 +105,6 @@ impl<'a> ResourceBuilder<'a> for FleetBuilder { None => minecraft_server_fleet.spec.replicas as i32, }; - let mut template_labels = MinecraftServerFleetReconciler::get_labels( - minecraft_server_fleet, - "minecraft-server".to_string(), - "minecraft-server".to_string(), - ); - template_labels.extend( - game_server_spec - .template - .metadata - .as_ref() - .map_or_else(BTreeMap::new, |metadata| { - metadata.labels.clone().unwrap_or_default() - }), - ); - - let mut template_annotations = BTreeMap::::new(); - template_annotations.extend( - game_server_spec - .template - .metadata - .as_ref() - .map_or_else(BTreeMap::new, |metadata| { - metadata.annotations.clone().unwrap_or_default() - }), - ); - - if let Some(metadata) = &minecraft_server_fleet.spec.template.metadata { - if let Some(additional_labels) = metadata.labels.clone() { - template_labels.extend(additional_labels); - } - - if let Some(additional_annotations) = metadata.annotations.clone() { - template_annotations.extend(additional_annotations); - } - } - let fleet = Fleet { metadata: ObjectMeta { name: Some(name.to_string()), diff --git a/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/snapshots/shulker_operator__reconcilers__minecraft_server_fleet__fleet__tests__build_snapshot.snap b/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/snapshots/shulker_operator__reconcilers__minecraft_server_fleet__fleet__tests__build_snapshot.snap index 8920485d..ba7a27b2 100644 --- a/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/snapshots/shulker_operator__reconcilers__minecraft_server_fleet__fleet__tests__build_snapshot.snap +++ b/packages/shulker-operator/src/reconcilers/minecraft_server_fleet/snapshots/shulker_operator__reconcilers__minecraft_server_fleet__fleet__tests__build_snapshot.snap @@ -23,8 +23,6 @@ spec: template: metadata: annotations: - kubectl.kubernetes.io/default-exec-container: minecraft-server - minecraftserver.shulkermc.io/tags: lobby test-annotation/shulkermc.io: my-value labels: app.kubernetes.io/component: minecraft-server @@ -50,6 +48,7 @@ spec: annotations: kubectl.kubernetes.io/default-exec-container: minecraft-server minecraftserver.shulkermc.io/tags: lobby + test-annotation/shulkermc.io: my-value labels: app.kubernetes.io/component: minecraft-server app.kubernetes.io/instance: minecraft-server-my-server @@ -57,6 +56,8 @@ spec: app.kubernetes.io/name: minecraft-server app.kubernetes.io/part-of: cluster-my-cluster minecraftcluster.shulkermc.io/name: my-cluster + minecraftserverfleet.shulkermc.io/name: my-server + test-label/shulkermc.io: my-value spec: containers: - env: diff --git a/scripts/upload_codecov_files.sh b/scripts/upload_codecov_files.sh index e7481d9d..8d0dcf5f 100644 --- a/scripts/upload_codecov_files.sh +++ b/scripts/upload_codecov_files.sh @@ -1,6 +1,7 @@ #!/bin/bash CODECOV="${CODECOV:-codecov}" $CODECOV -t $CODECOV_TOKEN -F google-agones-crds -f ./coverage/rust/google-agones-crds/cobertura.xml +$CODECOV -t $CODECOV_TOKEN -F google-agones-sdk-bindings-rust -f ./coverage/rust/google-agones-sdk-bindings-rust/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F google-open-match-sdk-bindings-rust -f ./coverage/rust/google-open-match-sdk-bindings-rust/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F shulker-addon-matchmaking -f ./coverage/rust/shulker-addon-matchmaking/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F shulker-crds -f ./coverage/rust/shulker-crds/cobertura.xml