Skip to content

Commit

Permalink
cloud provider added to runtime CR
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslaw-pieszka committed Oct 30, 2024
1 parent 1ecfd2d commit 3cbcb6f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
7 changes: 5 additions & 2 deletions internal/process/provisioning/create_runtime_resource_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ func (s *CreateRuntimeResourceStep) updateRuntimeResourceObject(runtime *imv1.Ru
}
runtime.ObjectMeta.Name = runtimeName
runtime.ObjectMeta.Namespace = operation.KymaResourceNamespace
runtime.ObjectMeta.Labels = s.createLabelsForRuntime(operation, values.Region)

cloudProvider := string(provider.ProviderToCloudProvider(values.ProviderType))
runtime.ObjectMeta.Labels = s.createLabelsForRuntime(operation, values.Region, cloudProvider)

providerObj, err := s.createShootProvider(&operation, values)
if err != nil {
Expand All @@ -161,7 +163,7 @@ func (s *CreateRuntimeResourceStep) updateRuntimeResourceObject(runtime *imv1.Ru
return nil
}

func (s *CreateRuntimeResourceStep) createLabelsForRuntime(operation internal.Operation, region string) map[string]string {
func (s *CreateRuntimeResourceStep) createLabelsForRuntime(operation internal.Operation, region string, cloudProvider string) map[string]string {
labels := map[string]string{
"kyma-project.io/instance-id": operation.InstanceID,
"kyma-project.io/runtime-id": operation.RuntimeID,
Expand All @@ -172,6 +174,7 @@ func (s *CreateRuntimeResourceStep) createLabelsForRuntime(operation internal.Op
"kyma-project.io/shoot-name": operation.ShootName,
"kyma-project.io/region": region,
"operator.kyma-project.io/kyma-name": operation.KymaResourceName,
"kyma-project.io/provider": cloudProvider,
}
controlledByProvisioner := s.kimConfig.ViewOnly && !s.kimConfig.IsDrivenByKimOnly(broker.PlanNamesMapping[operation.ProvisioningParameters.PlanID])
labels[imv1.LabelControlledByProvisioner] = strconv.FormatBool(controlledByProvisioner)
Expand Down
37 changes: 18 additions & 19 deletions internal/process/steps/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
ShootNameLabel = "kyma-project.io/shoot-name"
RegionLabel = "kyma-project.io/region"
PlatformRegionLabel = "kyma-project.io/platform-region"
ProviderLabel = "kyma-project.io/provider"
CloudProviderLabel = "kyma-project.io/provider"
KymaNameLabel = "operator.kyma-project.io/kyma-name"
ManagedByLabel = "operator.kyma-project.io/managed-by"
InternalLabel = "operator.kyma-project.io/internal"
Expand All @@ -33,24 +33,23 @@ func setCommonLabels(labels map[string]string, operation internal.Operation) map
labels[PlatformRegionLabel] = operation.ProvisioningParameters.PlatformRegion
}
labels[KymaNameLabel] = operation.KymaResourceName
labels[ProviderLabel] = string(operation.InputCreator.Provider()) //TODO change internal.CloudProvider
return labels
}

// TODO move it to lifecycle_manager.go
//func setLabelsForLM(labels map[string]string, operation internal.Operation) map[string]string {
// labels = setCommonLabels(labels, operation)
// labels[RegionLabel] = operation.Region
// labels[ManagedByLabel] = "lifecycle-manager"
// if steps.isKymaResourceInternal(operation) {
// labels[InternalLabel] = "true"
// }
// return labels
//}
//
//// TODO move it to create_runtime_resource_step.go
//func setLabelsForRuntime(labels map[string]string, operation internal.Operation, region string) map[string]string {
// labels = setCommonLabels(labels, operation)
// labels[RegionLabel] = region
// return labels
//}
func setLabelsForLM(labels map[string]string, operation internal.Operation) map[string]string {
labels = setCommonLabels(labels, operation)
labels[RegionLabel] = operation.Region
labels[ManagedByLabel] = "lifecycle-manager"
labels[CloudProviderLabel] = string(operation.InputCreator.Provider()) //TODO change internal.CloudProvider
if isKymaResourceInternal(operation) {
labels[InternalLabel] = "true"
}
return labels
}

func setLabelsForRuntime(labels map[string]string, operation internal.Operation, region string, cloudProvider string) map[string]string {
labels = setCommonLabels(labels, operation)
labels[RegionLabel] = region
labels[CloudProviderLabel] = cloudProvider
return labels
}
15 changes: 15 additions & 0 deletions internal/provider/provider_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,18 @@ func GenerateValues(
}
return p.Provide(), nil
}

func ProviderToCloudProvider(providerType string) internal.CloudProvider {
switch providerType {
case "azure":
return internal.Azure
case "aws":
return internal.AWS
case "gcp":
return internal.GCP
case "openstack":
return internal.SapConvergedCloud
default:
return internal.UnknownProvider
}
}

0 comments on commit 3cbcb6f

Please sign in to comment.