From 2e1afb0c747f41e4f81e24af1e489113210c37dd Mon Sep 17 00:00:00 2001 From: "Gross, Lukas" Date: Mon, 2 Dec 2024 12:59:38 +0100 Subject: [PATCH] Use lodash chaining to resolve secretbinding quotas --- .../lib/services/cloudProviderCredentials.js | 25 +++++++++++-------- .../api.cloudProviderCredentials.spec.js.snap | 8 ------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/backend/lib/services/cloudProviderCredentials.js b/backend/lib/services/cloudProviderCredentials.js index f41ef75769..9b6384cc76 100644 --- a/backend/lib/services/cloudProviderCredentials.js +++ b/backend/lib/services/cloudProviderCredentials.js @@ -23,16 +23,21 @@ exports.list = async function ({ user, params }) { client.core.secrets.list(secretBindingNamespace, { labelSelector: 'reference.gardener.cloud/secretbinding=true' }), ]) - const quotas = _.flatMap(secretBindings, secretBinding => { - const bindingQuotas = resolveQuotas(secretBinding) - const clusterLifetimeQuotas = _.filter(bindingQuotas, 'spec.clusterLifetimeDays') - return _.flatMap(clusterLifetimeQuotas, ({ metadata, spec }) => { - return { - metadata: _.pick(metadata, ['name', 'namespace', 'uid']), - spec: _.pick(spec, ['clusterLifetimeDays', 'scope']), - } - }) - }) + const pickQuotaProperties = _.partialRight(_.pick, [ + 'apiVersion', + 'kind', + 'metadata.name', + 'metadata.namespace', + 'spec.scope', + 'spec.clusterLifetimeDays', + ]) + + const quotas = _ + .chain(secretBindings) + .flatMap(secretBinding => resolveQuotas(secretBinding)) + .filter('spec.clusterLifetimeDays') + .map(pickQuotaProperties) + .value() return { secretBindings, diff --git a/backend/test/acceptance/__snapshots__/api.cloudProviderCredentials.spec.js.snap b/backend/test/acceptance/__snapshots__/api.cloudProviderCredentials.spec.js.snap index 01bb27128d..19fece6a70 100644 --- a/backend/test/acceptance/__snapshots__/api.cloudProviderCredentials.spec.js.snap +++ b/backend/test/acceptance/__snapshots__/api.cloudProviderCredentials.spec.js.snap @@ -443,7 +443,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota1", "namespace": "garden-foo", - "uid": 2, }, "spec": { "clusterLifetimeDays": 14, @@ -457,7 +456,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota2", "namespace": "garden-foo", - "uid": 3, }, "spec": { "clusterLifetimeDays": 14, @@ -471,7 +469,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota1", "namespace": "garden-foo", - "uid": 2, }, "spec": { "clusterLifetimeDays": 14, @@ -485,7 +482,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota2", "namespace": "garden-foo", - "uid": 3, }, "spec": { "clusterLifetimeDays": 14, @@ -499,7 +495,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota1", "namespace": "garden-foo", - "uid": 2, }, "spec": { "clusterLifetimeDays": 14, @@ -513,7 +508,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota2", "namespace": "garden-foo", - "uid": 3, }, "spec": { "clusterLifetimeDays": 14, @@ -527,7 +521,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota1", "namespace": "garden-foo", - "uid": 2, }, "spec": { "clusterLifetimeDays": 14, @@ -541,7 +534,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti "metadata": { "name": "foo-quota2", "namespace": "garden-foo", - "uid": 3, }, "spec": { "clusterLifetimeDays": 14,