From de6eb8cbb6902ce37fa5b1a387ff49eed7a83dec Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Tue, 6 Aug 2024 17:08:50 +0200 Subject: [PATCH] Fixes to make migrator up to date --- hack/runtime-migrator/main.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/hack/runtime-migrator/main.go b/hack/runtime-migrator/main.go index 97791825..3aee2f6e 100644 --- a/hack/runtime-migrator/main.go +++ b/hack/runtime-migrator/main.go @@ -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 { @@ -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{ @@ -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 { @@ -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) @@ -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"