This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 3d26e99539385fd2ed9475ecb62cf1fbe258187f
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Wed Sep 28 15:07:12 2022 +0200

    chore(trait): Deprecate cached discovery option from GC trait
---
 .../camel.apache.org_integrationplatforms.yaml     | 10 +++--
 .../crd/bases/camel.apache.org_integrations.yaml   |  5 ++-
 .../bases/camel.apache.org_kameletbindings.yaml    |  5 ++-
 docs/modules/ROOT/partials/apis/camel-k-crds.adoc  |  3 +-
 docs/modules/traits/pages/gc.adoc                  |  3 +-
 helm/camel-k/crds/crd-integration-platform.yaml    | 10 +++--
 helm/camel-k/crds/crd-integration.yaml             |  5 ++-
 helm/camel-k/crds/crd-kamelet-binding.yaml         |  5 ++-
 pkg/apis/camel/v1/trait/gc.go                      |  3 +-
 pkg/resources/resources.go                         | 16 +++----
 pkg/trait/gc.go                                    | 52 +++-------------------
 resources/traits.yaml                              |  4 +-
 12 files changed, 45 insertions(+), 76 deletions(-)

diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml 
b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index da49d6aad..e990fd40a 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -812,8 +812,9 @@ spec:
                         type: object
                         x-kubernetes-preserve-unknown-fields: true
                       discoveryCache:
-                        description: Discovery client cache to be used, either 
`disabled`,
-                          `disk` or `memory` (default `memory`)
+                        description: 'Discovery client cache to be used, 
either `disabled`,
+                          `disk` or `memory` (default `memory`). Deprecated: 
to be
+                          removed from trait configuration.'
                         type: string
                       enabled:
                         description: Can be used to enable or disable a trait. 
All
@@ -2449,8 +2450,9 @@ spec:
                         type: object
                         x-kubernetes-preserve-unknown-fields: true
                       discoveryCache:
-                        description: Discovery client cache to be used, either 
`disabled`,
-                          `disk` or `memory` (default `memory`)
+                        description: 'Discovery client cache to be used, 
either `disabled`,
+                          `disk` or `memory` (default `memory`). Deprecated: 
to be
+                          removed from trait configuration.'
                         type: string
                       enabled:
                         description: Can be used to enable or disable a trait. 
All
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml 
b/config/crd/bases/camel.apache.org_integrations.yaml
index e7c6616a6..00ce1ac6a 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -6503,8 +6503,9 @@ spec:
                         type: object
                         x-kubernetes-preserve-unknown-fields: true
                       discoveryCache:
-                        description: Discovery client cache to be used, either 
`disabled`,
-                          `disk` or `memory` (default `memory`)
+                        description: 'Discovery client cache to be used, 
either `disabled`,
+                          `disk` or `memory` (default `memory`). Deprecated: 
to be
+                          removed from trait configuration.'
                         type: string
                       enabled:
                         description: Can be used to enable or disable a trait. 
All
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml 
b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index 333b762a2..dbf907941 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -6786,8 +6786,9 @@ spec:
                             type: object
                             x-kubernetes-preserve-unknown-fields: true
                           discoveryCache:
-                            description: Discovery client cache to be used, 
either
-                              `disabled`, `disk` or `memory` (default `memory`)
+                            description: 'Discovery client cache to be used, 
either
+                              `disabled`, `disk` or `memory` (default 
`memory`). Deprecated:
+                              to be removed from trait configuration.'
                             type: string
                           enabled:
                             description: Can be used to enable or disable a 
trait.
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc 
b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index 3b8ceab0e..6ed75c0d5 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -4381,7 +4381,8 @@ The GC Trait garbage-collects all resources that are no 
longer necessary upon in
 |
 
 
-Discovery client cache to be used, either `disabled`, `disk` or `memory` 
(default `memory`)
+Discovery client cache to be used, either `disabled`, `disk` or `memory` 
(default `memory`).
+Deprecated: to be removed from trait configuration.
 
 
 |===
diff --git a/docs/modules/traits/pages/gc.adoc 
b/docs/modules/traits/pages/gc.adoc
index 88af7ba26..44955bdc2 100755
--- a/docs/modules/traits/pages/gc.adoc
+++ b/docs/modules/traits/pages/gc.adoc
@@ -27,7 +27,8 @@ The following configuration options are available:
 
 | gc.discovery-cache
 | github.com/apache/camel-k/pkg/apis/camel/v1/trait.DiscoveryCacheType
-| Discovery client cache to be used, either `disabled`, `disk` or `memory` 
(default `memory`)
+| Discovery client cache to be used, either `disabled`, `disk` or `memory` 
(default `memory`).
+Deprecated: to be removed from trait configuration.
 
 |===
 
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml 
b/helm/camel-k/crds/crd-integration-platform.yaml
index da49d6aad..e990fd40a 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -812,8 +812,9 @@ spec:
                         type: object
                         x-kubernetes-preserve-unknown-fields: true
                       discoveryCache:
-                        description: Discovery client cache to be used, either 
`disabled`,
-                          `disk` or `memory` (default `memory`)
+                        description: 'Discovery client cache to be used, 
either `disabled`,
+                          `disk` or `memory` (default `memory`). Deprecated: 
to be
+                          removed from trait configuration.'
                         type: string
                       enabled:
                         description: Can be used to enable or disable a trait. 
All
@@ -2449,8 +2450,9 @@ spec:
                         type: object
                         x-kubernetes-preserve-unknown-fields: true
                       discoveryCache:
-                        description: Discovery client cache to be used, either 
`disabled`,
-                          `disk` or `memory` (default `memory`)
+                        description: 'Discovery client cache to be used, 
either `disabled`,
+                          `disk` or `memory` (default `memory`). Deprecated: 
to be
+                          removed from trait configuration.'
                         type: string
                       enabled:
                         description: Can be used to enable or disable a trait. 
All
diff --git a/helm/camel-k/crds/crd-integration.yaml 
b/helm/camel-k/crds/crd-integration.yaml
index e7c6616a6..00ce1ac6a 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -6503,8 +6503,9 @@ spec:
                         type: object
                         x-kubernetes-preserve-unknown-fields: true
                       discoveryCache:
-                        description: Discovery client cache to be used, either 
`disabled`,
-                          `disk` or `memory` (default `memory`)
+                        description: 'Discovery client cache to be used, 
either `disabled`,
+                          `disk` or `memory` (default `memory`). Deprecated: 
to be
+                          removed from trait configuration.'
                         type: string
                       enabled:
                         description: Can be used to enable or disable a trait. 
All
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml 
b/helm/camel-k/crds/crd-kamelet-binding.yaml
index 333b762a2..dbf907941 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -6786,8 +6786,9 @@ spec:
                             type: object
                             x-kubernetes-preserve-unknown-fields: true
                           discoveryCache:
-                            description: Discovery client cache to be used, 
either
-                              `disabled`, `disk` or `memory` (default `memory`)
+                            description: 'Discovery client cache to be used, 
either
+                              `disabled`, `disk` or `memory` (default 
`memory`). Deprecated:
+                              to be removed from trait configuration.'
                             type: string
                           enabled:
                             description: Can be used to enable or disable a 
trait.
diff --git a/pkg/apis/camel/v1/trait/gc.go b/pkg/apis/camel/v1/trait/gc.go
index 89d277a94..8b4ddf43c 100644
--- a/pkg/apis/camel/v1/trait/gc.go
+++ b/pkg/apis/camel/v1/trait/gc.go
@@ -22,7 +22,8 @@ package trait
 // +camel-k:trait=gc.
 type GCTrait struct {
        Trait `property:",squash" json:",inline"`
-       // Discovery client cache to be used, either `disabled`, `disk` or 
`memory` (default `memory`)
+       // Discovery client cache to be used, either `disabled`, `disk` or 
`memory` (default `memory`).
+       // Deprecated: to be removed from trait configuration.
        DiscoveryCache *DiscoveryCacheType `property:"discovery-cache" 
json:"discoveryCache,omitempty"`
 }
 
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index d6a5a4692..9bb9b7b45 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -138,23 +138,23 @@ var assets = func() http.FileSystem {
                "/crd/bases/camel.apache.org_integrationplatforms.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             
"camel.apache.org_integrationplatforms.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 178319,
+                       uncompressedSize: 178481,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\xdb\x36\xb6\x30\x8e\xff\x9e\xbf\x02\xe3\xce\x1d\x3b\x19\x49\x4e\xba\xb7\xbb\xbd\x7e\xa6\xf3\x3c\xae\x93\xb6\x6e\xe2\xd8\xd7\x76\x72\xef\x4e\xdb\xa9\x20\xf2\x48\x42\x4c\x02\x5c\x00\x94\xa3\x7e\xf7\xfb\xbf\x7f\x06\x07\x00\x49\x49\x24\x48\x49\x7e\x6b\x23\x76\x66\x37\xb6\x09\xf0\xe0\xe0\xe0\xbc\xe1\xbc\x7c\x45\xfa\x77\xf7\x3c\xfb\x8a\xbc\x63\x11\x70\x05\x31\xd1\x82\xe8\x29\x90\xe3\x8c\x46\x53\x20\x57\x62\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\xdb\x36\xb6\x30\x8e\xff\x9e\xbf\x02\xe3\xce\x1d\x3b\x19\x49\x4e\xba\xb7\xbb\xbd\x7e\xa6\xf3\x3c\xae\x93\xb6\x6e\xe2\xd8\xd7\x76\x72\xef\x4e\xdb\xa9\x20\xf2\x48\x42\x4c\x02\x5c\x00\x94\xa3\x7e\xf7\xfb\xbf\x7f\x06\x07\x00\x49\x49\x24\x48\x49\x7e\x6b\x23\x76\x66\x37\xb6\x09\xf0\xe0\xe0\xe0\xbc\xe1\xbc\x7c\x45\xfa\x77\xf7\x3c\xfb\x8a\xbc\x63\x11\x70\x05\x31\xd1\x82\xe8\x29\x90\xe3\x8c\x46\x53\x20\x57\x62\x
 [...]
                },
                "/crd/bases/camel.apache.org_integrations.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             "camel.apache.org_integrations.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 487525,
+                       uncompressedSize: 487606,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\x96\x38\x0c\xff\xef\x4f\x81\x72\x52\x3f\x49\x1b\x91\xb2\x33\xb3\x53\x3b\x7e\xa7\x36\xa5\x91\xe4\x44\x6f\x6c\x99\x65\x29\xc9\x2f\xe5\x64\x13\xb0\x1b\x24\xb1\x6a\x02\x3d\x00\x9a\x12\xe7\xc9\xf3\xdd\x9f\xc2\x01\xd0\x17\xde\xfa\xa0\x45\x3a\xce\x4c\x63\xaa\x32\x26\xc5\x3e\x8d\xcb\xc1\xb9\x5f\x3e\x23\x83\xfd\x8d\x67\x9f\x91\x37\x3c\x61\x42\xb3\x94\x18\x49\xcc\x8c\x91\xf3\x9c\x26\x33\x46\x6e\xe5\xc4\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\x96\x38\x0c\xff\xef\x4f\x81\x72\x52\x3f\x49\x1b\x91\xb2\x33\xb3\x53\x3b\x7e\xa7\x36\xa5\x91\xe4\x44\x6f\x6c\x99\x65\x29\xc9\x2f\xe5\x64\x13\xb0\x1b\x24\xb1\x6a\x02\x3d\x00\x9a\x12\xe7\xc9\xf3\xdd\x9f\xc2\x01\xd0\x17\xde\xfa\xa0\x45\x3a\xce\x4c\x63\xaa\x32\x26\xc5\x3e\x8d\xcb\xc1\xb9\x5f\x3e\x23\x83\xfd\x8d\x67\x9f\x91\x37\x3c\x61\x42\xb3\x94\x18\x49\xcc\x8c\x91\xf3\x9c\x26\x33\x46\x6e\xe5\xc4\x
 [...]
                },
                "/crd/bases/camel.apache.org_kameletbindings.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             
"camel.apache.org_kameletbindings.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 561411,
+                       uncompressedSize: 561496,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\xb6\x28\x8a\xff\x9f\x4f\x81\x72\x52\x47\xd2\x8e\x48\xd9\x99\x47\xed\xf1\x6f\xea\xa4\xb4\x65\x39\xd1\x2f\xb1\xcc\xb2\x94\xe4\xa4\x9c\xec\x04\xec\x06\x49\x1c\x35\x81\xde\x00\x9a\x12\xe7\xe6\x7e\xf7\x5b\x58\x00\xba\xd1\x7c\x09\xab\x29\x69\xe4\x99\xc6\x54\x65\x4c\x8a\xbd\x1a\x8f\x85\xf5\x7e\x7c\x4e\x06\x0f\x37\x3e\xfb\x9c\x7c\xcf\x33\x26\x34\xcb\x89\x91\xc4\xcc\x18\x39\x2d\x69\x36\x63\xe4\x4a\x4e\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\x7b\x73\x1b\x37\xb6\x28\x8a\xff\x9f\x4f\x81\x72\x52\x47\xd2\x8e\x48\xd9\x99\x47\xed\xf1\x6f\xea\xa4\xb4\x65\x39\xd1\x2f\xb1\xcc\xb2\x94\xe4\xa4\x9c\xec\x04\xec\x06\x49\x1c\x35\x81\xde\x00\x9a\x12\xe7\xe6\x7e\xf7\x5b\x58\x00\xba\xd1\x7c\x09\xab\x29\x69\xe4\x99\xc6\x54\x65\x4c\x8a\xbd\x1a\x8f\x85\xf5\x7e\x7c\x4e\x06\x0f\x37\x3e\xfb\x9c\x7c\xcf\x33\x26\x34\xcb\x89\x91\xc4\xcc\x18\x39\x2d\x69\x36\x63\xe4\x4a\x4e\x
 [...]
                },
                "/crd/bases/camel.apache.org_kamelets.yaml": 
&vfsgen۰CompressedFileInfo{
                        name:             "camel.apache.org_kamelets.yaml",
@@ -611,9 +611,9 @@ var assets = func() http.FileSystem {
                "/traits.yaml": &vfsgen۰CompressedFileInfo{
                        name:             "traits.yaml",
                        modTime:          time.Time{},
-                       uncompressedSize: 55071,
+                       uncompressedSize: 56337,
 
-                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfd\x73\x1b\xb9\x95\xe0\xef\xf3\x57\xa0\xb4\xb7\x25\xc9\x45\x52\x9e\xc9\x26\x9b\xd5\x9d\x37\xa7\xb1\x9d\x44\x33\xfe\xd0\xd9\x9e\xd9\x4d\xf9\x5c\x21\xd8\x0d\x92\x30\x9b\x40\x07\x40\x4b\xe6\x5c\xee\x7f\xbf\xc2\xfb\x00\xd0\x4d\x4a\xa2\x6c\x6b\x2e\xba\xba\x4c\x55\x2c\x92\xdd\xc0\xc3\xc3\xc3\xc3\xfb\x7e\xc1\x49\x1d\xfc\xe9\x37\x63\x61\xe4\x5a\x9d\x8a\xdf\xf8\x4a\x36\xea\x1b\x21\xda\x46\x86\xb9\x75\xeb\x53\x31\x97\x
 [...]
+                       compressedContent: 
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\x6b\x73\x1c\xb9\x91\xe0\xf7\xf9\x15\x08\xee\x6d\x90\x54\x74\x35\x35\xe3\xb5\x77\x96\x77\x5a\x1f\x47\x92\x6d\xce\xe8\xc1\x13\x39\xe3\x75\xe8\x14\x6e\x74\x15\xba\x1b\xea\x2a\xa0\x0c\xa0\x48\xb5\x6f\xef\xbf\x5f\x20\x33\xf1\xa8\xea\x6a\xb2\x29\x89\x73\xe6\xc5\xad\x23\x76\x44\xb2\x90\x48\x24\x12\x89\x44\x3e\x9d\xe1\xd2\xd9\xd3\x6f\x0a\xa6\x78\x23\x4e\xd9\x6f\x6c\xc9\x6b\xf1\x0d\x63\x6d\xcd\xdd\x42\x9b\xe6\x94\x2d\x
 [...]
                },
        }
        fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
diff --git a/pkg/trait/gc.go b/pkg/trait/gc.go
index 755b51b9a..723a51437 100644
--- a/pkg/trait/gc.go
+++ b/pkg/trait/gc.go
@@ -19,8 +19,6 @@ package trait
 
 import (
        "context"
-       "fmt"
-       "path/filepath"
        "regexp"
        "strconv"
        "strings"
@@ -38,9 +36,8 @@ import (
        "k8s.io/apimachinery/pkg/runtime/schema"
        "k8s.io/apimachinery/pkg/selection"
        "k8s.io/client-go/discovery"
-       "k8s.io/client-go/discovery/cached/disk"
-       "k8s.io/client-go/discovery/cached/memory"
        "k8s.io/utils/pointer"
+
        ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -51,11 +48,9 @@ import (
 var (
        toFileName = regexp.MustCompile(`[^(\w/\.)]`)
 
-       lock                  sync.Mutex
-       rateLimiter           = rate.NewLimiter(rate.Every(time.Minute), 1)
-       collectableGVKs       = make(map[schema.GroupVersionKind]struct{})
-       memoryCachedDiscovery discovery.CachedDiscoveryInterface
-       diskCachedDiscovery   discovery.CachedDiscoveryInterface
+       lock            sync.Mutex
+       rateLimiter     = rate.NewLimiter(rate.Every(time.Minute), 1)
+       collectableGVKs = make(map[schema.GroupVersionKind]struct{})
 )
 
 type gcTrait struct {
@@ -74,11 +69,6 @@ func (t *gcTrait) Configure(e *Environment) (bool, error) {
                return false, nil
        }
 
-       if t.DiscoveryCache == nil {
-               s := traitv1.MemoryDiscoveryCache
-               t.DiscoveryCache = &s
-       }
-
        return e.IntegrationInPhase(v1.IntegrationPhaseInitialization) || 
e.IntegrationInRunningPhases(), nil
 }
 
@@ -190,11 +180,7 @@ func (t *gcTrait) getDeletableTypes(e *Environment) 
(map[schema.GroupVersionKind
 
        // We rely on the discovery API to retrieve all the resources GVK,
        // that results in an unbounded set that can impact garbage collection 
latency when scaling up.
-       discoveryClient, err := t.discoveryClient()
-       if err != nil {
-               return nil, err
-       }
-       resources, err := discoveryClient.ServerPreferredNamespacedResources()
+       resources, err := 
t.Client.Discovery().ServerPreferredNamespacedResources()
        // Swallow group discovery errors, e.g., Knative serving exposes
        // an aggregated API for custom.metrics.k8s.io that requires special
        // authentication scheme while discovering preferred resources.
@@ -242,31 +228,3 @@ func (t *gcTrait) getDeletableTypes(e *Environment) 
(map[schema.GroupVersionKind
 
        return collectableGVKs, nil
 }
-
-func (t *gcTrait) discoveryClient() (discovery.DiscoveryInterface, error) {
-       switch *t.DiscoveryCache {
-       case traitv1.DiskDiscoveryCache:
-               if diskCachedDiscovery != nil {
-                       return diskCachedDiscovery, nil
-               }
-               config := t.Client.GetConfig()
-               httpCacheDir := filepath.Join(mustHomeDir(), ".kube", 
"http-cache")
-               diskCacheDir := filepath.Join(mustHomeDir(), ".kube", "cache", 
"discovery", toHostDir(config.Host))
-               var err error
-               diskCachedDiscovery, err = 
disk.NewCachedDiscoveryClientForConfig(config, diskCacheDir, httpCacheDir, 
10*time.Minute)
-               return diskCachedDiscovery, err
-
-       case traitv1.MemoryDiscoveryCache:
-               if memoryCachedDiscovery != nil {
-                       return memoryCachedDiscovery, nil
-               }
-               memoryCachedDiscovery = 
memory.NewMemCacheClient(t.Client.Discovery())
-               return memoryCachedDiscovery, nil
-
-       case traitv1.DisabledDiscoveryCache, "":
-               return t.Client.Discovery(), nil
-
-       default:
-               return nil, fmt.Errorf("unsupported discovery cache type: %s", 
*t.DiscoveryCache)
-       }
-}
diff --git a/resources/traits.yaml b/resources/traits.yaml
index 3cee61d7e..bddc6cf90 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -440,8 +440,8 @@ traits:
       property.
   - name: discovery-cache
     type: github.com/apache/camel-k/pkg/apis/camel/v1/trait.DiscoveryCacheType
-    description: Discovery client cache to be used, either `disabled`, `disk` 
or `memory`
-      (default `memory`)
+    description: 'Discovery client cache to be used, either `disabled`, `disk` 
or
+      `memory` (default `memory`). Deprecated: to be removed from trait 
configuration.'
 - name: health
   platform: false
   profiles:

Reply via email to