resourcemap

package
v0.0.0-...-4efcaec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedStatus

type CachedStatus struct {
	Status      v1alpha1.Status
	Conditions  []v1alpha1.Condition
	SourceHash  string
	InventoryID string
}

CachedStatus stores the status and condition for one resource.

type ResourceMap

type ResourceMap struct {
	// contains filtered or unexported fields
}

ResourceMap maintains the following maps: 1) resToResgroups maps a resource to all the resource groups including it 2) resgroupToResources maps a resource group to its resource set 3) resToStatus maps a resource to its cached status 4) gkToResources maps a GroupKind to its resource set During the reconciliation of a RG in the root controller, the updates to these two maps should be atomic.

func NewResourceMap

func NewResourceMap() *ResourceMap

NewResourceMap initializes an empty ReverseMap

func (*ResourceMap) Get

func (m *ResourceMap) Get(res resource) []types.NamespacedName

Get returns the resourceGroupSet for res

func (*ResourceMap) GetResources

func (m *ResourceMap) GetResources(gk schema.GroupKind) []resource

GetResources get the set of resources for the given group kind.

func (*ResourceMap) GetStatus

func (m *ResourceMap) GetStatus(res resource) *CachedStatus

GetStatus returns the cached status for the input resource.

func (*ResourceMap) GetStatusMap

func (m *ResourceMap) GetStatusMap() map[resource]*CachedStatus

GetStatusMap returns the map from resources to their status.

func (*ResourceMap) HasResgroup

func (m *ResourceMap) HasResgroup(group types.NamespacedName) bool

HasResgroup checks whether a resourcegroup is in the ResourceMap

func (*ResourceMap) HasResource

func (m *ResourceMap) HasResource(res resource) bool

HasResource checks whether a resource is in the ResourceMap

func (*ResourceMap) IsEmpty

func (m *ResourceMap) IsEmpty() bool

IsEmpty checks whether the ResourceMap is empty

func (*ResourceMap) Reconcile

func (m *ResourceMap) Reconcile(ctx context.Context, group types.NamespacedName, resources []resource, deleteRG bool) []schema.GroupKind

Reconcile takes a resourcegroup name and all the resources belonging to it, and updates the resToResgroups map and resgroupToResources map atomically. The updates include: 1) calculate the diff between resgroupToResources[`group`] and `resources`; 2) update resToResgroups and gkToResources using the diff;

  • for resources only in resgroupToResources[`group`], remove <resource, group> from resToResgroups and gkToResources;
  • for resources only in `resources`, add <resource, group> into resToResgroups and gkToResources;
  • for resources in both resgroupToResources[`group`] and `resources`, do nothing.

3) set resgroupToResources[group] to resources, or delete group from resgroupToResources if `resources` is empty.

Returns:

a slice of GroupKinds that should be watched

To set the resources managed by a RG to be empty, call ResourceMap.Reconcile(group, []resource{}, false).

To delete a RG, call ResourceMap.Reconcile(group, []resource{}, true).

func (*ResourceMap) SetStatus

func (m *ResourceMap) SetStatus(res resource, resStatus *CachedStatus)

SetStatus sets the status and conditions for a resource.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL