From 2bff80eab69bfdb5557a62250e3dfeffef08527b Mon Sep 17 00:00:00 2001 From: Wenjie Ma Date: Mon, 18 Sep 2023 22:21:45 -0500 Subject: [PATCH] Set annotations Signed-off-by: Wenjie Ma --- .../rabbitmq_controller/exec/reconciler.rs | 18 ++++++++++++++++-- .../rabbitmq_controller/spec/reconciler.rs | 18 +++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/controller_examples/rabbitmq_controller/exec/reconciler.rs b/src/controller_examples/rabbitmq_controller/exec/reconciler.rs index a04a57aac..196fd8a95 100644 --- a/src/controller_examples/rabbitmq_controller/exec/reconciler.rs +++ b/src/controller_examples/rabbitmq_controller/exec/reconciler.rs @@ -485,6 +485,7 @@ pub fn make_service(rabbitmq: &RabbitmqCluster, name:String, ports: Vec owner_references }); metadata.set_labels(make_labels(rabbitmq)); + metadata.set_annotations(rabbitmq.spec().annotations()); metadata }); secret.set_data(data); @@ -600,6 +602,7 @@ fn make_plugins_config_map(rabbitmq: &RabbitmqCluster) -> (config_map: ConfigMap owner_references }); metadata.set_labels(make_labels(rabbitmq)); + metadata.set_annotations(rabbitmq.spec().annotations()); metadata }); let mut data = StringMap::empty(); @@ -625,6 +628,7 @@ ensures ); } let mut metadata = found_config_map.metadata(); + let made_server_cm = make_server_config_map(rabbitmq); // Since we requirement the owner_reference only contains current cr, this set operation won't change anything. // Similarly, we never set finalizers for any stateful set, resetting finalizers won't change anything. @@ -633,7 +637,9 @@ ensures // for stateful set are. metadata.set_owner_references(owner_references); metadata.unset_finalizers(); - found_config_map.set_data(make_server_config_map(rabbitmq).data().unwrap()); + metadata.set_labels(made_server_cm.metadata().labels().unwrap()); + metadata.set_annotations(made_server_cm.metadata().annotations().unwrap()); + found_config_map.set_data(made_server_cm.data().unwrap()); found_config_map.set_metadata(metadata); found_config_map } @@ -662,6 +668,7 @@ fn make_server_config_map(rabbitmq: &RabbitmqCluster) -> (config_map: ConfigMap) owner_references }); metadata.set_labels(make_labels(rabbitmq)); + metadata.set_annotations(rabbitmq.spec().annotations()); metadata }); let mut data = StringMap::empty(); @@ -729,6 +736,7 @@ fn make_service_account(rabbitmq: &RabbitmqCluster) -> (service_account: Service owner_references }); metadata.set_labels(make_labels(rabbitmq)); + metadata.set_annotations(rabbitmq.spec().annotations()); metadata }); service_account @@ -758,6 +766,7 @@ fn make_role(rabbitmq: &RabbitmqCluster) -> (role: Role) owner_references }); metadata.set_labels(make_labels(rabbitmq)); + metadata.set_annotations(rabbitmq.spec().annotations()); metadata }); role.set_policy_rules({ @@ -871,6 +880,7 @@ fn make_role_binding(rabbitmq: &RabbitmqCluster) -> (role_binding: RoleBinding) owner_references }); metadata.set_labels(make_labels(rabbitmq)); + metadata.set_annotations(rabbitmq.spec().annotations()); metadata }); role_binding.set_role_ref({ @@ -916,6 +926,7 @@ fn update_stateful_set(rabbitmq: &RabbitmqCluster, mut found_stateful_set: State ); } let mut metadata = found_stateful_set.metadata(); + let made_sts = make_stateful_set(rabbitmq, config_map_rv); // Since we requirement the owner_reference only contains current cr, this set operation won't change anything. // Similarly, we never set finalizers for any stateful set, resetting finalizers won't change anything. @@ -924,7 +935,9 @@ fn update_stateful_set(rabbitmq: &RabbitmqCluster, mut found_stateful_set: State // for stateful set are. metadata.set_owner_references(owner_references); metadata.unset_finalizers(); - found_stateful_set.set_spec(make_stateful_set(rabbitmq, config_map_rv).spec().unwrap()); + metadata.set_labels(made_sts.metadata().labels().unwrap()); + metadata.set_annotations(made_sts.metadata().annotations().unwrap()); + found_stateful_set.set_spec(made_sts.spec().unwrap()); found_stateful_set.set_metadata(metadata); found_stateful_set } @@ -970,6 +983,7 @@ fn make_stateful_set(rabbitmq: &RabbitmqCluster, config_map_rv: &String) -> (sta owner_references }); metadata.set_labels(make_labels(rabbitmq)); + metadata.set_annotations(rabbitmq.spec().annotations()); metadata }); stateful_set.set_spec({ diff --git a/src/controller_examples/rabbitmq_controller/spec/reconciler.rs b/src/controller_examples/rabbitmq_controller/spec/reconciler.rs index 46626706a..11e752210 100644 --- a/src/controller_examples/rabbitmq_controller/spec/reconciler.rs +++ b/src/controller_examples/rabbitmq_controller/spec/reconciler.rs @@ -424,6 +424,7 @@ pub open spec fn make_service( .set_namespace(rabbitmq.metadata.namespace.get_Some_0()) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations) ).set_spec({ let spec = ServiceSpecView::default() .set_ports(ports) @@ -482,6 +483,7 @@ pub open spec fn make_secret( .set_namespace(rabbitmq.metadata.namespace.get_Some_0()) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations) ).set_data(data) } @@ -496,6 +498,7 @@ pub open spec fn make_plugins_config_map(rabbitmq: RabbitmqClusterView) -> Confi .set_namespace(rabbitmq.metadata.namespace.get_Some_0()) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations) ) .set_data(Map::empty() .insert(new_strlit("enabled_plugins")@, new_strlit("[rabbitmq_peer_discovery_k8s,rabbitmq_management].")@) @@ -503,7 +506,9 @@ pub open spec fn make_plugins_config_map(rabbitmq: RabbitmqClusterView) -> Confi } pub open spec fn update_server_config_map(rabbitmq: RabbitmqClusterView, found_config_map: ConfigMapView) -> ConfigMapView { - let metadata = found_config_map.metadata.set_owner_references(seq![rabbitmq.controller_owner_ref()]).unset_finalizers(); + let metadata = found_config_map.metadata.set_owner_references(seq![rabbitmq.controller_owner_ref()]).unset_finalizers() + .set_labels(make_server_config_map(rabbitmq).metadata.labels.get_Some_0()) + .set_annotations(make_server_config_map(rabbitmq).metadata.annotations.get_Some_0()); found_config_map.set_data(make_server_config_map(rabbitmq).data.get_Some_0()).set_metadata(metadata) } @@ -533,6 +538,7 @@ pub open spec fn make_server_config_map(rabbitmq: RabbitmqClusterView) -> Config .set_namespace(rabbitmq.metadata.namespace.get_Some_0()) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations) ) .set_data(Map::empty() .insert(new_strlit("operatorDefaults.conf")@, default_rbmq_config(rabbitmq)) @@ -578,6 +584,7 @@ pub open spec fn make_service_account(rabbitmq: RabbitmqClusterView) -> ServiceA .set_namespace(rabbitmq.metadata.namespace.get_Some_0()) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations) ) } @@ -592,6 +599,7 @@ pub open spec fn make_role(rabbitmq: RabbitmqClusterView) -> RoleView .set_namespace(rabbitmq.metadata.namespace.get_Some_0()) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations) ).set_policy_rules( seq![ PolicyRuleView::default().set_api_groups(seq![new_strlit("")@]).set_resources(seq![new_strlit("endpoints")@]).set_verbs(seq![new_strlit("get")@]), @@ -611,6 +619,7 @@ pub open spec fn make_role_binding(rabbitmq: RabbitmqClusterView) -> RoleBinding .set_namespace(rabbitmq.metadata.namespace.get_Some_0()) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations) ).set_role_ref(RoleRefView::default() .set_api_group(new_strlit("rbac.authorization.k8s.io")@) .set_kind(new_strlit("Role")@) @@ -644,7 +653,9 @@ pub open spec fn update_stateful_set( rabbitmq.metadata.name.is_Some(), rabbitmq.metadata.namespace.is_Some(), { - let metadata = found_stateful_set.metadata.set_owner_references(seq![rabbitmq.controller_owner_ref()]).unset_finalizers(); + let metadata = found_stateful_set.metadata.set_owner_references(seq![rabbitmq.controller_owner_ref()]).unset_finalizers() + .set_labels(make_stateful_set(rabbitmq, config_map_rv).metadata.labels.get_Some_0()) + .set_annotations(make_stateful_set(rabbitmq, config_map_rv).metadata.annotations.get_Some_0()); found_stateful_set.set_spec(make_stateful_set(rabbitmq, config_map_rv).spec.get_Some_0()).set_metadata(metadata) } @@ -666,7 +677,8 @@ pub open spec fn make_stateful_set(rabbitmq: RabbitmqClusterView, config_map_rv: .set_name(sts_name) .set_namespace(namespace) .set_owner_references(seq![rabbitmq.controller_owner_ref()]) - .set_labels(make_labels(rabbitmq)); + .set_labels(make_labels(rabbitmq)) + .set_annotations(rabbitmq.spec.annotations); let spec = StatefulSetSpecView { replicas: Some(rabbitmq.spec.replicas),