Skip to content

Commit

Permalink
Use lodash chaining to resolve secretbinding quotas
Browse files Browse the repository at this point in the history
  • Loading branch information
grolu committed Dec 2, 2024
1 parent 36bc5ed commit 2e1afb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
25 changes: 15 additions & 10 deletions backend/lib/services/cloudProviderCredentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota1",
"namespace": "garden-foo",
"uid": 2,
},
"spec": {
"clusterLifetimeDays": 14,
Expand All @@ -457,7 +456,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota2",
"namespace": "garden-foo",
"uid": 3,
},
"spec": {
"clusterLifetimeDays": 14,
Expand All @@ -471,7 +469,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota1",
"namespace": "garden-foo",
"uid": 2,
},
"spec": {
"clusterLifetimeDays": 14,
Expand All @@ -485,7 +482,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota2",
"namespace": "garden-foo",
"uid": 3,
},
"spec": {
"clusterLifetimeDays": 14,
Expand All @@ -499,7 +495,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota1",
"namespace": "garden-foo",
"uid": 2,
},
"spec": {
"clusterLifetimeDays": 14,
Expand All @@ -513,7 +508,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota2",
"namespace": "garden-foo",
"uid": 3,
},
"spec": {
"clusterLifetimeDays": 14,
Expand All @@ -527,7 +521,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota1",
"namespace": "garden-foo",
"uid": 2,
},
"spec": {
"clusterLifetimeDays": 14,
Expand All @@ -541,7 +534,6 @@ exports[`api cloudproviderCredentials should return three cloudProvider credenti
"metadata": {
"name": "foo-quota2",
"namespace": "garden-foo",
"uid": 3,
},
"spec": {
"clusterLifetimeDays": 14,
Expand Down

0 comments on commit 2e1afb0

Please sign in to comment.