...

Source file src/sigs.k8s.io/cli-utils/pkg/apply/cache/resource_cache.go

Documentation: sigs.k8s.io/cli-utils/pkg/apply/cache

     1  // Copyright 2021 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package cache
     5  
     6  import (
     7  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
     8  	"sigs.k8s.io/cli-utils/pkg/kstatus/status"
     9  	"sigs.k8s.io/cli-utils/pkg/object"
    10  )
    11  
    12  // ResourceStatus wraps an unstructured resource object, combined with the
    13  // computed status (whether the status matches the spec).
    14  type ResourceStatus struct {
    15  	// Resource is the last known value retrieved from the cluster
    16  	Resource *unstructured.Unstructured
    17  	// Status of the resource
    18  	Status status.Status
    19  	// StatusMessage is the human readable reason for the status
    20  	StatusMessage string
    21  }
    22  
    23  // ResourceCache stores CachedResource objects
    24  type ResourceCache interface {
    25  	ResourceCacheReader
    26  	// Load one or more resources into the cache, generating the ObjMetadata
    27  	// from the objects.
    28  	Load(...ResourceStatus)
    29  	// Put the resource into the cache using the specified ID.
    30  	Put(object.ObjMetadata, ResourceStatus)
    31  	// Remove the resource associated with the ID from the cache.
    32  	Remove(object.ObjMetadata)
    33  	// Clear the cache.
    34  	Clear()
    35  }
    36  
    37  // ResourceCacheReader retrieves CachedResource objects
    38  type ResourceCacheReader interface {
    39  	// Get the resource associated with the ID from the cache.
    40  	// If not cached, status will be Unknown and resource will be nil.
    41  	Get(object.ObjMetadata) ResourceStatus
    42  }
    43  

View as plain text