Skip to content

Commit

Permalink
Fixes to make migrator up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
akgalwas committed Aug 6, 2024
1 parent 177cb8d commit de6eb8c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions hack/runtime-migrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func saveRuntime(ctx context.Context, cfg migrator.Config, runtime v1.Runtime, g
func createRuntime(ctx context.Context, shoot v1beta1.Shoot, cfg migrator.Config, provider kubeconfig.Provider) (v1.Runtime, error) {
var subjects = getAdministratorsList(ctx, provider, shoot.Name)
var oidcConfig = getOidcConfig(shoot)
var hAFailureToleranceType = getFailureToleranceType(shoot)
var licenceType = shoot.Annotations["kcp.provisioner.kyma-project.io/licence-type"]
labels, err := getAllRuntimeLabels(ctx, shoot, cfg.Client)
if err != nil {
Expand Down Expand Up @@ -210,16 +209,13 @@ func createRuntime(ctx context.Context, shoot v1beta1.Shoot, cfg migrator.Config
Workers: shoot.Spec.Provider.Workers,
},
Networking: v1.Networking{
Type: shoot.Spec.Networking.Type,
Pods: *shoot.Spec.Networking.Pods,
Nodes: *shoot.Spec.Networking.Nodes,
Services: *shoot.Spec.Networking.Services,
},
ControlPlane: v1beta1.ControlPlane{
HighAvailability: &v1beta1.HighAvailability{
FailureTolerance: v1beta1.FailureTolerance{
Type: hAFailureToleranceType,
},
},
HighAvailability: getHighAvailability(shoot),
},
},
Security: v1.Security{
Expand Down Expand Up @@ -280,13 +276,18 @@ func getShootList(ctx context.Context, cfg migrator.Config, gardenerNamespace st
return list
}

func getFailureToleranceType(shoot v1beta1.Shoot) v1beta1.FailureToleranceType {
func getHighAvailability(shoot v1beta1.Shoot) *v1beta1.HighAvailability {
if shoot.Spec.ControlPlane != nil {
if shoot.Spec.ControlPlane.HighAvailability != nil {
return shoot.Spec.ControlPlane.HighAvailability.FailureTolerance.Type
return &v1beta1.HighAvailability{
FailureTolerance: v1beta1.FailureTolerance{
Type: shoot.Spec.ControlPlane.HighAvailability.FailureTolerance.Type,
},
}
}
}
return ""

return nil
}

func getAdministratorsList(ctx context.Context, provider kubeconfig.Provider, shootName string) []string {
Expand Down Expand Up @@ -395,8 +396,14 @@ func getAllRuntimeLabels(ctx context.Context, shoot v1beta1.Shoot, getClient mig
return map[string]string{}, errors.Wrap(clientErr, fmt.Sprintf("Failed to get GardenerClient for shoot %s - %s\n", shoot.Name, clientErr))
}
gardenerCluster := v1.GardenerCluster{}
shootKey := types.NamespacedName{Name: shoot.Name, Namespace: "kcp-system"}
getGardenerCRerr := k8sClient.Get(ctx, shootKey, &gardenerCluster)

kymaID, found := shoot.Annotations["kcp.provisioner.kyma-project.io/runtime-id"]
if !found {
return nil, errors.New("Runtime ID not found in shoot annotations")
}

gardenerCRKey := types.NamespacedName{Name: kymaID, Namespace: "kcp-system"}
getGardenerCRerr := k8sClient.Get(ctx, gardenerCRKey, &gardenerCluster)
if getGardenerCRerr != nil {
var errMsg = fmt.Sprintf("Failed to retrieve GardenerCluster CR for shoot %s\n", shoot.Name)
return map[string]string{}, errors.Wrap(getGardenerCRerr, errMsg)
Expand All @@ -410,7 +417,8 @@ func getAllRuntimeLabels(ctx context.Context, shoot v1beta1.Shoot, getClient mig
enrichedRuntimeLabels["kyma-project.io/region"] = gardenerCluster.Labels["kyma-project.io/region"]
enrichedRuntimeLabels["kyma-project.io/shoot-name"] = gardenerCluster.Labels["kyma-project.io/shoot-name"]
enrichedRuntimeLabels["operator.kyma-project.io/kyma-name"] = gardenerCluster.Labels["operator.kyma-project.io/kyma-name"]

// The runtime CR should not be controlled by the KIM
enrichedRuntimeLabels["kyma-project.io/controlled-by-provisioner"] = "false"
// add custom label for the migrator
enrichedRuntimeLabels[migratorLabel] = "true"

Expand Down

0 comments on commit de6eb8c

Please sign in to comment.