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 <hchiramm@redhat.com>
This commit is contained in:
Humble Chirammal 2019-04-05 13:37:19 +05:30
parent e9ca60bf0d
commit 6eae6bbac5

View File

@ -865,7 +865,7 @@ func (p *glusterfsVolumeProvisioner) CreateVolume(gid int) (r *v1.GlusterfsPersi
epServiceName = p.provisionerConfig.customEpNamePrefix + "-" + string(p.options.PVC.UID) epServiceName = p.provisionerConfig.customEpNamePrefix + "-" + string(p.options.PVC.UID)
} }
epNamespace := p.options.PVC.Namespace 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 { if err != nil {
klog.Errorf("failed to create endpoint/service %v/%v: %v", epNamespace, epServiceName, err) klog.Errorf("failed to create endpoint/service %v/%v: %v", epNamespace, epServiceName, err)
deleteErr := cli.VolumeDelete(volume.Id) 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 // exist for the given namespace, PVC name, endpoint name, and
// set of IPs. I.e. the endpoint or service is only created // set of IPs. I.e. the endpoint or service is only created
// if it does not exist yet. // 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)) addrlist := make([]v1.EndpointAddress, len(hostips))
for i, v := range hostips { for i, v := range hostips {
@ -898,7 +904,7 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
Namespace: namespace, Namespace: namespace,
Name: epServiceName, Name: epServiceName,
Labels: map[string]string{ Labels: map[string]string{
"gluster.kubernetes.io/provisioned-for-pvc": pvcname, "gluster.kubernetes.io/provisioned-for-pvc": pvcNameOrID,
}, },
}, },
Subsets: []v1.EndpointSubset{{ Subsets: []v1.EndpointSubset{{
@ -924,7 +930,7 @@ func (p *glusterfsVolumeProvisioner) createEndpointService(namespace string, epS
Name: epServiceName, Name: epServiceName,
Namespace: namespace, Namespace: namespace,
Labels: map[string]string{ Labels: map[string]string{
"gluster.kubernetes.io/provisioned-for-pvc": pvcname, "gluster.kubernetes.io/provisioned-for-pvc": pvcNameOrID,
}, },
}, },
Spec: v1.ServiceSpec{ Spec: v1.ServiceSpec{