Skip to content

Commit

Permalink
add resource name length limit
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <[email protected]>
  • Loading branch information
LiZhenCheng9527 committed Feb 21, 2024
1 parent 386cab0 commit 141b1fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
8 changes: 6 additions & 2 deletions pkg/cluster-operator/customcluster_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,15 @@ func generateClusterConfigKey(customCluster *v1alpha1.CustomCluster) client.Obje
}

func generateClusterHostsName(customCluster *v1alpha1.CustomCluster) string {
return customCluster.Name + "-" + ClusterHostsName
hostName := customCluster.Name + "-" + ClusterHostsName
hostName = names.SimpleNameGenerator.GenerateName(hostName)
return hostName
}

func generateClusterConfigName(customCluster *v1alpha1.CustomCluster) string {
return customCluster.Name + "-" + ClusterConfigName
configName := customCluster.Name + "-" + ClusterConfigName
configName = names.SimpleNameGenerator.GenerateName(configName)
return configName
}

func generateOwnerRefFromCustomCluster(customCluster *v1alpha1.CustomCluster) metav1.OwnerReference {
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster-operator/customcluster_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apiserver/pkg/storage/names"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
Expand Down Expand Up @@ -234,7 +235,9 @@ func generateScaleUpHostsKey(customCluster *v1alpha1.CustomCluster) client.Objec
}

func generateScaleUpHostsName(customCluster *v1alpha1.CustomCluster) string {
return customCluster.Name + "-" + ClusterHostsName + "-scale-up"
scaleUpHostName := customCluster.Name + "-" + ClusterHostsName + "-scale-up"
scaleUpHostName = names.SimpleNameGenerator.GenerateName(scaleUpHostName)
return scaleUpHostName
}

// generateScaleDownManageCMD generate a kubespray cmd to delete the node from the list of nodesNeedDelete.
Expand Down
3 changes: 3 additions & 0 deletions pkg/fleet-manager/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apiserver/pkg/storage/names"
ctrl "sigs.k8s.io/controller-runtime"

fleetapi "kurator.dev/kurator/pkg/apis/fleet/v1alpha1"
Expand All @@ -45,6 +46,7 @@ func (f *FleetManager) reconcileControlPlane(ctx context.Context, fleet *fleetap
}
// TODO: generate a valid name
podName := fleet.Name + "-init"
podName = names.SimpleNameGenerator.GenerateName(podName)
namespace := fleet.Namespace

clusterKey := types.NamespacedName{Name: podName, Namespace: namespace}
Expand Down Expand Up @@ -155,6 +157,7 @@ func (f *FleetManager) deleteControlPlane(ctx context.Context, fleet *fleetapi.F
return nil
}
podName := fleet.Name + "-delete"
podName = names.SimpleNameGenerator.GenerateName(podName)
namespace := fleet.Namespace

clusterKey := types.NamespacedName{Name: podName, Namespace: namespace}
Expand Down

0 comments on commit 141b1fd

Please sign in to comment.