generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/go_modules/github.com/gardener/oi…
…dc-webhook-authenticator-0.32.0
- Loading branch information
Showing
11 changed files
with
134 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package extender | ||
|
||
import ( | ||
gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
imv1 "github.com/kyma-project/infrastructure-manager/api/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
seedRegionSelectorLabel = "seed.gardener.cloud/region" | ||
) | ||
|
||
// ExtendWithSeedSelector creates a new extender function that can enforce shoot seed location to be the same region as shoot | ||
// When EnforceSeedLocation flag in set on RuntimeCR to true it adds a special seedSelector field with labelSelector set to match seed region with shoot region | ||
func ExtendWithSeedSelector(runtime imv1.Runtime, shoot *gardener.Shoot) error { | ||
if runtime.Spec.Shoot.EnforceSeedLocation != nil && *runtime.Spec.Shoot.EnforceSeedLocation && runtime.Spec.Shoot.Region != "" { | ||
shoot.Spec.SeedSelector = &gardener.SeedSelector{ | ||
LabelSelector: metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
seedRegionSelectorLabel: runtime.Spec.Shoot.Region, | ||
}, | ||
}, | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package extender | ||
|
||
import ( | ||
"testing" | ||
|
||
imv1 "github.com/kyma-project/infrastructure-manager/api/v1" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSeedSelectorExtender(t *testing.T) { | ||
t.Run("Add and populate seed selector field if RuntimeCR has SeedInSameRegionFlag set to true", func(t *testing.T) { | ||
// given | ||
runtimeShoot := getRuntimeWithSeedInSameRegionFlag(true) | ||
shoot := fixEmptyGardenerShoot("test", "dev") | ||
|
||
// when | ||
err := ExtendWithSeedSelector(runtimeShoot, &shoot) | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.NotNil(t, shoot.Spec.SeedSelector) | ||
assert.Equal(t, runtimeShoot.Spec.Shoot.Region, shoot.Spec.SeedSelector.LabelSelector.MatchLabels[seedRegionSelectorLabel]) | ||
}) | ||
|
||
t.Run("Don't add seed selector field if RuntimeCR has SeedInSameRegionFlag set to false", func(t *testing.T) { | ||
// given | ||
runtimeShoot := getRuntimeWithSeedInSameRegionFlag(false) | ||
shoot := fixEmptyGardenerShoot("test", "dev") | ||
|
||
// when | ||
err := ExtendWithSeedSelector(runtimeShoot, &shoot) | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Nil(t, shoot.Spec.SeedSelector) | ||
}) | ||
|
||
t.Run("Don't add seed selector field if RuntimeCR has no SeedInSameRegionFlag set", func(t *testing.T) { | ||
// given | ||
runtimeShoot := getRuntimeWithoutSeedInSameRegionFlag() | ||
shoot := fixEmptyGardenerShoot("test", "dev") | ||
|
||
// when | ||
err := ExtendWithSeedSelector(runtimeShoot, &shoot) | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Nil(t, shoot.Spec.SeedSelector) | ||
}) | ||
} | ||
|
||
func getRuntimeWithSeedInSameRegionFlag(enabled bool) imv1.Runtime { | ||
return imv1.Runtime{ | ||
Spec: imv1.RuntimeSpec{ | ||
Shoot: imv1.RuntimeShoot{ | ||
Name: "myshoot", | ||
EnforceSeedLocation: &enabled, | ||
Region: "far-far-away", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func getRuntimeWithoutSeedInSameRegionFlag() imv1.Runtime { | ||
return imv1.Runtime{ | ||
Spec: imv1.RuntimeSpec{ | ||
Shoot: imv1.RuntimeShoot{ | ||
Name: "myshoot", | ||
Region: "far-far-away", | ||
}, | ||
}, | ||
} | ||
} |