From f4201483564e83df774daa437450bff0afe091af Mon Sep 17 00:00:00 2001 From: Pieszka Date: Mon, 15 Jul 2024 20:15:10 +0200 Subject: [PATCH 1/3] initial commit logging KymaTemplate length fixture with kymaTemplate --- .../create_runtime_resource_step.go | 35 ++++++++++--------- .../create_runtime_resource_step_test.go | 13 +++++++ internal/process/staged_manager.go | 1 + 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/internal/process/provisioning/create_runtime_resource_step.go b/internal/process/provisioning/create_runtime_resource_step.go index 1162b255c1..7156e9e8a5 100644 --- a/internal/process/provisioning/create_runtime_resource_step.go +++ b/internal/process/provisioning/create_runtime_resource_step.go @@ -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" @@ -93,11 +92,9 @@ func (s *CreateRuntimeResourceStep) createRuntimeResourceObject(operation intern 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 } @@ -126,24 +123,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 +} diff --git a/internal/process/provisioning/create_runtime_resource_step_test.go b/internal/process/provisioning/create_runtime_resource_step_test.go index 28614e5d8c..c4c3a62664 100644 --- a/internal/process/provisioning/create_runtime_resource_step_test.go +++ b/internal/process/provisioning/create_runtime_resource_step_test.go @@ -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) assert.NoError(t, err) diff --git a/internal/process/staged_manager.go b/internal/process/staged_manager.go index 6772c9e218..b9d879c5aa 100644 --- a/internal/process/staged_manager.go +++ b/internal/process/staged_manager.go @@ -231,6 +231,7 @@ func (m *StagedManager) runStep(step Step, operation internal.Operation, logger logger.Infof("Start step") stepLogger := logger.WithFields(logrus.Fields{"step": step.Name(), "operation": processedOperation.ID}) processedOperation, backoff, err = step.Run(processedOperation, stepLogger) + stepLogger.Infof("!!!KymaTemplate len: %d", len(processedOperation.KymaTemplate)) if err != nil { processedOperation.LastError = kebError.ReasonForError(err) logOperation := stepLogger.WithFields(logrus.Fields{"error_component": processedOperation.LastError.Component(), "error_reason": processedOperation.LastError.Reason()}) From 8a72cb9d211081d3a55a73831554c5fd70ce57f7 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Mon, 15 Jul 2024 20:22:33 +0200 Subject: [PATCH 2/3] make fix --- go.mod | 2 +- .../create_runtime_resource_step.go | 20 +++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index f465a35fdd..8b569541f1 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/internal/process/provisioning/create_runtime_resource_step.go b/internal/process/provisioning/create_runtime_resource_step.go index 7156e9e8a5..3093f662cc 100644 --- a/internal/process/provisioning/create_runtime_resource_step.go +++ b/internal/process/provisioning/create_runtime_resource_step.go @@ -50,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 { @@ -74,21 +77,12 @@ 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 From eab39c7659ce5644c274c2a3b802ee94ed2341d1 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Mon, 15 Jul 2024 20:23:58 +0200 Subject: [PATCH 3/3] log in staged manager removed --- internal/process/staged_manager.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/process/staged_manager.go b/internal/process/staged_manager.go index b9d879c5aa..6772c9e218 100644 --- a/internal/process/staged_manager.go +++ b/internal/process/staged_manager.go @@ -231,7 +231,6 @@ func (m *StagedManager) runStep(step Step, operation internal.Operation, logger logger.Infof("Start step") stepLogger := logger.WithFields(logrus.Fields{"step": step.Name(), "operation": processedOperation.ID}) processedOperation, backoff, err = step.Run(processedOperation, stepLogger) - stepLogger.Infof("!!!KymaTemplate len: %d", len(processedOperation.KymaTemplate)) if err != nil { processedOperation.LastError = kebError.ReasonForError(err) logOperation := stepLogger.WithFields(logrus.Fields{"error_component": processedOperation.LastError.Component(), "error_reason": processedOperation.LastError.Reason()})