Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Fix volume name prefix (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harvey Lowndes authored and owainlewis committed Sep 24, 2018
1 parent c9f124c commit 3539b19
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
7 changes: 1 addition & 6 deletions pkg/provisioner/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
const (
ociVolumeID = "ociVolumeID"
ociVolumeBackupID = "volume.beta.kubernetes.io/oci-volume-source"
volumePrefixEnvVarName = "OCI_VOLUME_NAME_PREFIX"
fsType = "fsType"
volumeRoundingUpEnabled = "volumeRoundingUpEnabled"
)
Expand Down Expand Up @@ -166,7 +165,7 @@ func (block *blockProvisioner) Provision(options controller.VolumeOptions, ad *i
volumeDetails := core.CreateVolumeDetails{
AvailabilityDomain: ad.Name,
CompartmentId: common.String(block.client.CompartmentOCID()),
DisplayName: common.String(fmt.Sprintf("%s%s", os.Getenv(volumePrefixEnvVarName), options.PVC.Name)),
DisplayName: common.String(fmt.Sprintf("%s%s", provisioner.GetPrefix(), options.PVC.Name)),
SizeInMBs: common.Int(volSizeMB),
}

Expand All @@ -177,10 +176,6 @@ func (block *blockProvisioner) Provision(options controller.VolumeOptions, ad *i

ctx, cancel := context.WithTimeout(ctx, block.client.Timeout())
defer cancel()
prefix := strings.TrimSpace(os.Getenv(volumePrefixEnvVarName))
if prefix != "" && !strings.HasSuffix(prefix, "-") {
prefix = fmt.Sprintf("%s%s", prefix, "-")
}

newVolume, err := block.client.BlockStorage().CreateVolume(ctx, core.CreateVolumeRequest{
CreateVolumeDetails: volumeDetails,
Expand Down
16 changes: 7 additions & 9 deletions pkg/provisioner/fss/fss.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"math/rand"
"os"

"github.com/golang/glog"
"github.com/kubernetes-incubator/external-storage/lib/controller"
Expand All @@ -38,12 +37,11 @@ import (
)

const (
ociVolumeID = "volume.beta.kubernetes.io/oci-volume-id"
ociExportID = "volume.beta.kubernetes.io/oci-export-id"
volumePrefixEnvVarName = "OCI_VOLUME_NAME_PREFIX"
fsType = "fsType"
subnetID = "subnetId"
mntTargetID = "mntTargetId"
ociVolumeID = "volume.beta.kubernetes.io/oci-volume-id"
ociExportID = "volume.beta.kubernetes.io/oci-export-id"
fsType = "fsType"
subnetID = "subnetId"
mntTargetID = "mntTargetId"
)

// filesystemProvisioner is the internal provisioner for OCI filesystem volumes
Expand Down Expand Up @@ -127,7 +125,7 @@ func (fsp *filesystemProvisioner) getOrCreateMountTarget(ctx context.Context, mt
AvailabilityDomain: &ad,
SubnetId: &subnetID,
CompartmentId: common.String(fsp.client.CompartmentOCID()),
DisplayName: common.String(fmt.Sprintf("%s%s", os.Getenv(volumePrefixEnvVarName), "mnt")),
DisplayName: common.String(fmt.Sprintf("%s%s", provisioner.GetPrefix(), "mnt")),
},
})
if err != nil {
Expand All @@ -147,7 +145,7 @@ func (fsp *filesystemProvisioner) Provision(options controller.VolumeOptions, ad
CreateFileSystemDetails: filestorage.CreateFileSystemDetails{
AvailabilityDomain: ad.Name,
CompartmentId: common.String(fsp.client.CompartmentOCID()),
DisplayName: common.String(fmt.Sprintf("%s%s", os.Getenv(volumePrefixEnvVarName), options.PVC.Name)),
DisplayName: common.String(fmt.Sprintf("%s%s", provisioner.GetPrefix(), options.PVC.Name)),
},
})
if err != nil {
Expand Down
31 changes: 31 additions & 0 deletions pkg/provisioner/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package provisioner

import (
"fmt"
"os"
"strings"
)

// GetPrefix returns a prefix suffixed by a hyphen based on the value of the
// envrionment variable OCI_VOLUME_NAME_PREFIX.
func GetPrefix() string {
prefix := strings.TrimSpace(os.Getenv("OCI_VOLUME_NAME_PREFIX"))
if prefix != "" && !strings.HasSuffix(prefix, "-") {
prefix = fmt.Sprintf("%s%s", prefix, "-")
}
return prefix
}

0 comments on commit 3539b19

Please sign in to comment.