Skip to content

Commit

Permalink
labels initialize
Browse files Browse the repository at this point in the history
yaml library changed

more labels set properly

TODOs added

commas corrected

TODOs removed
  • Loading branch information
jaroslaw-pieszka committed Jul 11, 2024
1 parent 68b07de commit ae11cf6
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package provisioning

import (
"fmt"
"sigs.k8s.io/yaml"

Check failure on line 5 in internal/process/provisioning/create_runtime_resource_step.go

View workflow job for this annotation

GitHub Actions / run-go-linter

File is not `goimports`-ed (goimports)
"time"

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"

"github.com/kyma-project/kyma-environment-broker/internal/kim"
"gopkg.in/yaml.v3"

"github.com/kyma-project/kyma-environment-broker/internal"
"github.com/kyma-project/kyma-environment-broker/internal/process"
Expand Down Expand Up @@ -54,9 +56,9 @@ func (s *CreateRuntimeResourceStep) Run(operation internal.Operation, log logrus
if s.kimConfig.DryRun {
yaml, err := RuntimeToYaml(runtimeCR)
if err != nil {
log.Errorf("failed to encode Runtime CR to yaml: %s", err)
log.Errorf("failed to encode Runtime CR as yaml: %s", err)
} else {
log.Infof("Runtime CR yaml:%s", yaml)
fmt.Println(yaml)
}
} else {
err := s.CreateResource(runtimeCR)
Expand All @@ -75,11 +77,30 @@ func (s *CreateRuntimeResourceStep) CreateResource(cr *imv1.Runtime) error {

func (s *CreateRuntimeResourceStep) createRuntimeResourceObject(operation internal.Operation) (*imv1.Runtime, error) {
runtime := imv1.Runtime{}
runtime.Spec.Shoot.Name = "shoot-name"
runtime.ObjectMeta.Name = operation.RuntimeID
runtime.ObjectMeta.Namespace = operation.KymaResourceNamespace
runtime.ObjectMeta.Labels = createLabelsForRuntime(operation)
runtime.Spec.Shoot.Provider.Type = string(operation.ProvisioningParameters.PlatformProvider)
runtime.Spec.Shoot.Provider.Workers = []gardener.Worker{}

return &runtime, nil
}

func createLabelsForRuntime(operation internal.Operation) map[string]string {
labels := map[string]string{
"kyma-project.io/instance-id": operation.InstanceID,
"kyma-project.io/runtime-id": operation.RuntimeID,
"kyma-project.io/broker-plan-id": operation.ProvisioningParameters.PlanID,
"kyma-project.io/broker-plan-name": broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID],
"kyma-project.io/global-account-id": operation.ProvisioningParameters.ErsContext.GlobalAccountID,
"kyma-project.io/subaccount-id": operation.ProvisioningParameters.ErsContext.SubAccountID,
"kyma-project.io/shoot-name": operation.ShootName,
"kyma-project.io/region": *operation.ProvisioningParameters.Parameters.Region,
"operator.kyma-project.io/kyma-name": operation.KymaResourceName,
}
return labels
}

func RuntimeToYaml(runtime *imv1.Runtime) (string, error) {
result, err := yaml.Marshal(runtime)
if err != nil {
Expand Down

0 comments on commit ae11cf6

Please sign in to comment.