Skip to content

Commit

Permalink
Set annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Wenjie Ma <[email protected]>
  • Loading branch information
euclidgame committed Sep 19, 2023
1 parent 1da5fd1 commit 2bff80e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/controller_examples/rabbitmq_controller/exec/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ pub fn make_service(rabbitmq: &RabbitmqCluster, name:String, ports: Vec<ServiceP
owner_references
});
metadata.set_labels(make_labels(rabbitmq));
metadata.set_annotations(rabbitmq.spec().annotations());
metadata
});
service.set_spec({
Expand Down Expand Up @@ -570,6 +571,7 @@ pub fn make_secret(rabbitmq: &RabbitmqCluster, name:String , data: StringMap) ->
owner_references
});
metadata.set_labels(make_labels(rabbitmq));
metadata.set_annotations(rabbitmq.spec().annotations());
metadata
});
secret.set_data(data);
Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand All @@ -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
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
Expand Down Expand Up @@ -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({
Expand Down
18 changes: 15 additions & 3 deletions src/controller_examples/rabbitmq_controller/spec/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand All @@ -496,14 +498,17 @@ 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].")@)
)
}

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)
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
)
}

Expand All @@ -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")@]),
Expand All @@ -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")@)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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),
Expand Down

0 comments on commit 2bff80e

Please sign in to comment.