Documentation
¶
Overview ¶
Package rulestore manages the in-memory cache of compiled WatchRule configurations. It provides efficient lookup and matching of Kubernetes resources against active watch rules.
Index ¶
- type CompiledClusterResourceRule
- type CompiledClusterRule
- type CompiledResourceRule
- type CompiledRule
- type RuleStore
- func (s *RuleStore) AddOrUpdateClusterWatchRule(rule configv1alpha3.ClusterWatchRule, gitTargetName string, ...)
- func (s *RuleStore) AddOrUpdateWatchRule(rule configv1alpha3.WatchRule, gitTargetName string, gitTargetNamespace string, ...)
- func (s *RuleStore) Delete(key types.NamespacedName)
- func (s *RuleStore) DeleteClusterWatchRule(key types.NamespacedName)
- func (s *RuleStore) GetMatchingClusterRules(resourcePlural string, operation configv1alpha3.OperationType, apiGroup string, ...) []CompiledClusterRule
- func (s *RuleStore) GetMatchingRules(obj client.Object, resourcePlural string, ...) []CompiledRule
- func (s *RuleStore) IsReady() bool
- func (s *RuleStore) MarkReady()
- func (s *RuleStore) SnapshotClusterWatchRules() []CompiledClusterRule
- func (s *RuleStore) SnapshotWatchRules() []CompiledRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompiledClusterResourceRule ¶
type CompiledClusterResourceRule struct {
// Operations specifies which operations trigger this rule.
Operations []configv1alpha3.OperationType
// APIGroups specifies which API groups this rule matches.
APIGroups []string
// APIVersions specifies which API versions this rule matches.
APIVersions []string
// Resources specifies which resource types this rule matches.
Resources []string
// Scope indicates whether this rule watches Cluster or Namespaced resources.
Scope configv1alpha3.ResourceScope
}
CompiledClusterResourceRule represents a single cluster resource rule with scope.
type CompiledClusterRule ¶
type CompiledClusterRule struct {
// Source is the NamespacedName of the ClusterWatchRule CR (namespace will be empty).
Source types.NamespacedName
// GitTarget reference (for event routing)
GitTargetRef string
GitTargetNamespace string
// Resolved values (from GitTarget)
GitProviderRef string
GitProviderNamespace string
Branch string
Path string
// Rules contains the compiled cluster resource rules with per-rule scope.
Rules []CompiledClusterResourceRule
}
CompiledClusterRule represents a fully processed ClusterWatchRule, ready for quick lookups.
type CompiledResourceRule ¶
type CompiledResourceRule struct {
// Operations specifies which operations trigger this rule.
Operations []configv1alpha3.OperationType
// APIGroups specifies which API groups this rule matches.
APIGroups []string
// APIVersions specifies which API versions this rule matches.
APIVersions []string
// Resources specifies which resource types this rule matches.
Resources []string
}
CompiledResourceRule represents a single resource matching rule with all its filters.
type CompiledRule ¶
type CompiledRule struct {
// Source is the NamespacedName of the WatchRule CR.
Source types.NamespacedName
// GitTarget reference (for event routing)
GitTargetRef string
GitTargetNamespace string
// Resolved values (from GitTarget)
GitProviderRef string
GitProviderNamespace string
Branch string
Path string
// IsClusterScoped indicates if this rule watches cluster-scoped resources.
// Always false for WatchRule (namespace-scoped).
IsClusterScoped bool
// ResourceRules contains the compiled resource matching rules.
ResourceRules []CompiledResourceRule
}
CompiledRule represents a fully processed WatchRule, ready for quick lookups.
type RuleStore ¶
type RuleStore struct {
// contains filtered or unexported fields
}
RuleStore holds the in-memory representation of all active watch rules. It is safe for concurrent use.
func (*RuleStore) AddOrUpdateClusterWatchRule ¶
func (s *RuleStore) AddOrUpdateClusterWatchRule( rule configv1alpha3.ClusterWatchRule, gitTargetName string, gitTargetNamespace string, gitProviderName string, gitProviderNamespace string, branch string, path string, )
AddOrUpdateClusterWatchRule adds or updates a ClusterWatchRule with a resolved target from GitTarget. The chain is: ClusterWatchRule -> GitTarget -> GitProvider Parameters:
- rule: the ClusterWatchRule to add or update
- gitTargetName: the name of the GitTarget
- gitTargetNamespace: the namespace containing the GitTarget
- gitProviderName: the name of the resolved GitProvider (from GitTarget.Spec.Provider)
- gitProviderNamespace: the namespace containing the resolved GitProvider
- branch: the Git branch to write to (from GitTarget.Spec.Branch)
- path: POSIX-like relative path prefix for writes (from GitTarget.Spec.Path, sanitized upstream)
func (*RuleStore) AddOrUpdateWatchRule ¶
func (s *RuleStore) AddOrUpdateWatchRule( rule configv1alpha3.WatchRule, gitTargetName string, gitTargetNamespace string, gitProviderName string, gitProviderNamespace string, branch string, path string, )
AddOrUpdateWatchRule adds or updates a WatchRule with a resolved target from GitTarget. The chain is: WatchRule -> GitTarget -> GitProvider Parameters:
- rule: the WatchRule to add or update
- gitTargetName: the name of the GitTarget
- gitTargetNamespace: the namespace containing the GitTarget
- gitProviderName: the name of the resolved GitProvider (from GitTarget.Spec.Provider)
- gitProviderNamespace: the namespace containing the resolved GitProvider
- branch: the Git branch to write to (from GitTarget.Spec.Branch)
- path: POSIX-like relative path prefix for writes (from GitTarget.Spec.Path, sanitized upstream)
func (*RuleStore) Delete ¶
func (s *RuleStore) Delete(key types.NamespacedName)
Delete removes a rule from the store.
func (*RuleStore) DeleteClusterWatchRule ¶
func (s *RuleStore) DeleteClusterWatchRule(key types.NamespacedName)
DeleteClusterWatchRule removes a ClusterWatchRule from the store.
func (*RuleStore) GetMatchingClusterRules ¶
func (s *RuleStore) GetMatchingClusterRules( resourcePlural string, operation configv1alpha3.OperationType, apiGroup string, apiVersion string, isClusterScoped bool, _ map[string]string, ) []CompiledClusterRule
GetMatchingClusterRules returns ClusterWatchRules matching the resource. This handles both cluster-scoped and namespaced resources with per-rule scope matching. Parameters:
- resourcePlural: The plural form of the resource (e.g., "nodes", "pods")
- operation: The operation type (CREATE, UPDATE, DELETE)
- apiGroup: The API group of the resource (empty string for core API)
- apiVersion: The API version of the resource
- isClusterScoped: Whether the resource is cluster-scoped
- namespaceLabels: Labels of the namespace (ignored in simplified MVP)
func (*RuleStore) GetMatchingRules ¶
func (s *RuleStore) GetMatchingRules( obj client.Object, resourcePlural string, operation configv1alpha3.OperationType, apiGroup string, apiVersion string, isClusterScoped bool, ) []CompiledRule
GetMatchingRules returns all namespaced WatchRules that match the given resource. For namespaced resources, callers should provide an object carrying the event namespace so namespaced WatchRules only match objects from their own namespace. Parameters:
- obj: The Kubernetes object to match; its namespace is used for WatchRule filtering
- resourcePlural: The plural form of the resource (e.g., "pods", "deployments")
- operation: The operation type (CREATE, UPDATE, DELETE)
- apiGroup: The API group of the resource (empty string for core API)
- apiVersion: The API version of the resource
- isClusterScoped: Whether the resource is cluster-scoped
func (*RuleStore) MarkReady ¶
func (s *RuleStore) MarkReady()
MarkReady records that initial WatchRule and ClusterWatchRule bootstrap has completed.
func (*RuleStore) SnapshotClusterWatchRules ¶
func (s *RuleStore) SnapshotClusterWatchRules() []CompiledClusterRule
SnapshotClusterWatchRules returns a deep-copied slice of compiled ClusterWatchRule entries. Safe for concurrent use; the returned slice can be freely modified by callers.
func (*RuleStore) SnapshotWatchRules ¶
func (s *RuleStore) SnapshotWatchRules() []CompiledRule
SnapshotWatchRules returns a deep-copied slice of compiled WatchRule entries. Safe for concurrent use; the returned slice can be freely modified by callers.