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

Hap Rule Configs Wiring #1644

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions cmd/broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"

"github.com/kyma-project/kyma-environment-broker/internal/expiration"
"github.com/kyma-project/kyma-environment-broker/internal/hap"
"github.com/kyma-project/kyma-environment-broker/internal/metricsv2"
"github.com/kyma-project/kyma-environment-broker/internal/whitelist"

Expand Down Expand Up @@ -142,6 +143,7 @@ type Config struct {
Events events.Config

MetricsV2 metricsv2.Config
Hap hap.Config

Provisioning process.StagedManagerConfiguration
Deprovisioning process.StagedManagerConfiguration
Expand Down
2 changes: 1 addition & 1 deletion cmd/broker/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewProvisioningProcessingQueue(ctx context.Context, provisionManager *proce
},
{
stage: createRuntimeStageName,
step: provisioning.NewResolveCredentialsStep(db.Operations(), accountProvider),
step: provisioning.NewResolveCredentialsStep(db.Operations(), accountProvider, cfg.Hap),
condition: provisioning.SkipForOwnClusterPlan,
},
{
Expand Down
12 changes: 12 additions & 0 deletions internal/hap/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hap

import (
"github.com/kyma-project/kyma-environment-broker/internal/utils"
)

type Config struct {
SharedRule utils.Whitelist `envconfig`
euAccessRule utils.Whitelist `envconfig`
clusterRegionRule utils.Whitelist `envconfig`
platformRegionRule utils.Whitelist `envconfig`
}
37 changes: 37 additions & 0 deletions internal/hap/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package hap

import (
"os"
"testing"

"github.com/stretchr/testify/require"
"github.com/vrischmann/envconfig"
)

func TestHyperscalerConfigs(t *testing.T) {

t.Run("should read default values from env variables", func(t *testing.T) {
// given
var cfg Config
err := envconfig.InitWithPrefix(&cfg, "APP_HAP")
require.NoError(t, err)

require.True(t, cfg.SharedSecretPlans.Contains("trial:*"))

Check failure on line 19 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)

Check failure on line 19 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)
require.True(t, cfg.SharedSecretPlans.Contains("sap-converged-cloud:*"))

Check failure on line 20 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)

Check failure on line 20 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)
})

t.Run("should read single values from env variables", func(t *testing.T) {
err := os.Setenv("APP_HAP_SHARED_SECRET_PLANS", "aws:*;azure:*;gcp:eu1")
require.NoError(t, err)

// given
var cfg Config
err = envconfig.InitWithPrefix(&cfg, "APP_HAP")
require.NoError(t, err)

require.True(t, cfg.SharedSecretPlans.Contains("aws:*"))

Check failure on line 32 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)

Check failure on line 32 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)
require.False(t, cfg.SharedSecretPlans.Contains("azure"))

Check failure on line 33 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)

Check failure on line 33 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)
require.True(t, cfg.SharedSecretPlans.Contains("azure:*"))

Check failure on line 34 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)

Check failure on line 34 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)
require.True(t, cfg.SharedSecretPlans.Contains("gcp:eu1"))

Check failure on line 35 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-linter

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)

Check failure on line 35 in internal/hap/config_test.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

cfg.SharedSecretPlans undefined (type Config has no field or method SharedSecretPlans)
})
}
4 changes: 3 additions & 1 deletion internal/process/provisioning/resolve_creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
accountProvider hyperscaler.AccountProvider
opStorage storage.Operations
tenant string
hapConfig *hap.Config

Check failure on line 26 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-govulncheck

undefined: hap

Check failure on line 26 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-go-linter

undefined: hap

Check failure on line 26 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-go-linter

undefined: hap

Check failure on line 26 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

undefined: hap
}

func NewResolveCredentialsStep(os storage.Operations, accountProvider hyperscaler.AccountProvider) *ResolveCredentialsStep {
func NewResolveCredentialsStep(os storage.Operations, accountProvider hyperscaler.AccountProvider, hapConfig hap.Config) *ResolveCredentialsStep {

Check failure on line 29 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-govulncheck

undefined: hap

Check failure on line 29 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-go-linter

undefined: hap)

Check failure on line 29 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-go-linter

undefined: hap

Check failure on line 29 in internal/process/provisioning/resolve_creds.go

View workflow job for this annotation

GitHub Actions / run-go-tests / build

undefined: hap
step := &ResolveCredentialsStep{
opStorage: os,
accountProvider: accountProvider,
hapConfig: &hapConfig,
}
step.operationManager = process.NewOperationManager(os, step.Name(), kebError.AccountPoolDependency)
return step
Expand Down
22 changes: 12 additions & 10 deletions internal/process/provisioning/resolve_creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/kyma-project/kyma-environment-broker/common/gardener"
pkg "github.com/kyma-project/kyma-environment-broker/common/runtime"
"github.com/kyma-project/kyma-environment-broker/internal/fixture"
"github.com/kyma-project/kyma-environment-broker/internal/hap"
"github.com/kyma-project/kyma-environment-broker/internal/utils"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

Expand Down Expand Up @@ -41,7 +43,7 @@ func TestResolveCredentialsStepHappyPath_Run(t *testing.T) {
accountProviderMock := &hyperscalerMocks.AccountProvider{}
accountProviderMock.On("GardenerSecretName", hyperscaler.GCP("westeurope"), statusGlobalAccountID, false).Return("gardener-secret-gcp", nil)

step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock, hap.Config{})

// when
operation, repeat, err := step.Run(operation, fixLogger())
Expand All @@ -68,7 +70,7 @@ func TestResolveCredentialsEUStepHappyPath_Run(t *testing.T) {
accountProviderMock := &hyperscalerMocks.AccountProvider{}
accountProviderMock.On("GardenerSecretName", hyperscaler.AWS(), statusGlobalAccountID, true).Return("gardener-secret-aws", nil)

step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock, hap.Config{})

// when
operation, repeat, err := step.Run(operation, fixLogger())
Expand All @@ -95,7 +97,7 @@ func TestResolveCredentialsCHStepHappyPath_Run(t *testing.T) {
accountProviderMock := &hyperscalerMocks.AccountProvider{}
accountProviderMock.On("GardenerSecretName", hyperscaler.Azure(), statusGlobalAccountID, true).Return("gardener-secret-az", nil)

step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock, hap.Config{})

// when
operation, repeat, err := step.Run(operation, fixLogger())
Expand All @@ -121,7 +123,7 @@ func TestResolveCredentialsStepHappyPathTrialDefaultProvider_Run(t *testing.T) {
accountProviderMock := &hyperscalerMocks.AccountProvider{}
accountProviderMock.On("GardenerSharedSecretName", hyperscaler.Azure(), false).Return("gardener-secret-azure", nil)

step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock, hap.Config{})

// when
operation, repeat, err := step.Run(operation, fixLogger())
Expand All @@ -148,7 +150,7 @@ func TestResolveCredentialsStepHappyPathTrialGivenProvider_Run(t *testing.T) {
accountProviderMock := &hyperscalerMocks.AccountProvider{}
accountProviderMock.On("GardenerSharedSecretName", hyperscaler.GCP("westeurope"), false).Return("gardener-secret-gcp", nil)

step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock, hap.Config{})

// when
operation, repeat, err := step.Run(operation, fixLogger())
Expand All @@ -174,7 +176,7 @@ func TestResolveCredentialsStepRetry_Run(t *testing.T) {
accountProviderMock := &hyperscalerMocks.AccountProvider{}
accountProviderMock.On("GardenerSecretName", hyperscaler.GCP("westeurope"), statusGlobalAccountID, false).Return("", fmt.Errorf("Failed!"))

step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProviderMock, hap.Config{})

operation.UpdatedAt = time.Now()

Expand Down Expand Up @@ -208,7 +210,7 @@ func TestResolveCredentials_IntegrationAWS(t *testing.T) {
op := fixOperationWithPlatformRegion("cf-us10", pkg.AWS)
err := memoryStorage.Operations().InsertOperation(op)
assert.NoError(t, err)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider, hap.Config{})

// when
operation, backoff, err := step.Run(op, fixLogger())
Expand All @@ -232,7 +234,7 @@ func TestResolveCredentials_IntegrationAWSEuAccess(t *testing.T) {
op := fixOperationWithPlatformRegion("cf-eu11", pkg.AWS)
err := memoryStorage.Operations().InsertOperation(op)
assert.NoError(t, err)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider, hap.Config{})

// when
operation, backoff, err := step.Run(op, fixLogger())
Expand All @@ -254,7 +256,7 @@ func TestResolveCredentials_IntegrationAzure(t *testing.T) {
op := fixOperationWithPlatformRegion("cf-eu21", pkg.Azure)
err := memoryStorage.Operations().InsertOperation(op)
assert.NoError(t, err)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider, hap.Config{})

// when
operation, backoff, err := step.Run(op, fixLogger())
Expand All @@ -278,7 +280,7 @@ func TestResolveCredentials_IntegrationAzureEuAccess(t *testing.T) {
op := fixOperationWithPlatformRegion("cf-ch20", pkg.Azure)
err := memoryStorage.Operations().InsertOperation(op)
assert.NoError(t, err)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider)
step := NewResolveCredentialsStep(memoryStorage.Operations(), accountProvider, hap.Config{})

// when
operation, backoff, err := step.Run(op, fixLogger())
Expand Down
39 changes: 39 additions & 0 deletions internal/utils/whitelist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package utils

import (
"sort"
"strings"
)

type Whitelist map[string]struct{}

func (t *Whitelist) Unmarshal(s string) error {
*t = make(Whitelist)

for _, item := range strings.Split(s, ";") {
(*t)[item] = struct{}{}
}

return nil
}

func (t *Whitelist) Contains(item string) bool {
_, found := (*t)[item]
return found
}

func (t Whitelist) String() string {
keys := make([]string, 0, len(t))
for item := range t {
keys = append(keys, item)
}

sort.Strings(keys)

output := ""
for _, item := range keys {
output += item + ";"
}

return output
}
34 changes: 34 additions & 0 deletions internal/utils/whitelist_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package utils

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
)

func TestWhitelist(t *testing.T) {

t.Run("should unmarshal from string representation", func(t *testing.T) {
// given
whitelist := Whitelist{}

// when
err := whitelist.Unmarshal("key1;key2")
require.NoError(t, err)

// then
require.True(t, whitelist.Contains("key1"))
require.True(t, whitelist.Contains("key2"))
require.False(t, whitelist.Contains("key3"))
})

t.Run("should print all values", func(t *testing.T) {
// given
whitelist := Whitelist{"key1": struct{}{}, "key2": struct{}{}}

// then
require.Equal(t, "key1;key2;", whitelist.String())
require.Equal(t, "key1;key2;", fmt.Sprint(whitelist))
})
}
8 changes: 8 additions & 0 deletions resources/keb/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ spec:
value: "{{ .Values.broker.subaccountMovementEnabled }}"
- name: APP_BROKER_UPDATE_CUSTOM_RESOURCES_LABELS_ON_ACCOUNT_MOVE
value: "{{ .Values.broker.updateCustomResourcesLabelsOnAccountMove }}"
- name: APP_HAP_PLATFORM_REGION_RULE
value: "{{ .Values.hap.platformRegionRule }}"
- name: APP_HAP_CLUSTER_REGION_RULE
value: "{{ .Values.hap.clusterRegionRule }}"
- name: APP_HAP_SHARED_RULE
value: "{{ .Values.hap.sharedRule }}"
- name: APP_HAP_EU_ACCESS_RULE
value: "{{ .Values.hap.euAccessRule }}"
ports:
- name: http
containerPort: {{ .Values.broker.port }}
Expand Down
5 changes: 5 additions & 0 deletions resources/keb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ sapConvergedCloudPlanRegionMappings: |-
disableSapConvergedCloud: false
disableProcessOperationsInProgress: "false"
enablePlans: "azure,gcp,azure_lite,trial"
hap:
platformRegionRule: "gcp:cf-sa30"
clusterRegionRule: "sap-converged-cloud"
sharedRule: "trial;sap-converged-cloud"
euAccessRule: "azure:cf-ch20;aws:cf-eu11"
onlySingleTrialPerGA: "true"
enableKubeconfigURLLabel: "false"
includeAdditionalParamsInSchema: "false"
Expand Down
Loading