diff --git a/go.mod b/go.mod index bf71074e..a0dae809 100644 --- a/go.mod +++ b/go.mod @@ -347,6 +347,7 @@ require ( golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect golang.org/x/mod v0.20.0 // indirect + golang.org/x/net v0.28.0 // indirect golang.org/x/oauth2 v0.22.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.23.0 // indirect diff --git a/go.sum b/go.sum index ea21cab2..9ae6693a 100644 --- a/go.sum +++ b/go.sum @@ -825,8 +825,6 @@ github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpR github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY= github.com/tetafro/godot v1.4.16 h1:4ChfhveiNLk4NveAZ9Pu2AN8QZ2nkUGFuadM9lrr5D0= github.com/tetafro/godot v1.4.16/go.mod h1:2oVxTBSftRTh4+MVfUaUXR6bn2GDXCaMcOG4Dk3rfio= -github.com/thejerf/suture/v4 v4.0.5 h1:F1E/4FZwXWqvlWDKEUo6/ndLtxGAUzMmNqkrMknZbAA= -github.com/thejerf/suture/v4 v4.0.5/go.mod h1:gu9Y4dXNUWFrByqRt30Rm9/UZ0wzRSt9AJS6xu/ZGxU= github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 h1:quvGphlmUVU+nhpFa4gg4yJyTRJ13reZMDHrKwYw53M= github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966/go.mod h1:27bSVNWSBOHm+qRp1T9qzaIpsWEP6TbUnei/43HK+PQ= github.com/timonwong/loggercheck v0.9.4 h1:HKKhqrjcVj8sxL7K77beXh0adEm6DLjV/QOGeMXEVi4= diff --git a/internal/kubernetes/schema/group_name.go b/internal/kubernetes/schema/group_name.go new file mode 100644 index 00000000..a6949e45 --- /dev/null +++ b/internal/kubernetes/schema/group_name.go @@ -0,0 +1,7 @@ +package schema + +type GroupName struct { + Group string + Kind string + Name string +} diff --git a/pkg/cache/discovery_cache.go b/pkg/cache/discovery_cache.go index fb1b042f..f4870406 100644 --- a/pkg/cache/discovery_cache.go +++ b/pkg/cache/discovery_cache.go @@ -28,6 +28,7 @@ func DiscoveryCache() cmap.ConcurrentMap[string, bool] { } func RunDiscoveryCacheInBackgroundOrDie(ctx context.Context, discoveryClient *discovery.DiscoveryClient) { + log.Logger.Info("starting discovery cache") err := helpers.BackgroundPollUntilContextCancel(ctx, 5*time.Minute, true, true, func(_ context.Context) (done bool, err error) { if err = updateDiscoveryCache(discoveryClient); err != nil { log.Logger.Error(err, "can't fetch API versions") diff --git a/pkg/cache/resource_cache.go b/pkg/cache/resource_cache.go index 7237983e..e0af327c 100644 --- a/pkg/cache/resource_cache.go +++ b/pkg/cache/resource_cache.go @@ -12,8 +12,6 @@ import ( "sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader" "sigs.k8s.io/cli-utils/pkg/kstatus/polling/statusreaders" - "github.com/pluralsh/deployment-operator/pkg/manifests" - "github.com/pluralsh/polly/containers" "github.com/samber/lo" "k8s.io/apimachinery/pkg/api/meta" @@ -27,6 +25,7 @@ import ( "sigs.k8s.io/cli-utils/pkg/object" "github.com/pluralsh/deployment-operator/internal/kstatus/watcher" + "github.com/pluralsh/deployment-operator/internal/kubernetes/schema" "github.com/pluralsh/deployment-operator/internal/utils" "github.com/pluralsh/deployment-operator/pkg/common" "github.com/pluralsh/deployment-operator/pkg/log" @@ -101,7 +100,7 @@ func Init(ctx context.Context, config *rest.Config, ttl time.Duration) { w := watcher.NewDynamicStatusWatcher(dynamicClient, discoveryClient, mapper, watcher.Options{ UseCustomObjectFilter: true, ObjectFilter: nil, - RESTScopeStrategy: lo.ToPtr(kwatcher.RESTScopeRoot), + RESTScopeStrategy: lo.ToPtr(kwatcher.RESTScopeRoot), Filters: &kwatcher.Filters{ Labels: common.ManagedByAgentLabelSelector(), Fields: nil, @@ -225,7 +224,7 @@ func (in *ResourceCache) GetCacheStatus(key object.ObjMetadata) (*console.Compon return nil, err } in.saveResourceStatus(obj) - return common.StatusEventToComponentAttributes(*s, make(map[manifests.GroupName]string)), nil + return common.StatusEventToComponentAttributes(*s, make(map[schema.GroupName]string)), nil } func (in *ResourceCache) saveResourceStatus(resource *unstructured.Unstructured) { diff --git a/pkg/cache/resource_cache_entry.go b/pkg/cache/resource_cache_entry.go index a8e391f0..704f9bf6 100644 --- a/pkg/cache/resource_cache_entry.go +++ b/pkg/cache/resource_cache_entry.go @@ -5,8 +5,8 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/cli-utils/pkg/apply/event" + "github.com/pluralsh/deployment-operator/internal/kubernetes/schema" "github.com/pluralsh/deployment-operator/pkg/common" - "github.com/pluralsh/deployment-operator/pkg/manifests" ) type SHAType string @@ -80,5 +80,5 @@ func (in *ResourceCacheEntry) RequiresApply(manifestSHA string) bool { // SetStatus saves the last seen resource [event.StatusEvent] and converts it to a simpler // [console.ComponentAttributes] structure. func (in *ResourceCacheEntry) SetStatus(se event.StatusEvent) { - in.status = common.StatusEventToComponentAttributes(se, make(map[manifests.GroupName]string)) + in.status = common.StatusEventToComponentAttributes(se, make(map[schema.GroupName]string)) } diff --git a/pkg/common/lua.go b/pkg/common/lua.go index cba3809b..688ddb04 100644 --- a/pkg/common/lua.go +++ b/pkg/common/lua.go @@ -3,9 +3,10 @@ package common import ( "sync" - "github.com/pluralsh/deployment-operator/pkg/lua" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + + "github.com/pluralsh/deployment-operator/pkg/lua" ) func init() { diff --git a/pkg/common/status.go b/pkg/common/status.go index 43a07550..b0264141 100644 --- a/pkg/common/status.go +++ b/pkg/common/status.go @@ -2,21 +2,22 @@ package common import ( console "github.com/pluralsh/console/go/client" - dlog "github.com/pluralsh/deployment-operator/pkg/log" - "github.com/pluralsh/deployment-operator/pkg/manifests" "github.com/samber/lo" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/cli-utils/pkg/apply/event" "sigs.k8s.io/cli-utils/pkg/kstatus/status" + + schema2 "github.com/pluralsh/deployment-operator/internal/kubernetes/schema" + dlog "github.com/pluralsh/deployment-operator/pkg/log" ) -func StatusEventToComponentAttributes(e event.StatusEvent, vcache map[manifests.GroupName]string) *console.ComponentAttributes { +func StatusEventToComponentAttributes(e event.StatusEvent, vcache map[schema2.GroupName]string) *console.ComponentAttributes { if e.Resource == nil { return nil } gvk := e.Resource.GroupVersionKind() - gname := manifests.GroupName{ + gname := schema2.GroupName{ Group: gvk.Group, Kind: gvk.Kind, Name: e.Resource.GetName(), diff --git a/pkg/controller/service/reconciler.go b/pkg/controller/service/reconciler.go index d19887c7..aad67be2 100644 --- a/pkg/controller/service/reconciler.go +++ b/pkg/controller/service/reconciler.go @@ -25,6 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/pluralsh/deployment-operator/cmd/agent/args" + "github.com/pluralsh/deployment-operator/internal/kubernetes/schema" agentcommon "github.com/pluralsh/deployment-operator/pkg/common" clienterrors "github.com/pluralsh/deployment-operator/internal/errors" @@ -61,8 +62,8 @@ type ServiceReconciler struct { UtilFactory util.Factory RestoreNamespace string - mapper meta.RESTMapper - pinger *ping.Pinger + mapper meta.RESTMapper + pinger *ping.Pinger } func NewServiceReconciler(consoleClient client.Client, config *rest.Config, refresh, manifestTTL time.Duration, restoreNamespace, consoleURL string) (*ServiceReconciler, error) { @@ -353,7 +354,7 @@ func (s *ServiceReconciler) Reconcile(ctx context.Context, id string) (result re }) metrics.Record().ServiceDeletion(id) - err = s.UpdatePruneStatus(ctx, svc, ch, map[manis.GroupName]string{}) + err = s.UpdatePruneStatus(ctx, svc, ch, map[schema.GroupName]string{}) return } diff --git a/pkg/controller/service/reconciler_status.go b/pkg/controller/service/reconciler_status.go index b01516e0..426010ac 100644 --- a/pkg/controller/service/reconciler_status.go +++ b/pkg/controller/service/reconciler_status.go @@ -13,12 +13,17 @@ import ( "sigs.k8s.io/cli-utils/pkg/print/stats" "sigs.k8s.io/controller-runtime/pkg/log" + internalschema "github.com/pluralsh/deployment-operator/internal/kubernetes/schema" "github.com/pluralsh/deployment-operator/internal/metrics" "github.com/pluralsh/deployment-operator/pkg/cache" - "github.com/pluralsh/deployment-operator/pkg/manifests" ) -func (s *ServiceReconciler) UpdatePruneStatus(ctx context.Context, svc *console.GetServiceDeploymentForAgent_ServiceDeployment, ch <-chan event.Event, vcache map[manifests.GroupName]string) error { +func (s *ServiceReconciler) UpdatePruneStatus( + ctx context.Context, + svc *console.GetServiceDeploymentForAgent_ServiceDeployment, + ch <-chan event.Event, + vcache map[internalschema.GroupName]string, +) error { logger := log.FromContext(ctx) var statsCollector stats.Stats @@ -61,7 +66,7 @@ func (s *ServiceReconciler) UpdateApplyStatus( svc *console.GetServiceDeploymentForAgent_ServiceDeployment, ch <-chan event.Event, printStatus bool, - vcache map[manifests.GroupName]string, + vcache map[internalschema.GroupName]string, ) error { logger := log.FromContext(ctx) start, err := metrics.FromContext[time.Time](ctx, metrics.ContextKeyTimeStart) diff --git a/pkg/controller/service/status_collector.go b/pkg/controller/service/status_collector.go index 1b1ea1f1..4967d1bc 100644 --- a/pkg/controller/service/status_collector.go +++ b/pkg/controller/service/status_collector.go @@ -11,10 +11,10 @@ import ( "sigs.k8s.io/cli-utils/pkg/apply/event" "sigs.k8s.io/cli-utils/pkg/object" + "github.com/pluralsh/deployment-operator/internal/kubernetes/schema" "github.com/pluralsh/deployment-operator/pkg/cache" "github.com/pluralsh/deployment-operator/pkg/common" "github.com/pluralsh/deployment-operator/pkg/log" - "github.com/pluralsh/deployment-operator/pkg/manifests" ) type serviceComponentsStatusCollector struct { @@ -58,12 +58,12 @@ func (sc *serviceComponentsStatusCollector) refetch(resource *unstructured.Unstr return response } -func (sc *serviceComponentsStatusCollector) fromApplyResult(e event.ApplyEvent, vcache map[manifests.GroupName]string) *console.ComponentAttributes { +func (sc *serviceComponentsStatusCollector) fromApplyResult(e event.ApplyEvent, vcache map[schema.GroupName]string) *console.ComponentAttributes { if e.Resource == nil { return nil } gvk := e.Resource.GroupVersionKind() - gname := manifests.GroupName{ + gname := schema.GroupName{ Group: gvk.Group, Kind: gvk.Kind, Name: e.Resource.GetName(), @@ -96,7 +96,7 @@ func (sc *serviceComponentsStatusCollector) fromApplyResult(e event.ApplyEvent, } } -func (sc *serviceComponentsStatusCollector) componentsAttributes(vcache map[manifests.GroupName]string) []*console.ComponentAttributes { +func (sc *serviceComponentsStatusCollector) componentsAttributes(vcache map[schema.GroupName]string) []*console.ComponentAttributes { components := make([]*console.ComponentAttributes, 0, len(sc.latestStatus)) if sc.DryRun { @@ -123,7 +123,7 @@ func (sc *serviceComponentsStatusCollector) componentsAttributes(vcache map[mani log.Logger.Error(err, "failed to get cache status") continue } - gname := manifests.GroupName{ + gname := schema.GroupName{ Group: e.Group, Kind: e.Kind, Name: e.Name, diff --git a/pkg/manifests/versions.go b/pkg/manifests/versions.go index 9f3f1adb..b1cf89f6 100644 --- a/pkg/manifests/versions.go +++ b/pkg/manifests/versions.go @@ -2,19 +2,15 @@ package manifests import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" -) -type GroupName struct { - Group string - Kind string - Name string -} + "github.com/pluralsh/deployment-operator/internal/kubernetes/schema" +) -func VersionCache(manifests []*unstructured.Unstructured) map[GroupName]string { - res := map[GroupName]string{} +func VersionCache(manifests []*unstructured.Unstructured) map[schema.GroupName]string { + res := map[schema.GroupName]string{} for _, man := range manifests { gvk := man.GroupVersionKind() - name := GroupName{ + name := schema.GroupName{ Group: gvk.Group, Kind: gvk.Kind, Name: man.GetName(),