func (ins *Instance) PolicyUpdate(resp *envoy_service_disacovery.DiscoveryResponse) (err error) {
	defer func() {
		if r := recover(); r != nil {
			var ok bool
			if err, ok = r.(error); !ok {
				err = fmt.Errorf("NPDS: Panic: %v", r)
			}
		}
	}()

	log.Debugf("NPDS: Updating policy from %v", resp)

	oldMap := ins.getPolicyMap()
	newMap := newPolicyMap()

	for _, any := range resp.Resources {
		if any.TypeUrl != resp.TypeUrl {
			return fmt.Errorf("NPDS: Mismatching TypeUrls: %s != %s", any.TypeUrl, resp.TypeUrl)
		}
		var config cilium.NetworkPolicy
		if err = proto.Unmarshal(any.Value, &config); err != nil {
			return fmt.Errorf("NPDS: Policy unmarshal error: %v", err)
		}

		policyName := config.GetName()

		// Locate the old version, if any
		oldPolicy, found := oldMap[policyName]
		if found {
			// Check if the new policy is the same as the old one
			if proto.Equal(&config, oldPolicy.protobuf) {
				log.Debugf("NPDS: New policy for %s is equal to the old one, no need to change", policyName)
				newMap[policyName] = oldPolicy
				continue
			}
		}

		// Validate new config
		if err = config.Validate(); err != nil {
			return fmt.Errorf("NPDS: Policy validation error for %s: %v", policyName, err)
		}

		// Create new PolicyInstance, may panic. Takes ownership of 'config'.
		newMap[policyName] = newPolicyInstance(&config)
	}

	// Store the new policy map
	ins.setPolicyMap(newMap)

	log.Debugf("NPDS: Policy Update completed for instance %d: %v", ins.id, newMap)
	return
}
// Update the PolicyMap from a protobuf. PolicyMap is only ever changed if the whole update is successful.
Update the PolicyMap from a protobuf. PolicyMap is only ever changed if the whole update is successful.
// Update the PolicyMap from a protobuf . PolicyMap is only ever changed if the whole update is successful .
func (ins *Instance) PolicyUpdate(resp *envoy_service_disacovery.DiscoveryResponse) (err error) {
	defer func() {
		if r := recover(); r != nil {
			var ok bool
			if err, ok = r.(error); !ok {
				err = fmt.Errorf("NPDS: Panic: %v", r)
			}
		}
	}()
	log.Debugf("NPDS: Updating policy from %v", resp)
	oldMap := ins.getPolicyMap()
	newMap := newPolicyMap()
	for _, any := range resp.Resources {
		if any.TypeUrl != resp.TypeUrl {
			return fmt.Errorf("NPDS: Mismatching TypeUrls: %s != %s", any.TypeUrl, resp.TypeUrl)
		}
		var config cilium.NetworkPolicy
		if err = proto.Unmarshal(any.Value, &config); err != nil {
			return fmt.Errorf("NPDS: Policy unmarshal error: %v", err)
		}
		policyName := config.GetName()
		oldPolicy, found := oldMap[policyName]
		if found {
			if proto.Equal(&config, oldPolicy.protobuf) {
				log.Debugf("NPDS: New policy for %s is equal to the old one, no need to change", policyName)
				newMap[policyName] = oldPolicy
				continue
			}
		}
		if err = config.Validate(); err != nil {
			return fmt.Errorf("NPDS: Policy validation error for %s: %v", policyName, err)
		}
		newMap[policyName] = newPolicyInstance(&config)
	}
	ins.setPolicyMap(newMap)
	log.Debugf("NPDS: Policy Update completed for instance %d: %v", ins.id, newMap)
	return
}
func ( ins * Instance ) PolicyUpdate ( resp * envoy_service_disacovery . DiscoveryResponse ) ( err error ) { defer func ( ) { if r := recover ( ) ; r != nil { var ok bool if err , ok = r . ( error ) ; ! ok { err = fmt . Errorf ( " " , r ) } } } ( ) log . Debugf ( " " , resp ) oldMap := ins . getPolicyMap ( ) newMap := newPolicyMap ( ) for _ , any := range resp . Resources { if any . TypeUrl != resp . TypeUrl { return fmt . Errorf ( " " , any . TypeUrl , resp . TypeUrl ) } var config cilium . NetworkPolicy if err = proto . Unmarshal ( any . Value , & config ) ; err != nil { return fmt . Errorf ( " " , err ) } policyName := config . GetName ( ) oldPolicy , found := oldMap [ policyName ] if found { if proto . Equal ( & config , oldPolicy . protobuf ) { log . Debugf ( " " , policyName ) newMap [ policyName ] = oldPolicy continue } } if err = config . Validate ( ) ; err != nil { return fmt . Errorf ( " " , policyName , err ) } newMap [ policyName ] = newPolicyInstance ( & config ) } ins . setPolicyMap ( newMap ) log . Debugf ( " " , ins . id , newMap ) return }
Update the PolicyMap from a protobuf.
Update the PolicyMap from a protobuf .
// Locate the old version, if any // Check if the new policy is the same as the old one // Validate new config // Create new PolicyInstance, may panic. Takes ownership of 'config'. // Store the new policy map