From 6348727b5619735bd2230acde827e643c617a247 Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Mon, 19 Feb 2024 17:04:35 +0800 Subject: [PATCH] add length limits to API name Signed-off-by: LiZhenCheng9527 --- e2e/suite_test.go | 2 +- pkg/cluster-operator/customcluster_helper.go | 14 ++++++++++++-- pkg/cluster-operator/customcluster_scale.go | 7 ++++++- pkg/fleet-manager/application/helper.go | 2 +- pkg/fleet-manager/backup/shared.go | 8 +++++++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/e2e/suite_test.go b/e2e/suite_test.go index a1644087d..982d21f18 100644 --- a/e2e/suite_test.go +++ b/e2e/suite_test.go @@ -96,8 +96,8 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { gomega.Expect(secretCreateErr).ShouldNot(gomega.HaveOccurred()) attachedCreateErr := resources.CreateAttachedCluster(kuratorClient, attachedcluster) - gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred()) resources.WaitAttachedClusterFitWith(kuratorClient, namespace, memberClusterName, func(attachedCluster *clusterv1a1.AttachedCluster) bool { return attachedCluster.Status.Ready }) + gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred()) }) diff --git a/pkg/cluster-operator/customcluster_helper.go b/pkg/cluster-operator/customcluster_helper.go index a75587622..5912f8037 100644 --- a/pkg/cluster-operator/customcluster_helper.go +++ b/pkg/cluster-operator/customcluster_helper.go @@ -283,11 +283,21 @@ func generateClusterConfigKey(customCluster *v1alpha1.CustomCluster) client.Obje } func generateClusterHostsName(customCluster *v1alpha1.CustomCluster) string { - return customCluster.Name + "-" + ClusterHostsName + name := customCluster.Name + "-" + ClusterHostsName + name = strings.ToLower(name) + if len(name) > 63 { + name = name[:63] + } + return name } func generateClusterConfigName(customCluster *v1alpha1.CustomCluster) string { - return customCluster.Name + "-" + ClusterConfigName + name := customCluster.Name + "-" + ClusterConfigName + name = strings.ToLower(name) + if len(name) > 63 { + name = name[:63] + } + return name } func generateOwnerRefFromCustomCluster(customCluster *v1alpha1.CustomCluster) metav1.OwnerReference { diff --git a/pkg/cluster-operator/customcluster_scale.go b/pkg/cluster-operator/customcluster_scale.go index 99d49d2b3..2ae250d09 100644 --- a/pkg/cluster-operator/customcluster_scale.go +++ b/pkg/cluster-operator/customcluster_scale.go @@ -234,7 +234,12 @@ func generateScaleUpHostsKey(customCluster *v1alpha1.CustomCluster) client.Objec } func generateScaleUpHostsName(customCluster *v1alpha1.CustomCluster) string { - return customCluster.Name + "-" + ClusterHostsName + "-scale-up" + name := customCluster.Name + "-" + ClusterHostsName + "-scale-up" + name = strings.ToLower(name) + if len(name) > 63 { + name = name[:63] + } + return name } // generateScaleDownManageCMD generate a kubespray cmd to delete the node from the list of nodesNeedDelete. diff --git a/pkg/fleet-manager/application/helper.go b/pkg/fleet-manager/application/helper.go index a2d427b30..2bd26ba44 100644 --- a/pkg/fleet-manager/application/helper.go +++ b/pkg/fleet-manager/application/helper.go @@ -385,7 +385,7 @@ func getSyncPolicyKind(syncPolicy *applicationapi.ApplicationSyncPolicy) string } // generatePolicyResourceName creates a unique name for a policy resource (such as helmRelease or kustomization) -// based on the provided application, cluster kind, and cluster name. +// based on the provided application, cluster kind and cluster name. func generatePolicyResourceName(policyName, clusterKind, clusterName string) string { name := policyName + "-" + clusterKind + "-" + clusterName name = strings.ToLower(name) diff --git a/pkg/fleet-manager/backup/shared.go b/pkg/fleet-manager/backup/shared.go index 13d90f73a..f5d042dc6 100644 --- a/pkg/fleet-manager/backup/shared.go +++ b/pkg/fleet-manager/backup/shared.go @@ -19,6 +19,7 @@ import ( "fmt" "reflect" "sort" + "strings" "time" "github.com/robfig/cron/v3" @@ -241,7 +242,12 @@ func generateVeleroResourceObjectMeta(veleroResourceName string, labels map[stri // generateVeleroResourceName generate a name uniquely across object store func generateVeleroResourceName(clusterName, creatorKind, creatorNamespace, creatorName string) string { - return clusterName + "-" + creatorKind + "-" + creatorNamespace + "-" + creatorName + name := clusterName + "-" + creatorKind + "-" + creatorNamespace + "-" + creatorName + name = strings.ToLower(name) + if len(name) > 63 { + name = name[:63] + } + return name } // MostRecentCompletedBackup returns the most recent backup that's completed from a list of backups.