func (stp *stp) AllocateResources(c cache.Container) error {
	containerID := c.GetCacheID()
	stp.Debug("allocating resources for container %s...", containerID)
	cs := stpContainerStatus{Socket: -1}
	poolName := CmkPoolShared
	stp.Debug("RESOURCE REQUESTS: %s", c.GetResourceRequirements().Requests)
	requestedCPUs, ok := c.GetResourceRequirements().Requests[exclusiveCoreResourceName]
	if ok {
		nCPUs, _ := requestedCPUs.AsInt64()
		cs.NExclusiveCPUs = nCPUs
	}
	cmkArgs := stp.parseContainerCmdline(c.GetCommand(), c.GetArgs())
	if cmkArgs != nil {
		poolName = cmkArgs.Pool
		cs.Socket = cmkArgs.SocketID
		cs.NoAffinity = cmkArgs.NoAffinity
		c.SetCommand(cmkArgs.Command)
		c.SetArgs([]string{})
		stp.Debug("parsed options from container command line: %v", cmkArgs)
	}
	envVal, ok := c.GetEnv(StpEnvSocketID)
	if ok {
		socketID, err := strconv.ParseInt(envVal, 10, 32)
		if err != nil {
			stp.Warn("unable to parse socket id from %q: %v", StpEnvSocketID, err)
		} else {
			cs.Socket = socketID
		}
	}
	envVal, ok = c.GetEnv(StpEnvPool)
	if ok {
		poolName = envVal
	}
	_, ok = c.GetEnv(StpEnvNoAffinity)
	if ok {
		cs.NoAffinity = true
	}
	if poolName == CmkPoolInfra {
		cs.Socket = -1
	}
	if _, ok := stp.conf.Pools[poolName]; !ok {
		return stpError("non-existent pool %q", poolName)
	}
	cs.Pool = poolName
	err := stp.allocateStpResources(c, cs)
	if err != nil {
		return err
	}
	return nil
}
AllocateResources is a resource allocation request for this policy.
package stp
import (
	"flag"
	"fmt"
	"io/ioutil"
	"math/rand"
	"strconv"
	"strings"
	pkgcfg "github.com/intel/cri-resource-manager/pkg/config"
	"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/cache"
	"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/events"
	"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/introspect"
	"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/policy"
	logger "github.com/intel/cri-resource-manager/pkg/log"
	"github.com/intel/cri-resource-manager/pkg/utils"
)
const (
	PolicyName = "static-pools"
	PolicyDescription = "A reimplementation of CMK (CPU Manager for Kubernetes)."
	PolicyPath = "policy." + PolicyName
	StpEnvPool = "STP_POOL"
	StpEnvSocketID = "STP_SOCKET_ID"
	StpEnvNoAffinity = "STP_NO_AFFINITY"
	CmkEnvAssigned = "CMK_CPUS_ASSIGNED"
	CmkEnvInfra = "CMK_CPUS_INFRA"
	CmkEnvShared = "CMK_CPUS_SHARED"
	CmkEnvNumCores = "CMK_NUM_CORES"
	CmkPoolInfra = "infra"
	CmkPoolShared = "shared"
)
type stp struct {
	logger.Logger
	conf        *config       
	nodeUpdater *nodeUpdater  
	state       cache.Cache   
}
var _ policy.Backend = &stp{}
func CreateStpPolicy(opts *policy.BackendOptions) policy.Backend {
	stp := &stp{
		Logger:      logger.NewLogger(PolicyName),
		state:       opts.Cache,
		nodeUpdater: newNodeUpdater(opts.AgentCli),
	}
	stp.Info("creating policy...")
	pkgcfg.GetModule(PolicyPath).AddNotify(stp.configNotify)
	return stp
}
func (stp *stp) Name() string {
	return PolicyName
}
func (stp *stp) Description() string {
	return PolicyDescription
}
func (stp *stp) Start(add []cache.Container, del []cache.Container) error {
	if err := stp.nodeUpdater.start(); err != nil {
		return err
	}
	if stp.conf == nil {
		if err := stp.setConfig(conf); err != nil {
			return err
		}
	}
	if err := stp.initializeState(); err != nil {
		return err
	}
	stp.Debug("retrieved stp container states from cache:\n%s", utils.DumpJSON(*stp.getContainerRegistry()))
	if err := stp.Sync(add, del); err != nil {
		return err
	}
	stp.Debug("preparing for making decisions...")
	return nil
}
func (stp *stp) Sync(add []cache.Container, del []cache.Container) error {
	stp.Debug("synchronizing state...")
	for _, c := range del {
		stp.ReleaseResources(c)
	}
	for _, c := range add {
		stp.AllocateResources(c)
	}
	return nil
}