Files
zeekayandHanzo Dev 1ab6e799c1 cd: the module is github.com/hanzoai/cd, where it is actually hosted
go.mod still declared `module github.com/hanzoai/deploy` after the repo was
renamed. A Go module path is not cosmetic — it is the resolvable location. So
`go get github.com/hanzoai/cd` could not work, and anything importing this
module had to spell a name that no longer exists at that address. The build log
of v3.6.0 is where it surfaced: the compiler was still emitting
github.com/hanzoai/deploy/cmd/cd/commands.

3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile
and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to
ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from
the module path, replaced separately so neither could clobber the other.

go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 21:16:24 -07:00

186 lines
5.4 KiB
Go

package cache
import (
"time"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/rest"
"github.com/hanzoai/cd/gitops-engine/pkg/health"
"github.com/hanzoai/cd/gitops-engine/pkg/utils/kube"
"github.com/hanzoai/cd/gitops-engine/pkg/utils/tracing"
)
// NewNoopSettings returns cache settings that has not health customizations and don't filter any resources
func NewNoopSettings() *noopSettings {
return &noopSettings{}
}
type noopSettings struct{}
func (f *noopSettings) GetResourceHealth(_ *unstructured.Unstructured) (*health.HealthStatus, error) {
return nil, nil
}
func (f *noopSettings) IsExcludedResource(_, _, _ string) bool {
return false
}
// Settings caching customizations
type Settings struct {
// ResourceHealthOverride contains health assessment overrides
ResourceHealthOverride health.HealthOverride
// ResourcesFilter holds filter that excludes resources
ResourcesFilter kube.ResourceFilter
}
type UpdateSettingsFunc func(cache *clusterCache)
// SetKubectl allows to override kubectl wrapper implementation
func SetKubectl(kubectl kube.Kubectl) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.kubectl = kubectl
}
}
// SetPopulateResourceInfoHandler updates handler that populates resource info
func SetPopulateResourceInfoHandler(handler OnPopulateResourceInfoHandler) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.populateResourceInfoHandler = handler
}
}
// SetSettings updates caching settings
func SetSettings(settings Settings) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.settings = Settings{settings.ResourceHealthOverride, settings.ResourcesFilter}
}
}
// SetNamespaces updates list of monitored namespaces
func SetNamespaces(namespaces []string) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.namespaces = namespaces
}
}
// SetClusterResources specifies if cluster level resource included or not.
// Flag is used only if cluster is changed to namespaced mode using SetNamespaces setting
func SetClusterResources(val bool) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.clusterResources = val
}
}
// SetConfig updates cluster rest config
func SetConfig(config *rest.Config) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.config = config
}
}
// SetListPageSize sets the page size for list pager.
func SetListPageSize(listPageSize int64) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.listPageSize = listPageSize
}
}
// SetListPageBufferSize sets the number of pages to prefetch for list pager.
func SetListPageBufferSize(listPageBufferSize int32) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.listPageBufferSize = listPageBufferSize
}
}
// SetListSemaphore sets the semaphore for list operations.
// Taking an object rather than a number allows to share a semaphore among multiple caches if necessary.
func SetListSemaphore(listSemaphore WeightedSemaphore) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.listSemaphore = listSemaphore
}
}
// SetResyncTimeout updates cluster re-sync timeout
func SetResyncTimeout(timeout time.Duration) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.syncStatus.lock.Lock()
defer cache.syncStatus.lock.Unlock()
cache.syncStatus.resyncTimeout = timeout
}
}
// SetWatchResyncTimeout updates cluster re-sync timeout
func SetWatchResyncTimeout(timeout time.Duration) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.watchResyncTimeout = timeout
}
}
// SetClusterSyncRetryTimeout updates cluster sync retry timeout when sync error happens
func SetClusterSyncRetryTimeout(timeout time.Duration) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.clusterSyncRetryTimeout = timeout
}
}
// SetLogr sets the logger to use.
func SetLogr(log logr.Logger) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.log = log
if kcmd, ok := cache.kubectl.(*kube.KubectlCmd); ok {
kcmd.Log = log
}
}
}
// SetTracer sets the tracer to use.
func SetTracer(tracer tracing.Tracer) UpdateSettingsFunc {
return func(cache *clusterCache) {
if kcmd, ok := cache.kubectl.(*kube.KubectlCmd); ok {
kcmd.Tracer = tracer
}
}
}
// SetRetryOptions sets cluster list retry options
func SetRetryOptions(maxRetries int32, useBackoff bool, retryFunc ListRetryFunc) UpdateSettingsFunc {
return func(cache *clusterCache) {
// Max retries must be at least one
if maxRetries < 1 {
maxRetries = 1
}
cache.listRetryLimit = maxRetries
cache.listRetryUseBackoff = useBackoff
cache.listRetryFunc = retryFunc
}
}
// SetRespectRBAC allows to set whether to respect the controller rbac in list/watches
func SetRespectRBAC(respectRBAC int) UpdateSettingsFunc {
return func(cache *clusterCache) {
// if invalid value is provided disable respect rbac
if respectRBAC < RespectRbacDisabled || respectRBAC > RespectRbacStrict {
cache.respectRBAC = RespectRbacDisabled
} else {
cache.respectRBAC = respectRBAC
}
}
}
// SetBatchEventsProcessing allows to set whether to process events in batch
func SetBatchEventsProcessing(batchProcessing bool) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.batchEventsProcessing = batchProcessing
}
}
// SetEventProcessingInterval allows to set the interval for processing events
func SetEventProcessingInterval(interval time.Duration) UpdateSettingsFunc {
return func(cache *clusterCache) {
cache.eventProcessingInterval = interval
}
}