Documentation
¶
Overview ¶
Package networktask runs network manager tasks as AAP jobs and tracks them in a CR's status.jobs (network manager integration contract §4.3-§4.9). One Engine, created in cmd/main.go with New, is shared by every controller.
What the engine does ¶
- Launch: Run records the next attempt as {state: Running, jobID: ""} with a resourceVersion-conditional status update (a conflict or a stale cached object launches nothing and is returned as an error: requeue and do not write the object again), ensures the label osac-<task>-<manager>-<API ID>-<attempt> in the AAP organization, launches the job template <prefix>-<task with dashes> with {osac_job_vars: Vars + {task, manager: {name, type, ansible_role}}} and writes the jobID. A task outside the manager type's fixed set (FabricTasks, KubernetesTasks) is rejected before any launch.
- Tracking: Run reads the job and maps its end (contract §4.6, §4.7): successful runs the Request's AcceptFunc and marks the entry Succeeded in the same status write as the accepted outputs, or Failed with "OSAC rejected the <task> result: <reason>"; failed with a retryable osac_error, AAP error, the AAP timeout, a lost job (404) and a job AAP never started (cancelled after 30 minutes) become Retrying with backoff; other failures are Failed; a job cancelled by hand is launched again at once. Before cancelling a job AAP never started, the engine writes MessageNotStarted to the Running entry, so that AAP's canceled status is mapped to the retry and not to a cancel by hand, even after a restart. Cleanup tasks (delete_, detach_, release_, remove_, deprovision) are retried after every failure. A Running entry with an empty jobID is resolved by its label (lowest job ID tracked, others cancelled; absent for 2 minutes: launched again, or Cancelled while deleting).
- Backoff: min(2m * 2^(n-1), 30m) after the n-th consecutive failure, counted in memory and seeded from the attempt after a restart (decision 7); query_dhcp_lease waits 30 s, and 5 min from its 20th attempt. The entry message is "<task> (<manager>) attempt <n> failed: <msg>; next retry at <RFC3339>".
- Held launch: with Request.HoldLaunch, for a caller whose Vars are not complete for a launch, Run starts no job and only tracks one in progress. A Running entry that would be launched again (cancelled by hand, or lost) becomes Cancelled, so that LaunchDue reports it. A caller that launches only after a check (a storage gate) asks LaunchDue first and then holds every Run it did not check for.
- Deletion: no non-cleanup job starts while the object (or, with Request.TargetDeleting, its target) is being deleted. With Request.TargetDeleting a running non-cleanup job is cancelled in AAP and its entry becomes Cancelled once AAP reports its end (BMaaS apply/query at the BMI deletionTimestamp, CaaS publish jobs of a deleted automatic ExternalIPAttachment). CancelForDelete cancels every running non-cleanup job of the object and reports when the delete may start. A Running entry whose job was not found by its label for 2 minutes becomes Cancelled with an empty jobID; every later CancelForDelete looks its label up again and cancels a job AAP created after all, until the finalizer is removed. A job that AAP creates only after the finalizer is gone is not seen: delete-wins then relies on the managers' tombstones.
How a controller uses it ¶
A networking resource controller reconciles roughly like this:
// Create, once the parent is Ready (copy managers and network type first).
if eng := r.Engine; !eng.ProvisioningEnabled() {
networktask.SetProvisioningDisabled(obj, networktask.CreateSubnet) // no job; delete removes the finalizer
...
}
input, _ := networktask.LoadInput(subnet)
if input == nil { // first job: capture the input once
resource, _ := networktask.Snapshot(subnet, "Subnet", subnet.Spec, "ipv4Cidr")
input = networktask.NewInput(subnet, "Subnet", resource)
input["virtual_network"] = vnSnapshot // Snapshot(vn, "VirtualNetwork", vn.Spec, "ipv4Cidr")
ipam, _ := networktask.Layout(subnet.Spec.IPv4CIDR, subnet.Spec.AddressPlan)
input["ipam"] = networktask.IPAMVars(ipam)
before = func() error { subnet.Status.IPAM = ipam; return networktask.StoreInput(subnet, input) }
}
out, err := eng.Run(ctx, subnet, networktask.Request{
Task: networktask.CreateSubnet, Manager: v1alpha1.NetworkJobManagerFabric,
ManagerRef: subnet.Status.NetworkManagers.Fabric, Kind: "Subnet",
Vars: networktask.WithLaunchKeys(input, map[string]any{"network_type": "evpn"}),
BeforeLaunch: before, // lands in the same write as the first Running entry
Slot: &networktask.SubnetSlot{VirtualNetworkID: subnet.Spec.VirtualNetwork},
SerializeVNI: true,
Accept: func(ctx context.Context, res networktask.Result) error {
return networktask.AcceptSegment(ctx, eng.APIReader(), subnet, "evpn", res)
},
})
if err != nil { return ctrl.Result{}, err }
switch {
case out.Succeeded(): // next task (Kubernetes create_subnet with network_segment)
case out.Failed(): networktask.SetFailed(subnet, out.Entry.Message)
default: networktask.SetProgressing(subnet, networktask.ProgressMessage(out.Entry))
}
return ctrl.Result{RequeueAfter: out.RequeueAfter}, ...
On delete: call CancelForDelete until it returns true, then Run the cleanup task of each manager whose create started (Started), in reverse manager order, and remove the finalizer once all succeeded (none started: remove it at once). Call Forget(uid) after the finalizer is gone.
Results: AcceptNoOutput (default), ParseBackendID, ParseVirtualNetworkResult, ParseNetworkSegment and AcceptSegment, ParseDHCPLease, ParseExternalIP, ParseClusterIngress and ParseVMAttachment validate the typed outputs of contract §4.10; each returns a RejectError naming only the broken rule.
EVPN (EP #427): the Fabric create_virtual_network returns the L3 VNI (ParseVirtualNetworkResult, recorded in VirtualNetwork status.l3Vni) and the Fabric create_subnet returns network_segment {type, l2_vni}. The Subnet and NetworkAttachment inputs store the VirtualNetwork snapshot with status.l3Vni; network_segment is a launch key and never stored.
A SecurityGroup rule update stores the new input with StoreInput and calls MarkForRerun for each recorded manager in the same status write that sets the Updating (or Progressing) reason; Run then launches the next attempt at once. When the Fabric run fails finally, Cancel the Kubernetes entry.
Jobs with manager none (VMaaS provision/deprovision, CaaS guest endpoint jobs) use the same Run with Request.Template set; their Vars become osac_job_vars plus task.
Index ¶
- Constants
- Variables
- func APIID(obj client.Object, kind string) string
- func AcceptNoOutput(_ context.Context, result Result) error
- func AcceptSegment(ctx context.Context, reader client.Reader, subnet *v1alpha1.Subnet, ...) error
- func AcceptSubnetEligibility(subnet *v1alpha1.Subnet, result Result) error
- func Backoff(task string, failures int, attempt int32) time.Duration
- func Cancel(obj v1alpha1.NetworkTaskObject, task string, ...)
- func CheckVNIUnique(ctx context.Context, reader client.Reader, namespace, selfUID string, ...) error
- func DisabledMessage(task string) string
- func FindJob(jobs []v1alpha1.NetworkJobStatus, task string, ...) *v1alpha1.NetworkJobStatus
- func IDLabel(kind string) string
- func IPAMVars(ipam *v1alpha1.SubnetIPAM) map[string]any
- func IsCleanupTask(task string) bool
- func IsConflict(err error) bool
- func JobLabel(task string, manager v1alpha1.NetworkJobManager, apiID string, attempt int32) string
- func Layout(cidr string, plan v1alpha1.SubnetAddressPlan) (*v1alpha1.SubnetIPAM, error)
- func LoadInput(obj v1alpha1.NetworkInputObject) (map[string]any, error)
- func ManagerRef(managers *v1alpha1.NetworkManagers, manager v1alpha1.NetworkJobManager) *v1alpha1.NetworkManagerRef
- func ManagerVars(ref *v1alpha1.NetworkManagerRef, manager v1alpha1.NetworkJobManager) map[string]any
- func NewInput(obj client.Object, kind string, resource map[string]any) map[string]any
- func ParseBackendID(result Result) (string, error)
- func ParseClusterIngress(result Result, subnetCIDR string, ipam *v1alpha1.SubnetIPAM, accepted string) (string, error)
- func ParseDHCPLease(result Result, inputMAC, subnetCIDR string, ipam *v1alpha1.SubnetIPAM) (*v1alpha1.NetworkAttachmentDHCPLease, error)
- func ParseExternalIP(result Result, poolCIDR string) (string, error)
- func ParseNetworkSegment(result Result, networkType string) (*v1alpha1.NetworkSegment, error)
- func ParseVMAttachment(ctx context.Context, apiReader client.Reader, result Result, tenant string) (*v1alpha1.NetworkAttachmentVMAttachment, error)
- func ParseVirtualNetworkResult(result Result, networkType string) (string, int32, error)
- func ProgressMessage(entry v1alpha1.NetworkJobStatus) string
- func Reject(format string, args ...any) error
- func RetryMessage(entry v1alpha1.NetworkJobStatus, message string, at time.Time) string
- func SegmentVars(segment *v1alpha1.NetworkSegment) map[string]any
- func SetFailed(obj v1alpha1.NetworkResourceObject, message string) bool
- func SetProgressing(obj v1alpha1.NetworkResourceObject, message string) bool
- func SetProvisioningDisabled(obj v1alpha1.NetworkResourceObject, task string) bool
- func SetReady(obj v1alpha1.NetworkResourceObject, status metav1.ConditionStatus, ...) bool
- func SetSucceeded(obj v1alpha1.NetworkResourceObject) bool
- func Snapshot(obj client.Object, kind string, spec any, fields ...string) (map[string]any, error)
- func Started(obj v1alpha1.NetworkTaskObject, task string, ...) bool
- func StoreInput(obj v1alpha1.NetworkInputObject, input map[string]any) error
- func Succeeded(obj v1alpha1.NetworkTaskObject, task string, ...) bool
- func TemplateName(prefix, task string) string
- func ValidateTask(task string, manager v1alpha1.NetworkJobManager) error
- func WithLaunchKeys(input map[string]any, keys map[string]any) map[string]any
- type AAPClient
- type AcceptFunc
- type Config
- type Engine
- func (e *Engine) APIReader() client.Reader
- func (e *Engine) CancelForDelete(ctx context.Context, obj v1alpha1.NetworkTaskObject, kind string) (bool, time.Duration, error)
- func (e *Engine) Forget(uid types.UID)
- func (e *Engine) LaunchDue(obj v1alpha1.NetworkTaskObject, task string, ...) bool
- func (e *Engine) MarkForRerun(obj v1alpha1.NetworkTaskObject, task string, ...)
- func (e *Engine) ProvisioningEnabled() bool
- func (e *Engine) Run(ctx context.Context, obj v1alpha1.NetworkTaskObject, req Request) (Outcome, error)
- func (e *Engine) WithClock(c clock.PassiveClock) *Engine
- type OSACError
- type Outcome
- type RejectError
- type Request
- type Result
- type RetryError
- type SubnetSlot
- type VNIKind
Constants ¶
const ( // NotStartedTimeout is how long a job may stay new, pending or waiting. NotStartedTimeout = 30 * time.Minute // LostLaunchTimeout is how long a Running entry with an empty jobID waits // for its job to appear under its label before it is launched again. LostLaunchTimeout = 2 * time.Minute // DefaultPollInterval is how often a running job is read. DefaultPollInterval = 30 * time.Second // MessageTimedOut is the entry message of a job AAP ended at its timeout. MessageTimedOut = "job timed out after 60 minutes" // MessageNotStarted is the entry message of a job AAP never started. It is // written to the Running entry before OSAC cancels the job, so that AAP's // canceled status is not taken for a cancel by hand, even after a restart. MessageNotStarted = "AAP did not start the job within 30 minutes" // MessageRerun is the message of an entry marked for a run with a new input. MessageRerun = "waiting to run with the updated input" )
Timing rules of contract §4.7 and its edge cases.
const ( CreateVirtualNetwork = "create_virtual_network" DeleteVirtualNetwork = "delete_virtual_network" CreateSubnet = "create_subnet" DeleteSubnet = "delete_subnet" CreateSecurityGroup = "create_security_group" DeleteSecurityGroup = "delete_security_group" ApplyNetworkAttachment = "apply_network_attachment" DeleteNetworkAttachment = "delete_network_attachment" QueryDHCPLease = "query_dhcp_lease" CreateExternalIPPool = "create_external_ip_pool" DeleteExternalIPPool = "delete_external_ip_pool" CreateExternalIP = "create_external_ip" DeleteExternalIP = "delete_external_ip" AttachExternalIP = "attach_external_ip" DetachExternalIP = "detach_external_ip" CreateNATGateway = "create_nat_gateway" DeleteNATGateway = "delete_nat_gateway" CreateFabricDomain = "create_fabric_domain" DeleteFabricDomain = "delete_fabric_domain" ReserveClusterIngressIP = "reserve_cluster_ingress_ip" ReleaseClusterIngressIP = "release_cluster_ingress_ip" )
Task names of the network manager contract §4.10.
const MessageNetworkingDisabled = "provider networking is disabled"
MessageNetworkingDisabled is the Failed message of an ExternalIP, ExternalIPAttachment or NATGateway CR found while provider networking is disabled (these never exist in that mode).
const (
// TenantAnnotation carries the tenant API ID of a CR; osac_job_vars.tenant comes from it.
TenantAnnotation = "osac.openshift.io/tenant"
)
const VirtualNetworkIDLabel = "osac.openshift.io/virtual-network-id"
VirtualNetworkIDLabel indexes Subnets that share a VirtualNetwork task slot.
Variables ¶
var FabricTasks = map[string]bool{ CreateVirtualNetwork: true, DeleteVirtualNetwork: true, CreateSubnet: true, DeleteSubnet: true, CreateSecurityGroup: true, DeleteSecurityGroup: true, ApplyNetworkAttachment: true, DeleteNetworkAttachment: true, QueryDHCPLease: true, CreateExternalIPPool: true, DeleteExternalIPPool: true, CreateExternalIP: true, DeleteExternalIP: true, AttachExternalIP: true, DetachExternalIP: true, CreateNATGateway: true, DeleteNATGateway: true, CreateFabricDomain: true, DeleteFabricDomain: true, ReserveClusterIngressIP: true, ReleaseClusterIngressIP: true, }
FabricTasks is the fixed Fabric Manager task set (21 tasks).
var KubernetesTasks = map[string]bool{ CreateVirtualNetwork: true, DeleteVirtualNetwork: true, CreateSubnet: true, DeleteSubnet: true, CreateSecurityGroup: true, DeleteSecurityGroup: true, ApplyNetworkAttachment: true, DeleteNetworkAttachment: true, }
KubernetesTasks is the fixed Kubernetes Manager task set (8 tasks).
Functions ¶
func APIID ¶
APIID returns the API ID of a CR from its osac.openshift.io/<kind>-uuid label. A NetworkAttachment's ID is its spec.target.id.
func AcceptNoOutput ¶
AcceptNoOutput rejects any osac_result key: the task has no typed output.
func AcceptSegment ¶
func AcceptSegment(ctx context.Context, reader client.Reader, subnet *v1alpha1.Subnet, networkType string, result Result) error
AcceptSegment records the network segment returned by the Fabric Manager. On first acceptance it checks the L2 VNI against every other VirtualNetwork and Subnet (CheckVNIUnique, read through reader), so call it under Request.SerializeVNI; an accepted segment never changes afterwards.
func AcceptSubnetEligibility ¶ added in v0.0.42
AcceptSubnetEligibility records the optional Kubernetes create_subnet eligibility result. Older managers with no output support VM attachments by default; the attachment task remains authoritative before any VM resources are created.
func Backoff ¶
Backoff is the wait after the n-th consecutive failure: min(2m * 2^(n-1), 30m); query_dhcp_lease waits 30 s, and 5 min from its 20th attempt.
func Cancel ¶
func Cancel(obj v1alpha1.NetworkTaskObject, task string, manager v1alpha1.NetworkJobManager)
Cancel sets a Retrying (or not yet launched Running) entry to Cancelled in memory, for a retry that will never launch, for example the Kubernetes run of a SecurityGroup update whose Fabric run failed. The caller writes status.
func CheckVNIUnique ¶
func CheckVNIUnique(ctx context.Context, reader client.Reader, namespace, selfUID string, vni int32, kind VNIKind) error
CheckVNIUnique checks a VNI the Fabric Manager returned against every other VirtualNetwork and Subnet CR in the namespace, read from the API server (EP #427 §4.9): no L2 VNI equals any live L2 or L3 VNI, and no two VirtualNetworks share an L3 VNI. A CR exists until its Fabric delete has succeeded. When every conflicting CR is being deleted the check is deferred (RetryError); otherwise it is final (RejectError). Call it under the VNI acceptance lock (Request.SerializeVNI).
func DisabledMessage ¶
DisabledMessage names the task skipped because provider networking is disabled.
func FindJob ¶
func FindJob(jobs []v1alpha1.NetworkJobStatus, task string, manager v1alpha1.NetworkJobManager) *v1alpha1.NetworkJobStatus
FindJob returns the entry of task and manager, or nil.
func IPAMVars ¶
func IPAMVars(ipam *v1alpha1.SubnetIPAM) map[string]any
IPAMVars is the snake_case ipam key of the task input; empty ranges are [].
func IsCleanupTask ¶
IsCleanupTask reports whether a task is a delete, detach, release or removal. Cleanup tasks are retried after every failure, whatever osac_error says, and may run while the resource is being deleted.
func IsConflict ¶
IsConflict reports whether err is a status write conflict.
func Layout ¶
func Layout(cidr string, plan v1alpha1.SubnetAddressPlan) (*v1alpha1.SubnetIPAM, error)
Layout computes a Subnet's address layout from its CIDR and address plan (contract §4.8): the ranges overlay, fabric and lbVip follow each other from the network address, each the fewest aligned CIDRs covering it exactly, in ascending order; a share of 0 gives an empty list; the gateway is the network address plus one. Compute it once at Subnet create and record it in status.ipam; never recompute it.
func LoadInput ¶
func LoadInput(obj v1alpha1.NetworkInputObject) (map[string]any, error)
LoadInput returns the stored task input, or nil when none is stored.
func ManagerRef ¶
func ManagerRef(managers *v1alpha1.NetworkManagers, manager v1alpha1.NetworkJobManager) *v1alpha1.NetworkManagerRef
ManagerRef returns the recorded manager of a manager type, or nil.
func ManagerVars ¶
func ManagerVars(ref *v1alpha1.NetworkManagerRef, manager v1alpha1.NetworkJobManager) map[string]any
ManagerVars is osac_job_vars.manager.
func NewInput ¶
NewInput starts a stored task input: {resource: <snapshot>, tenant}. tenant comes from the osac.openshift.io/tenant annotation and is left out when the annotation is absent or for an ExternalIPPool. Add the task's other keys (virtual_network, subnet, ipam, target, ...) to the returned map.
func ParseBackendID ¶
ParseBackendID reads the optional backend_id of create_fabric_domain.
func ParseClusterIngress ¶
func ParseClusterIngress(result Result, subnetCIDR string, ipam *v1alpha1.SubnetIPAM, accepted string) (string, error)
ParseClusterIngress reads the cluster_ingress of reserve_cluster_ingress_ip: a canonical address in lb_vip_ipv4_cidrs, not the Subnet broadcast address, equal to accepted when an address was already accepted.
func ParseDHCPLease ¶
func ParseDHCPLease(result Result, inputMAC, subnetCIDR string, ipam *v1alpha1.SubnetIPAM) (*v1alpha1.NetworkAttachmentDHCPLease, error)
ParseDHCPLease reads the dhcp_lease of query_dhcp_lease: the MAC equals the input MAC, and the IP is canonical, in physical_ipv4_cidrs, and not the Subnet's network, broadcast or gateway address.
func ParseExternalIP ¶
ParseExternalIP reads the external_ip of create_external_ip: a canonical eligible address of the pool CIDR (all but the network and broadcast addresses; every address of a /31 or /32).
func ParseNetworkSegment ¶
func ParseNetworkSegment(result Result, networkType string) (*v1alpha1.NetworkSegment, error)
ParseNetworkSegment reads the network_segment of a Fabric create_subnet. networkType is the network_type of the input; without it the key is undefined. It checks the shape rules of contract §4.9: {type, l2_vni}; the L3 VNI belongs to the VirtualNetwork (ParseVirtualNetworkResult). VNI allocation and uniqueness are owned by the Fabric Manager.
func ParseVMAttachment ¶
func ParseVMAttachment(ctx context.Context, apiReader client.Reader, result Result, tenant string) (*v1alpha1.NetworkAttachmentVMAttachment, error)
ParseVMAttachment reads the vm_attachment of the Kubernetes apply_network_attachment: only namespace, and the namespace exists (read from the API server, not a cache) with osac.openshift.io/tenant equal to tenant.
func ParseVirtualNetworkResult ¶
ParseVirtualNetworkResult reads the result of a Fabric create_virtual_network (contract §4.9, EP #427): with a network type the integer l3_vni is required and backend_id is optional; without one only backend_id is defined. L3 VNI allocation and uniqueness are owned by the Fabric Manager.
func ProgressMessage ¶
func ProgressMessage(entry v1alpha1.NetworkJobStatus) string
ProgressMessage describes an entry for the Ready=False Progressing (or Ready=True Updating) message: the running task and its AAP job ID, or the manager's message and next retry time.
func RetryMessage ¶
RetryMessage is the entry message while a retry is scheduled.
func SegmentVars ¶
func SegmentVars(segment *v1alpha1.NetworkSegment) map[string]any
SegmentVars is the snake_case network_segment launch key.
func SetFailed ¶
func SetFailed(obj v1alpha1.NetworkResourceObject, message string) bool
SetFailed sets Ready=False, reason Failed.
func SetProgressing ¶
func SetProgressing(obj v1alpha1.NetworkResourceObject, message string) bool
SetProgressing sets Ready=False, reason Progressing.
func SetProvisioningDisabled ¶
func SetProvisioningDisabled(obj v1alpha1.NetworkResourceObject, task string) bool
SetProvisioningDisabled sets Ready=True, reason ProvisioningDisabled, naming the skipped task (Unified design, Provider networking control).
func SetReady ¶
func SetReady(obj v1alpha1.NetworkResourceObject, status metav1.ConditionStatus, reason, message string) bool
SetReady sets the Ready condition of a networking CR. It returns true when the condition changed.
func SetSucceeded ¶
func SetSucceeded(obj v1alpha1.NetworkResourceObject) bool
SetSucceeded sets Ready=True, reason Succeeded.
func Snapshot ¶
Snapshot builds the contract §4.5 snapshot of a CR: {apiVersion, kind, id, metadata{name, namespace, uid, generation}, spec}. spec is the CR's spec struct; only the listed camelCase fields are kept, so no other field (for example a secret) reaches a manager. With no fields the snapshot spec is {}.
func Started ¶
func Started(obj v1alpha1.NetworkTaskObject, task string, manager v1alpha1.NetworkJobManager) bool
Started reports whether a job of task and manager was ever recorded. The finalizer rule (contract §4.7) runs a cleanup task only for managers whose create, apply, attach or reserve started.
func StoreInput ¶
func StoreInput(obj v1alpha1.NetworkInputObject, input map[string]any) error
StoreInput writes the input to status.taskInput. Call it in the mutation passed as Request.BeforeLaunch so it lands in the same status write as the first Running entry, or alone for a SecurityGroup rule update.
func Succeeded ¶
func Succeeded(obj v1alpha1.NetworkTaskObject, task string, manager v1alpha1.NetworkJobManager) bool
Succeeded reports whether the latest job of task and manager succeeded.
func TemplateName ¶
TemplateName is the AAP job template of a task: <prefix>-<task with dashes>.
func ValidateTask ¶
func ValidateTask(task string, manager v1alpha1.NetworkJobManager) error
ValidateTask rejects a task outside the manager type's fixed set (contract §4.3). Jobs with manager none are not manager tasks and are not checked.
Types ¶
type AAPClient ¶
type AAPClient interface {
LaunchJobTemplate(ctx context.Context, req aap.LaunchJobTemplateRequest) (*aap.LaunchJobTemplateResponse, error)
GetJob(ctx context.Context, jobID string) (*aap.Job, error)
CancelJob(ctx context.Context, jobID string) error
ListJobsByLabel(ctx context.Context, labelName string) ([]aap.Job, error)
EnsureLabel(ctx context.Context, organization, name string) (int, error)
}
AAPClient is the part of the AAP client the engine uses.
type AcceptFunc ¶
AcceptFunc validates the result of a successful job and applies its typed outputs to the object, which the engine then writes in the same status update that marks the entry Succeeded. It returns a RejectError to reject the result or another error to retry the read.
type Config ¶
type Config struct {
// TemplatePrefix is the AAP job template prefix (OSAC_AAP_TEMPLATE_PREFIX).
TemplatePrefix string
// Organization is the AAP organization (name or ID) where job labels are created.
Organization string
// ProvisioningEnabled is global.networking.provisioningEnabled. When false
// no networking job may run.
ProvisioningEnabled bool
// PollInterval is how often a running job is read; DefaultPollInterval when zero.
PollInterval time.Duration
}
Config configures an Engine.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine launches and tracks network manager tasks on CRs (contract §4.3-§4.7). One Engine is shared by all controllers; it keeps in-memory clocks and backoff counters keyed by CR UID, task and manager.
func New ¶
New creates an Engine. c writes status (resourceVersion-conditional updates); apiReader reads from the API server where a stale cache must not be used.
func (*Engine) CancelForDelete ¶
func (e *Engine) CancelForDelete(ctx context.Context, obj v1alpha1.NetworkTaskObject, kind string) (bool, time.Duration, error)
CancelForDelete cancels every job of the object that is not a cleanup task (contract §4.7 Cancel on delete): a Retrying entry becomes Cancelled at once; a running job is cancelled in AAP and its entry becomes Cancelled once AAP reports it ended, whatever its status, and its result is ignored. A Running entry whose job is not found by its label for LostLaunchTimeout becomes Cancelled with an empty jobID; on every later call its label is looked up again, and a job AAP created after all is tracked and cancelled like any other (delete wins). It returns true when no such job runs any more, so the delete can start.
func (*Engine) Forget ¶
Forget drops the in-memory state of an object, for example after its finalizer was removed.
func (*Engine) LaunchDue ¶
func (e *Engine) LaunchDue(obj v1alpha1.NetworkTaskObject, task string, manager v1alpha1.NetworkJobManager) bool
LaunchDue reports whether Run would start a job now for a task whose entry is not Running: no entry yet, a Cancelled entry, or a Retrying entry whose wait has ended. It does not consider a pending deletion: call it for a live object.
func (*Engine) MarkForRerun ¶
func (e *Engine) MarkForRerun(obj v1alpha1.NetworkTaskObject, task string, manager v1alpha1.NetworkJobManager)
MarkForRerun records that a task must run again with a new stored input (a SecurityGroup rule update): the entry becomes Retrying with MessageRerun and the next Run launches the next attempt at once. Call it in the same status write that stores the new input.
func (*Engine) ProvisioningEnabled ¶
ProvisioningEnabled reports global.networking.provisioningEnabled.
func (*Engine) Run ¶
func (e *Engine) Run(ctx context.Context, obj v1alpha1.NetworkTaskObject, req Request) (Outcome, error)
Run advances one task: it launches the first or next attempt when allowed, tracks a running job, maps its end to the entry state, validates its result and writes status. Call it on every reconcile until the entry is Succeeded or Failed. A conflict on a status write is returned as an error: the in-memory object is then stale and must not be written; requeue.
type Outcome ¶
type Outcome struct {
// Entry is the task's entry after Run (zero when no job was recorded).
Entry v1alpha1.NetworkJobStatus
// Blocked is true when no job was launched because the resource or its
// target is being deleted.
Blocked bool
// WaitingForSlot is true when another Subnet of the VirtualNetwork holds the slot.
WaitingForSlot bool
// RequeueAfter is when the controller should reconcile again; zero when
// the entry is final (Succeeded, Failed or Cancelled).
RequeueAfter time.Duration
}
Outcome is the state of a task after Run.
type RejectError ¶
type RejectError struct {
Reason string
}
RejectError is a result OSAC rejects (contract §4.6). Its message names only the broken rule; the engine reports "OSAC rejected the <task> result: <reason>".
func (*RejectError) Error ¶
func (e *RejectError) Error() string
type Request ¶
type Request struct {
// Task is the task name.
Task string
// Manager is the manager type; none for a job that is not a manager task.
Manager v1alpha1.NetworkJobManager
// ManagerRef is the recorded manager; required unless Manager is none.
ManagerRef *v1alpha1.NetworkManagerRef
// Kind is the CR kind, used for the API ID label lookup (APIID).
Kind string
// APIID overrides the API ID used in the job label.
APIID string
// Template overrides the job template name; required for manager none.
// Default: TemplateName(prefix, Task).
Template string
// Vars is osac_job_vars without manager and task: the stored input plus
// the launch-time keys (see LoadInput and WithLaunchKeys).
Vars map[string]any
// BeforeLaunch mutates the object before the status write that records the
// first Running entry, for example StoreInput or status.ipam.
BeforeLaunch func() error
// Accept validates the result of a successful job and applies its typed
// outputs; nil means the task has no typed output (AcceptNoOutput).
Accept AcceptFunc
// Slot reserves launch and serializes acceptance/status per VirtualNetwork.
Slot *SubnetSlot
// SerializeVNI serializes this task's acceptance and its status write with
// every other VNI acceptance (EP #427: one operator-wide lock).
SerializeVNI bool
// TargetDeleting is true when the target workload (or the attachment)
// has a deletionTimestamp: no non-cleanup job starts then, and a running
// one is cancelled in AAP and becomes Cancelled once AAP reports its end.
TargetDeleting bool
// HoldLaunch starts no job in this Run, for a caller whose Vars are not
// complete for a launch: Run only tracks a job in progress. An entry that
// would be launched again from Running becomes Cancelled, so that LaunchDue
// reports it and the caller can launch it with complete Vars on its next Run.
HoldLaunch bool
}
Request describes one task of one resource on one manager.
type Result ¶
type Result map[string]json.RawMessage
Result is the osac_result object of a successful job: its keys and their raw values.
type RetryError ¶
type RetryError struct{ Reason string }
RetryError fails a result for now without making the task final: the entry becomes Retrying with the normal backoff, and the rerun is checked again.
func (*RetryError) Error ¶
func (e *RetryError) Error() string
type SubnetSlot ¶
type SubnetSlot struct {
// VirtualNetworkID is the API ID of the Subnet's VirtualNetwork.
VirtualNetworkID string
}
SubnetSlot serializes Subnet tasks per VirtualNetwork (contract §4.7 Concurrency). Set it on a Subnet task's Request: before the launch the engine takes the VirtualNetwork's lock, lists the Subnets from the API server with its namespace and VirtualNetwork label. The Running status reserves the slot after its conditional write releases the lock, before AAP calls. The same key serializes acceptance through its resulting status write.