in pkg/csi_driver/controller.go [316:352]
func (s *controllerServer) prepareNewInstance(name string, capBytes int64, params map[string]string, top *csi.TopologyRequirement) (*lustre.ServiceInstance, error) {
location, err := s.pickZone(top)
if err != nil {
return nil, fmt.Errorf("invalid topology: %w", err)
}
networkFullNamePattern := regexp.MustCompile(`projects/([^/]+)/global/networks/([^/]+)`)
networkNamePattern := regexp.MustCompile(`^[a-z]([-a-z0-9]*[a-z0-9])?$`)
networkFullName := fmt.Sprintf("projects/%s/global/networks/%s", s.cloudProvider.Project, defaultNetwork)
if v, exists := params[paramNetwork]; exists {
if networkNamePattern.MatchString(v) {
networkFullName = fmt.Sprintf("projects/%s/global/networks/%s", s.cloudProvider.Project, v)
}
if networkFullNamePattern.MatchString(v) {
networkFullName = v
}
}
instance := &lustre.ServiceInstance{
Name: name,
Project: s.cloudProvider.Project,
Location: location,
CapacityGib: capBytes / util.Gib, // TODO(tyuchn): investigate rounding mechanisms to enhance the UX when specifying capacities in TiB or GiB.
Network: networkFullName,
GkeSupportEnabled: s.driver.config.EnableLegacyLustrePort,
}
if v, exists := params[paramDescription]; exists {
if len(v) > 2048 {
klog.Warningf("Instance %v description exceeds 2048 characters, truncating", name)
v = v[:2048]
}
instance.Description = v
}
if v, exists := params[paramFilesystem]; exists {
instance.Filesystem = v
}
return instance, nil
}