///
/// Translate incoming k8 items into KVInputAction against MemStore which contains local state
/// It only generates KVInputAction if incoming k8 object is different from memstore
/// 
///
Translate incoming k8 items into KVInputAction against MemStore which contains local state
It only generates KVInputAction if incoming k8 object is different from memstore
Translate incoming k8 items into KVInputAction against MemStore which contains local state It only generates KVInputAction if incoming k8 object is different from memstore
pub fn k8_events_to_metadata_actions<S>(
    k8_tokens: K8List<S::K8Spec,<S::K8Spec as K8Spec>::Status>,
    local_store: &LocalStore<S>,
) -> Actions<LSChange<S>> 
    where 
        S: Spec + PartialEq + Debug, 
        S::Status: Status + PartialEq + Debug , 
        S::K8Spec: Debug, 
        S::Key: Clone + Ord  + Debug + Display
{
    let (mut add_cnt, mut mod_cnt, mut del_cnt, mut skip_cnt) = (0, 0, 0, 0);
    let mut local_names = local_store.all_keys();
    let all = local_store.count();
    let mut actions: Actions<LSChange<S>> = Actions::default();
    // loop through items and generate add/mod actions
    for k8_obj in k8_tokens.items {
        match k8_obj_to_kv_obj(k8_obj) {
            Ok(new_kv_value) =>  {
                let key = new_kv_value.key_owned();
                if let Some(old_value) = local_store.value(&key) {
                    // object exists
                    if old_value == new_kv_value {
                        skip_cnt += 1; //nothing changed
                    } else {
                        // diff
                        mod_cnt += 1;
                        debug!("adding {}:{} to local store",S::LABEL,new_kv_value.key());
                        local_store.insert(new_kv_value.clone());
                        actions.push(LSChange::update(new_kv_value, old_value));
                    }
                    local_names.retain(|n| *n != key);
                } else {
                    // object doesn't exisit
                    add_cnt += 1;
                    local_store.insert(new_kv_value.clone());
                    actions.push(LSChange::add(new_kv_value));
                }
            },
            Err(err) => {
                error!("{}", err);
                skip_cnt += 1;
            }
        }
    }
    // loop through the remaining names and generate delete actions
    for name in local_names.into_iter() {
        if local_store.contains_key(&name) {
            if let Some(old_value) = local_store.remove(&name) {
                del_cnt += 1;
                actions.push(LSChange::delete(old_value));
            } else {
                skip_cnt += 1;
                error!("delete  should never fail since key exists: {:#?}",name);
            }
        } else {
            skip_cnt += 1;
            error!("kv unexpectedly removed... skipped {:#?}", name);
        }
    }
    // log counters
    trace!(
        "KV {} events => local: {} [add:{}, mod:{}, del:{}, skip:{}]",
        S::LABEL,
        all,
        add_cnt,
        mod_cnt,
        del_cnt,
        skip_cnt
    );
    actions
}
pub fn k8_events_to_metadata_actions < S > ( k8_tokens : K8List < S :: K8Spec , < S :: K8Spec as K8Spec > :: Status > , local_store : & LocalStore < S > , ) -> Actions < LSChange < S > > where S : Spec + PartialEq + Debug , S :: Status : Status + PartialEq + Debug , S :: K8Spec : Debug , S :: Key : Clone + Ord + Debug + Display { let ( mut add_cnt , mut mod_cnt , mut del_cnt , mut skip_cnt ) = ( 0 , 0 , 0 , 0 ) ; let mut local_names = local_store . all_keys ( ) ; let all = local_store . count ( ) ; let mut actions : Actions < LSChange < S > > = Actions :: default ( ) ; // loop through items and generate add/mod actions for k8_obj in k8_tokens . items { match k8_obj_to_kv_obj ( k8_obj ) { Ok ( new_kv_value ) => { let key = new_kv_value . key_owned ( ) ; if let Some ( old_value ) = local_store . value ( & key ) { // object exists if old_value == new_kv_value { skip_cnt += 1 ; //nothing changed } else { // diff mod_cnt += 1 ; debug ! ( " " S LABEL new_kv_value key ( ) ) ; local_store . insert ( new_kv_value . clone ( ) ) ; actions . push ( LSChange :: update ( new_kv_value , old_value ) ) ; } local_names . retain ( | n | * n != key ) ; } else { // object doesn't exisit add_cnt += 1 ; local_store . insert ( new_kv_value . clone ( ) ) ; actions . push ( LSChange :: add ( new_kv_value ) ) ; } } , Err ( err ) => { error ! ( " " err ) ; skip_cnt += 1 ; } } } // loop through the remaining names and generate delete actions for name in local_names . into_iter ( ) { if local_store . contains_key ( & name ) { if let Some ( old_value ) = local_store . remove ( & name ) { del_cnt += 1 ; actions . push ( LSChange :: delete ( old_value ) ) ; } else { skip_cnt += 1 ; error ! ( " " name ) ; } } else { skip_cnt += 1 ; error ! ( " " name ) ; } } // log counters trace ! ( " " S LABEL all add_cnt mod_cnt del_cnt skip_cnt ) ; actions }
Translate incoming k8 items into KVInputAction against MemStore which contains local state
It only generates KVInputAction if incoming k8 object is different from memstore
Translate incoming k8 items into KVInputAction against MemStore which contains local state It only generates KVInputAction if incoming k8 object is different from memstore
k8_tokens
K8List<S::K8Spec,<S::K8Spec as K8Spec>::Status>
local_store
&LocalStore<S>