func (pl *ProfileLoader) handleSecurityProfileDeletion(event *model.SecurityProfileDeletedEvent) error {
	// This resource can exist in multiple version, this list will contain all the ProfileVersions to delete.
	pvsToDelete := ProfileVersionSet{}
	// Check if the profile is used locally
	profile := ProfileMetadata{
		ProfileVersion: ProfileVersion{
			UID:             event.Profile.UID,
			ResourceVersion: event.Profile.ResourceVersion,
		},
		Profile:      event.Profile,
		ContainerIDs: []string{},
	}
	for containerID, container := range pl.RunningContainers {
		// check if the profile UID match
		if container.ProfileVersion.UID != event.Profile.UID {
			continue
		} else {
			pvsToDelete.Add(container.ProfileVersion)
		}
		// Delete profile mappings
		if err := pl.DeleteProfileMappings(&profile, container); err != nil {
			profileLoaderLogger.Warnf("couldn't delete profile mappings for containerID %s: %v", containerID, err)
			continue
		}
		container.ProfileVersion = ProfileVersion{}
	}
	// Delete all detected versions of this security profile
	for _, pv := range pvsToDelete {
		profileToDelete, ok := pl.LoadedProfiles[pv]
		if !ok {
			continue
		}
		// Delete the profile from the kernel
		if err := pl.DeleteSecurityProfile(profileToDelete.Profile); err != nil {
			profileLoaderLogger.Warnf("couldn't delete security profile %s from kernel: %v", pv.UID, err)
		}
		// Delete profile from the list of loaded profiles
		delete(pl.LoadedProfiles, pv)
	}
	return nil
}
// handleSecurityProfileDeletion - Handles a security profile deletion
Handles a security profile deletion
// handleSecurityProfileDeletion - Handles a security profile deletion
func (pl *ProfileLoader) handleSecurityProfileDeletion(event *model.SecurityProfileDeletedEvent) error {
	pvsToDelete := ProfileVersionSet{}
	profile := ProfileMetadata{
		ProfileVersion: ProfileVersion{
			UID:             event.Profile.UID,
			ResourceVersion: event.Profile.ResourceVersion,
		},
		Profile:      event.Profile,
		ContainerIDs: []string{},
	}
	for containerID, container := range pl.RunningContainers {
		if container.ProfileVersion.UID != event.Profile.UID {
			continue
		} else {
			pvsToDelete.Add(container.ProfileVersion)
		}
		if err := pl.DeleteProfileMappings(&profile, container); err != nil {
			profileLoaderLogger.Warnf("couldn't delete profile mappings for containerID %s: %v", containerID, err)
			continue
		}
		container.ProfileVersion = ProfileVersion{}
	}
	for _, pv := range pvsToDelete {
		profileToDelete, ok := pl.LoadedProfiles[pv]
		if !ok {
			continue
		}
		if err := pl.DeleteSecurityProfile(profileToDelete.Profile); err != nil {
			profileLoaderLogger.Warnf("couldn't delete security profile %s from kernel: %v", pv.UID, err)
		}
		delete(pl.LoadedProfiles, pv)
	}
	return nil
}
func ( pl * ProfileLoader ) handleSecurityProfileDeletion ( event * model . SecurityProfileDeletedEvent ) error { pvsToDelete := ProfileVersionSet { } profile := ProfileMetadata { ProfileVersion : ProfileVersion { UID : event . Profile . UID , ResourceVersion : event . Profile . ResourceVersion , } , Profile : event . Profile , ContainerIDs : [ ] string { } , } for containerID , container := range pl . RunningContainers { if container . ProfileVersion . UID != event . Profile . UID { continue } else { pvsToDelete . Add ( container . ProfileVersion ) } if err := pl . DeleteProfileMappings ( & profile , container ) ; err != nil { profileLoaderLogger . Warnf ( " " , containerID , err ) continue } container . ProfileVersion = ProfileVersion { } } for _ , pv := range pvsToDelete { profileToDelete , ok := pl . LoadedProfiles [ pv ] if ! ok { continue } if err := pl . DeleteSecurityProfile ( profileToDelete . Profile ) ; err != nil { profileLoaderLogger . Warnf ( " " , pv . UID , err ) } delete ( pl . LoadedProfiles , pv ) } return nil }
Handles a security profile deletion
Handles a security profile deletion
// This resource can exist in multiple version, this list will contain all the ProfileVersions to delete. // Check if the profile is used locally // check if the profile UID match // Delete profile mappings // Delete all detected versions of this security profile // Delete the profile from the kernel // Delete profile from the list of loaded profiles