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

KymaResourceName and KymaResourceNamespace - KIM integration - phase 1 #931

Closed
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: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/dlmiddlecote/sqlstats v1.0.2
github.com/docker/docker v27.0.3+incompatible
github.com/docker/go-connections v0.5.0
github.com/gardener/gardener v1.99.0
github.com/go-co-op/gocron v1.37.0
github.com/gocraft/dbr v0.0.0-20190714181702-8114670a83bd
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -67,6 +66,7 @@ require (
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gardener/gardener v1.99.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
Expand Down
55 changes: 26 additions & 29 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"sigs.k8s.io/yaml"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"github.com/kyma-project/kyma-environment-broker/internal/broker"

Expand Down Expand Up @@ -51,15 +50,18 @@ func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log logrus
return operation, 0, nil
}

kymaResourceName, kymaResourceNamespace := getKymaNames(operation)
kymaResourceName, err := getKymaName(operation)
if err != nil {
return s.operationManager.OperationFailed(operation, fmt.Sprintf("while getting Kyma name: %s", err), err, log)
}

runtimeCR, err := s.createRuntimeResourceObject(operation, kymaResourceName, kymaResourceNamespace)
runtimeCR, err := s.createRuntimeResourceObject(operation, kymaResourceName)
if err != nil {
return s.operationManager.OperationFailed(operation, fmt.Sprintf("while creating Runtime CR object: %s", err), err, log)
}

if s.kimConfig.DryRun {
yaml, err := RuntimeToYaml(runtimeCR)
yaml, err := runtimeToYaml(runtimeCR)
if err != nil {
log.Errorf("failed to encode Runtime CR as yaml: %s", err)
} else {
Expand All @@ -75,29 +77,18 @@ func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log logrus
return operation, 0, nil
}

func getKymaNames(operation internal.Operation) (string, string) {
template, err := steps.DecodeKymaTemplate(operation.KymaTemplate)
if err != nil {
//TODO remove fallback
return "", ""
}
return template.GetName(), template.GetNamespace()
}

func (s *CreateRuntimeResourceStep) CreateResource(cr *imv1.Runtime) error {
logrus.Info("Creating Runtime CR - TO BE IMPLEMENTED")
return nil
}

func (s *CreateRuntimeResourceStep) createRuntimeResourceObject(operation internal.Operation, kymaName, kymaNamespace string) (*imv1.Runtime, error) {
func (s *CreateRuntimeResourceStep) createRuntimeResourceObject(operation internal.Operation, kymaName string) (*imv1.Runtime, error) {

runtime := imv1.Runtime{}
runtime.ObjectMeta.Name = operation.RuntimeID
runtime.ObjectMeta.Namespace = kymaNamespace
runtime.ObjectMeta.Namespace = operation.KymaResourceNamespace
runtime.ObjectMeta.Labels = s.createLabelsForRuntime(operation, kymaName)
runtime.Spec.Shoot.Provider = s.createShootProvider(operation)
runtime.Spec.Shoot.Provider.Workers = []gardener.Worker{}
runtime.Spec.Shoot.Provider.Type = string(operation.ProvisioningParameters.PlatformProvider)
runtime.Spec.Security = s.createSecurityConfiguration(operation)
return &runtime, nil
}
Expand Down Expand Up @@ -126,24 +117,30 @@ func (s *CreateRuntimeResourceStep) createLabelsForRuntime(operation internal.Op
func (s *CreateRuntimeResourceStep) createSecurityConfiguration(operation internal.Operation) imv1.Security {
security := imv1.Security{}
security.Administrators = operation.ProvisioningParameters.Parameters.RuntimeAdministrators
//TODO: Networking
//networking:
//filter:
// # spec.security.networking.filter.egress.enabled is required
//egress:
//enabled: false
// # spec.security.networking.filter.ingress.enabled is optional (default=false), not implemented in the first KIM release
// ingress:
// enabled: true

logrus.Info("Creating Security Configuration - UNDER CONSTRUCTION")
security.Networking.Filter.Egress.Enabled = false
// spec.security.networking.filter.ingress.enabled is optional (default=false), not implemented in the first KIM release
security.Networking.Filter.Ingress = &imv1.Ingress{
Enabled: false,
}

return security
}

func RuntimeToYaml(runtime *imv1.Runtime) (string, error) {
func runtimeToYaml(runtime *imv1.Runtime) (string, error) {
result, err := yaml.Marshal(runtime)
if err != nil {
return "", err
}
return string(result), nil
}

func getKymaName(operation internal.Operation) (string, error) {
if len(operation.KymaTemplate) == 0 {
return "", fmt.Errorf("KymaTemplate is empty")
}
template, err := steps.DecodeKymaTemplate(operation.KymaTemplate)
if err != nil {
return "", err
}
return template.GetName(), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ func TestCreateRuntimeResourceStep_HappyPath_YamlOnly(t *testing.T) {
memoryStorage := storage.NewMemoryStorage()

preOperation := fixture.FixProvisioningOperation(operationID, instanceID)
preOperation.KymaTemplate = `
apiVersion: operator.kyma-project.io/v1beta2
kind: Kyma
metadata:
name: gophers-test-kyma
namespace: kyma-system
spec:
sync:
strategy: secret
channel: stable
modules: []
`
preOperation.KymaResourceNamespace = "kyma-system"
err := memoryStorage.Operations().InsertOperation(preOperation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure that kyma template has proper name/namespace? let's discuss it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed, needs redesign. Probably in separate PR.

assert.NoError(t, err)

Expand Down
Loading