Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle removal of legacy access restriction #2196

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions frontend/__fixtures__/cloudprofiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ export default [
],
},
],
labels: {
'seed.gardener.cloud/eu-access': 'true',
},
accessRestrictions: [{
name: 'eu-access-only',
}],
},
{
name: 'eu-west-1',
Expand All @@ -424,9 +424,9 @@ export default [
],
},
],
labels: {
'seed.gardener.cloud/eu-access': 'true',
},
accessRestrictions: [{
name: 'eu-access-only',
}],
},
{
name: 'us-east-1',
Expand Down Expand Up @@ -535,9 +535,9 @@ export default [
],
},
],
labels: {
'seed.gardener.cloud/eu-access': 'true',
},
accessRestrictions: [{
name: 'eu-access-only',
}],
},
{
name: 'eastus',
Expand Down Expand Up @@ -713,9 +713,9 @@ export default [
],
},
],
labels: {
'seed.gardener.cloud/eu-access': 'true',
},
accessRestrictions: [{
name: 'eu-access-only',
}],
},
{
name: 'na-us-1',
Expand Down Expand Up @@ -895,9 +895,9 @@ export default [
],
},
],
labels: {
'seed.gardener.cloud/eu-access': 'true',
},
accessRestrictions: [{
name: 'eu-access-only',
}],
},
{
name: 'na-us-2',
Expand Down
2 changes: 1 addition & 1 deletion frontend/__fixtures__/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default {
noItemsText: 'Limited Access services for certain cloud providers and regions',
items: [
{
key: 'seed.gardener.cloud/eu-access',
key: 'eu-access-only',
display: {
title: 'Limited Access',
description: 'Clusters will not be migrated ...',
Expand Down
45 changes: 43 additions & 2 deletions frontend/src/composables/useShootAccessRestrictions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
// SPDX-License-Identifier: Apache-2.0
//

import { computed } from 'vue'
import {
computed,
ref,
} from 'vue'

import { useCloudProfileStore } from '@/store/cloudProfile'

import { NAND } from './helper'

import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'
import set from 'lodash/set'
import unset from 'lodash/unset'
import keyBy from 'lodash/keyBy'
Expand All @@ -33,6 +37,8 @@ export const useShootAccessRestrictions = (shootItem, options = {}) => {
return computed(() => get(shootItem.value, path))
})

const unsetLegacyAccessRestriction = ref(false)

const accessRestrictionDefinitionList = computed(() => {
return cloudProfileStore.accessRestrictionDefinitionsByCloudProfileNameAndRegion({
cloudProfileName: cloudProfileName.value,
Expand Down Expand Up @@ -100,10 +106,21 @@ export const useShootAccessRestrictions = (shootItem, options = {}) => {
if (index === -1) {
accessRestrictions.push({ name: key })
}

// TODO(petersutter): remove this block after gardener has dropped the access restriction sync logic for spec.seedSelector.matchLabels
if (key === 'eu-access-only') {
unsetLegacyAccessRestriction.value = false
}
} else {
if (index !== -1) {
accessRestrictions.splice(index, 1)
}

// TODO(petersutter): remove this block after gardener has dropped the access restriction sync logic for spec.seedSelector.matchLabels
if (key === 'eu-access-only') {
// Due to the migration/sync logic in g/g, to deactivate the `eu-access-only` access restriction, both `spec.AccessRestriction[@name="eu-access-only"]` and `spec.seedSelector.matchLabels["seed.gardener.cloud/eu-access"]` must be removed at the same time.
unsetLegacyAccessRestriction.value = true
}
}
setAccessRestrictions(accessRestrictions)
}
Expand Down Expand Up @@ -141,11 +158,35 @@ export const useShootAccessRestrictions = (shootItem, options = {}) => {

function getAccessRestrictionPatchData () {
const accessRestrictions = get(shootItem.value, ['spec', 'accessRestrictions'], [])
return {
const data = {
spec: {
accessRestrictions,
},
}

// TODO(petersutter): remove this block after gardener has dropped the access restriction sync logic for spec.seedSelector.matchLabels
if (unsetLegacyAccessRestriction.value) {
let seedSelector = get(shootItem.value, ['spec', 'seedSelector'])

unset(seedSelector, ['matchLabels', 'seed.gardener.cloud/eu-access'])

if (isEmpty(get(seedSelector, ['matchLabels']))) {
unset(seedSelector, ['matchLabels'])
}

if (isEmpty(seedSelector)) {
seedSelector = null
}

data.spec.seedSelector = seedSelector
data.metadata = {
annotations: {
'support.gardener.cloud/eu-access-for-cluster-addons': null,
'support.gardener.cloud/eu-access-for-cluster-nodes': null,
},
}
}
return data
}

const accessRestrictionList = computed(() => {
Expand Down
21 changes: 20 additions & 1 deletion frontend/src/store/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,26 @@ export const useConfigStore = defineStore('config', () => {
})

const accessRestriction = computed(() => {
return state.value?.accessRestriction
// TODO(petersutter): remove mapping from seed.gardener.cloud/eu-access to eu-access-only in dashboard version >=1.80.0. Add breaking change release note.
const accessRestriction = state.value?.accessRestriction
if (!accessRestriction) {
return
}

const items = map(accessRestriction.items, item => {
if (item.key === 'seed.gardener.cloud/eu-access') {
return {
...item,
key: 'eu-access-only',
}
}
return item
})

return {
...accessRestriction,
items,
}
})

const sla = computed(() => {
Expand Down