@@ -32,6 +32,8 @@ import (
32
32
"github.com/oracle/oci-go-sdk/identity"
33
33
"github.com/oracle/oci-volume-provisioner/pkg/oci/client"
34
34
"github.com/oracle/oci-volume-provisioner/pkg/provisioner/plugin"
35
+
36
+ "github.com/oracle/oci-volume-provisioner/pkg/oci/instancemeta"
35
37
)
36
38
37
39
const (
@@ -43,15 +45,17 @@ const (
43
45
44
46
// blockProvisioner is the internal provisioner for OCI block volumes
45
47
type blockProvisioner struct {
46
- client client.ProvisionerClient
48
+ client client.ProvisionerClient
49
+ metadata instancemeta.Interface
47
50
}
48
51
49
52
var _ plugin.ProvisionerPlugin = & blockProvisioner {}
50
53
51
54
// NewBlockProvisioner creates a new instance of the block storage provisioner
52
- func NewBlockProvisioner (client client.ProvisionerClient ) plugin.ProvisionerPlugin {
55
+ func NewBlockProvisioner (client client.ProvisionerClient , metadata instancemeta. Interface ) plugin.ProvisionerPlugin {
53
56
return & blockProvisioner {
54
- client : client ,
57
+ client : client ,
58
+ metadata : metadata ,
55
59
}
56
60
}
57
61
@@ -72,13 +76,10 @@ func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
72
76
}
73
77
74
78
// Provision creates an OCI block volume acording to the spec
75
- func (block * blockProvisioner ) Provision (options controller.VolumeOptions ,
76
- availabilityDomain * identity.AvailabilityDomain ) (* v1.PersistentVolume , error ) {
79
+ func (block * blockProvisioner ) Provision (options controller.VolumeOptions , ad * identity.AvailabilityDomain ) (* v1.PersistentVolume , error ) {
77
80
for _ , accessMode := range options .PVC .Spec .AccessModes {
78
81
if accessMode != v1 .ReadWriteOnce {
79
- return nil , fmt .Errorf ("invalid access mode %v specified. Only %v is supported" ,
80
- accessMode ,
81
- v1 .ReadWriteOnce )
82
+ return nil , fmt .Errorf ("invalid access mode %q specified (only %q is supported)" , accessMode , v1 .ReadWriteOnce )
82
83
}
83
84
}
84
85
@@ -88,10 +89,10 @@ func (block *blockProvisioner) Provision(options controller.VolumeOptions,
88
89
glog .Infof ("Volume size (bytes): %v" , volSizeBytes )
89
90
volSizeMB := int (roundUpSize (volSizeBytes , 1024 * 1024 ))
90
91
91
- glog .Infof ("Creating volume size=%v AD=%s compartmentOCID=%q" , volSizeMB , * availabilityDomain .Name , block .client .CompartmentOCID ())
92
+ glog .Infof ("Creating volume size=%v AD=%s compartmentOCID=%q" , volSizeMB , * ad .Name , block .client .CompartmentOCID ())
92
93
93
94
volumeDetails := core.CreateVolumeDetails {
94
- AvailabilityDomain : availabilityDomain .Name ,
95
+ AvailabilityDomain : ad .Name ,
95
96
CompartmentId : common .String (block .client .CompartmentOCID ()),
96
97
DisplayName : common .String (fmt .Sprintf ("%s%s" , os .Getenv (volumePrefixEnvVarName ), options .PVC .Name )),
97
98
SizeInMBs : common .Int (volSizeMB ),
@@ -119,13 +120,25 @@ func (block *blockProvisioner) Provision(options controller.VolumeOptions,
119
120
//volumeName := mapVolumeIDToName(*newVolume.Id)
120
121
filesystemType := resolveFSType (options )
121
122
123
+ region , ok := os .LookupEnv ("OCI_SHORT_REGION" )
124
+ if ! ok {
125
+ metadata , err := block .metadata .Get ()
126
+ if err != nil {
127
+ return nil , err
128
+ }
129
+ region = metadata .Region
130
+ }
131
+
122
132
pv := & v1.PersistentVolume {
123
133
ObjectMeta : metav1.ObjectMeta {
124
134
Name : * newVolume .Id ,
125
135
Annotations : map [string ]string {
126
136
ociVolumeID : * newVolume .Id ,
127
137
},
128
- Labels : map [string ]string {},
138
+ Labels : map [string ]string {
139
+ plugin .LabelZoneRegion : region ,
140
+ plugin .LabelZoneFailureDomain : * ad .Name ,
141
+ },
129
142
},
130
143
Spec : v1.PersistentVolumeSpec {
131
144
PersistentVolumeReclaimPolicy : options .PersistentVolumeReclaimPolicy ,
0 commit comments