From 6eae6bbac51e5e010314aa7c094732eb50e60d1a Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Fri, 5 Apr 2019 13:37:19 +0530 Subject: [PATCH] Use pvc uid in endpoint/service label If the pvc name is more than 63 chars, the endpoint creation will fail due to the validation of objectmeta length of fields ie 63 chars at max. This patch introduce an enhancement where if the pvc name is >=63 the pvc uid is recorded at label instead of name. To preserve backward compatibility, the pvcname has been kept in endpoint metadata label if length of pvc name is <63chars. Signed-off-by: Humble Chirammal --- pkg/volume/glusterfs/glusterfs.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index d357d0aec92..6b0b5ab3421 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -865,7 +865,7 @@ func (p *glusterfsVolumeProvisioner) CreateVolume(gid int) (r *v1.GlusterfsPersi epServiceName = p.provisionerConfig.customEpNamePrefix + "-" + string(p.options.PVC.UID) } epNamespace := p.options.PVC.Namespace - endpoint, service, err := p.createEndpointService(epNamespace, epServiceName, dynamicHostIps, p.options.PVC.Name) + endpoint, service, err := p.createEndpointService(epNamespace, epServiceName, dynamicHostIps, p.options.PVC) if err != nil { klog.Errorf("failed to create endpoint/service %v/%v: %v", epNamespace, epServiceName, err) deleteErr := cli.VolumeDelete(volume.Id) @@ -887,7 +887,13 @@ func (p *glusterfsVolumeProvisioner) CreateVolume(gid int) (r *v1.GlusterfsPersi // exist for the given namespace, PVC name, endpoint name, and // set of IPs. I.e. the endpoint or service is only created // if it does not exist yet. -func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epServiceName string, hostips []string, pvcname string) (endpoint *v1.Endpoints, service *v1.Service, err error) { +func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epServiceName string, hostips []string, pvc *v1.PersistentVolumeClaim) (endpoint *v1.Endpoints, service *v1.Service, err error) { + pvcNameOrID := "" + if len(pvc.Name) >= 63 { + pvcNameOrID = string(pvc.UID) + } else { + pvcNameOrID = pvc.Name + } addrlist := make([]v1.EndpointAddress, len(hostips)) for i, v := range hostips { @@ -898,7 +904,7 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS Namespace: namespace, Name: epServiceName, Labels: map[string]string{ - "gluster.kubernetes.io/provisioned-for-pvc": pvcname, + "gluster.kubernetes.io/provisioned-for-pvc": pvcNameOrID, }, }, Subsets: []v1.EndpointSubset{{ @@ -924,7 +930,7 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS Name: epServiceName, Namespace: namespace, Labels: map[string]string{ - "gluster.kubernetes.io/provisioned-for-pvc": pvcname, + "gluster.kubernetes.io/provisioned-for-pvc": pvcNameOrID, }, }, Spec: v1.ServiceSpec{