func (pl *ProfileLoader) handleNewSecurityProfile(eventProfile *v1.SecurityProfile) error {
	newPV := ProfileVersion{
		UID:             eventProfile.UID,
		ResourceVersion: eventProfile.ResourceVersion,
	}
	profile := ProfileMetadata{
		ProfileVersion: newPV,
		Profile:        eventProfile,
		ContainerIDs:   []string{},
	}
	selector := labels.NewSelector()
	for label, value := range eventProfile.Labels {
		req, err := labels.NewRequirement(
			label,
			selection.In,
			[]string{value},
		)
		if err != nil {
			return err
		}
		selector = selector.Add(*req)
	}
	// Loop through all the containers and check if their profiles need to be updated
	for _, container := range pl.RunningContainers {
		shouldCommit := false
		// Check versions
		if newPV.HasSameUID(container.ProfileVersion) && !newPV.HasSameResourceVersion(container.ProfileVersion) {
			shouldCommit = true
		}
		// If the container doesn't have a profile currently, check if its flags match the profile
		if container.ProfileVersion.IsEmpty() {
			if selector.Matches(container.Labels) {
				shouldCommit = true
			}
		}
		// Commit profile to container if applicable
		if shouldCommit {
			if err := pl.CommitSecurityProfile(&profile, container); err != nil {
				profileLoaderLogger.Warn(err)
			}
		}
	}
	// If the profile was applied to a container, add it to the list of loaded profiles
	if len(profile.ContainerIDs) > 0 {
		pl.LoadedProfiles[newPV] = &profile
	}
	return nil
}
// handleSecurityProfileUpdate - Handles a security profile update
Handles a security profile update
// handleSecurityProfileUpdate - Handles a security profile update
func (pl *ProfileLoader) handleNewSecurityProfile(eventProfile *v1.SecurityProfile) error {
	newPV := ProfileVersion{
		UID:             eventProfile.UID,
		ResourceVersion: eventProfile.ResourceVersion,
	}
	profile := ProfileMetadata{
		ProfileVersion: newPV,
		Profile:        eventProfile,
		ContainerIDs:   []string{},
	}
	selector := labels.NewSelector()
	for label, value := range eventProfile.Labels {
		req, err := labels.NewRequirement(
			label,
			selection.In,
			[]string{value},
		)
		if err != nil {
			return err
		}
		selector = selector.Add(*req)
	}
	for _, container := range pl.RunningContainers {
		shouldCommit := false
		if newPV.HasSameUID(container.ProfileVersion) && !newPV.HasSameResourceVersion(container.ProfileVersion) {
			shouldCommit = true
		}
		if container.ProfileVersion.IsEmpty() {
			if selector.Matches(container.Labels) {
				shouldCommit = true
			}
		}
		if shouldCommit {
			if err := pl.CommitSecurityProfile(&profile, container); err != nil {
				profileLoaderLogger.Warn(err)
			}
		}
	}
	if len(profile.ContainerIDs) > 0 {
		pl.LoadedProfiles[newPV] = &profile
	}
	return nil
}
func ( pl * ProfileLoader ) handleNewSecurityProfile ( eventProfile * v1 . SecurityProfile ) error { newPV := ProfileVersion { UID : eventProfile . UID , ResourceVersion : eventProfile . ResourceVersion , } profile := ProfileMetadata { ProfileVersion : newPV , Profile : eventProfile , ContainerIDs : [ ] string { } , } selector := labels . NewSelector ( ) for label , value := range eventProfile . Labels { req , err := labels . NewRequirement ( label , selection . In , [ ] string { value } , ) if err != nil { return err } selector = selector . Add ( * req ) } for _ , container := range pl . RunningContainers { shouldCommit := false if newPV . HasSameUID ( container . ProfileVersion ) && ! newPV . HasSameResourceVersion ( container . ProfileVersion ) { shouldCommit = true } if container . ProfileVersion . IsEmpty ( ) { if selector . Matches ( container . Labels ) { shouldCommit = true } } if shouldCommit { if err := pl . CommitSecurityProfile ( & profile , container ) ; err != nil { profileLoaderLogger . Warn ( err ) } } } if len ( profile . ContainerIDs ) > 0 { pl . LoadedProfiles [ newPV ] = & profile } return nil }
Handles a security profile update
Handles a security profile update
// Loop through all the containers and check if their profiles need to be updated // Check versions // If the container doesn't have a profile currently, check if its flags match the profile // Commit profile to container if applicable // If the profile was applied to a container, add it to the list of loaded profiles