@@ -19,7 +19,6 @@ package v1
1919import (
2020 "fmt"
2121 "strings"
22- "sync"
2322
2423 "github.com/openebs/api/pkg/apis/types"
2524 "github.com/openebs/api/pkg/util"
@@ -40,11 +39,7 @@ const (
4039 CStorVolumeReplicaFinalizer = "cstorvolumereplica.openebs.io/finalizer"
4140)
4241
43- var (
44- // ConfFileMutex is to hold the lock while updating istgt.conf file
45- ConfFileMutex = & sync.Mutex {}
46- )
47-
42+ // NewCStorVolumeConfig returns new instance of CStorVolumeConfig
4843func NewCStorVolumeConfig () * CStorVolumeConfig {
4944 return & CStorVolumeConfig {}
5045}
@@ -83,7 +78,7 @@ func (cvc *CStorVolumeConfig) WithAnnotations(annotations map[string]string) *CS
8378 return cvc
8479}
8580
86- // WithLacvelsNew sets the Lacvels field of CVC with provided arguments
81+ // WithLabelsNew sets the Lacvels field of CVC with provided arguments
8782func (cvc * CStorVolumeConfig ) WithLabelsNew (labels map [string ]string ) * CStorVolumeConfig {
8883 cvc .Labels = make (map [string ]string )
8984 for key , value := range labels {
@@ -92,7 +87,7 @@ func (cvc *CStorVolumeConfig) WithLabelsNew(labels map[string]string) *CStorVolu
9287 return cvc
9388}
9489
95- // WithLacvels appends or overwrites existing Lacvels
90+ // WithLabels appends or overwrites existing Lacvels
9691// values of CVC with provided arguments
9792func (cvc * CStorVolumeConfig ) WithLabels (labels map [string ]string ) * CStorVolumeConfig {
9893 if cvc .Labels == nil {
@@ -165,6 +160,7 @@ func IsScaleDownInProgress(cv *CStorVolume) bool {
165160//
166161// **************************************************************************
167162
163+ // NewCStorVolume returns new instance of CStorVolume
168164func NewCStorVolume () * CStorVolume {
169165 return & CStorVolume {}
170166}
@@ -208,7 +204,7 @@ func (cv *CStorVolume) WithAnnotations(annotations map[string]string) *CStorVolu
208204 return cv
209205}
210206
211- // WithLacvelsNew sets the Lacvels field of CV with provided arguments
207+ // WithLabelsNew sets the Lacvels field of CV with provided arguments
212208func (cv * CStorVolume ) WithLabelsNew (labels map [string ]string ) * CStorVolume {
213209 cv .Labels = make (map [string ]string )
214210 for key , value := range labels {
@@ -217,7 +213,7 @@ func (cv *CStorVolume) WithLabelsNew(labels map[string]string) *CStorVolume {
217213 return cv
218214}
219215
220- // WithLacvels appends or overwrites existing Lacvels
216+ // WithLabels appends or overwrites existing Lacvels
221217// values of CVC with provided arguments
222218func (cv * CStorVolume ) WithLabels (labels map [string ]string ) * CStorVolume {
223219 if cv .Labels == nil {
@@ -229,7 +225,7 @@ func (cv *CStorVolume) WithLabels(labels map[string]string) *CStorVolume {
229225 return cv
230226}
231227
232- // WithFinalizer sets the finalizer field in the CV
228+ // WithFinalizers sets the finalizer field in the CV
233229func (cv * CStorVolume ) WithFinalizers (finalizers ... string ) * CStorVolume {
234230 cv .Finalizers = append (cv .Finalizers , finalizers ... )
235231 return cv
@@ -324,9 +320,9 @@ func (cv *CStorVolume) RemoveFinalizer(finalizer string) {
324320}
325321
326322// IsResizePending return true if resize is in progress
327- func (c * CStorVolume ) IsResizePending () bool {
328- curCapacity := c .Status .Capacity
329- desiredCapacity := c .Spec .Capacity
323+ func (cv * CStorVolume ) IsResizePending () bool {
324+ curCapacity := cv .Status .Capacity
325+ desiredCapacity := cv .Spec .Capacity
330326 // Cmp returns 0 if the curCapacity is equal to desiredCapacity,
331327 // -1 if the curCapacity is less than desiredCapacity, or 1 if the
332328 // curCapacity is greater than desiredCapacity.
@@ -337,34 +333,34 @@ func (c *CStorVolume) IsResizePending() bool {
337333// Steps to verify whether drf is required
338334// 1. Read DesiredReplicationFactor configurations from istgt conf file
339335// 2. Compare the value with spec.DesiredReplicationFactor and return result
340- func (c * CStorVolume ) IsDRFPending () bool {
336+ func (cv * CStorVolume ) IsDRFPending () bool {
341337 fileOperator := util.RealFileOperator {}
342- ConfFileMutex .Lock ()
338+ types . ConfFileMutex .Lock ()
343339 //If it has proper config then we will get --> " DesiredReplicationFactor 3"
344340 i , gotConfig , err := fileOperator .GetLineDetails (types .IstgtConfPath , types .DesiredReplicationFactorKey )
345- ConfFileMutex .Unlock ()
341+ types . ConfFileMutex .Unlock ()
346342 if err != nil || i == - 1 {
347343 klog .Infof ("failed to get %s config details error: %v" ,
348344 types .DesiredReplicationFactorKey ,
349345 err ,
350346 )
351347 return false
352348 }
353- drfStringValue := fmt .Sprintf (" %d" , c .Spec .DesiredReplicationFactor )
349+ drfStringValue := fmt .Sprintf (" %d" , cv .Spec .DesiredReplicationFactor )
354350 // gotConfig will have " DesiredReplicationFactor 3" and we will extract
355351 // numeric character from output
356352 if ! strings .HasSuffix (gotConfig , drfStringValue ) {
357353 return true
358354 }
359355 // reconciliation check for replica scaledown scenarion
360- return (len (c .Spec .ReplicaDetails .KnownReplicas ) <
361- len (c .Status .ReplicaDetails .KnownReplicas ))
356+ return (len (cv .Spec .ReplicaDetails .KnownReplicas ) <
357+ len (cv .Status .ReplicaDetails .KnownReplicas ))
362358}
363359
364360// GetCVCondition returns corresponding cstorvolume condition based argument passed
365- func (c * CStorVolume ) GetCVCondition (
361+ func (cv * CStorVolume ) GetCVCondition (
366362 condType CStorVolumeConditionType ) CStorVolumeCondition {
367- for _ , cond := range c .Status .Conditions {
363+ for _ , cond := range cv .Status .Conditions {
368364 if condType == cond .Type {
369365 return cond
370366 }
@@ -373,8 +369,8 @@ func (c *CStorVolume) GetCVCondition(
373369}
374370
375371// IsConditionPresent returns true if condition is available
376- func (c * CStorVolume ) IsConditionPresent (condType CStorVolumeConditionType ) bool {
377- for _ , cond := range c .Status .Conditions {
372+ func (cv * CStorVolume ) IsConditionPresent (condType CStorVolumeConditionType ) bool {
373+ for _ , cond := range cv .Status .Conditions {
378374 if condType == cond .Type {
379375 return true
380376 }
@@ -384,10 +380,10 @@ func (c *CStorVolume) IsConditionPresent(condType CStorVolumeConditionType) bool
384380
385381// AreSpecReplicasHealthy return true if all the spec replicas are in Healthy
386382// state else return false
387- func (c * CStorVolume ) AreSpecReplicasHealthy (volStatus * CVStatus ) bool {
383+ func (cv * CStorVolume ) AreSpecReplicasHealthy (volStatus * CVStatus ) bool {
388384 var isReplicaExist bool
389385 var replicaInfo ReplicaStatus
390- for _ , replicaValue := range c .Spec .ReplicaDetails .KnownReplicas {
386+ for _ , replicaValue := range cv .Spec .ReplicaDetails .KnownReplicas {
391387 isReplicaExist = false
392388 for _ , replicaInfo = range volStatus .ReplicaStatuses {
393389 if replicaInfo .ID == replicaValue {
@@ -403,22 +399,22 @@ func (c *CStorVolume) AreSpecReplicasHealthy(volStatus *CVStatus) bool {
403399}
404400
405401// GetRemovingReplicaID return replicaID that present in status but not in spec
406- func (c * CStorVolume ) GetRemovingReplicaID () string {
407- for repID := range c .Status .ReplicaDetails .KnownReplicas {
402+ func (cv * CStorVolume ) GetRemovingReplicaID () string {
403+ for repID := range cv .Status .ReplicaDetails .KnownReplicas {
408404 // If known replica is not exist in spec but if it exist in status then
409405 // user/operator selected that replica for removal
410406 if _ , isReplicaExist :=
411- c .Spec .ReplicaDetails .KnownReplicas [repID ]; ! isReplicaExist {
407+ cv .Spec .ReplicaDetails .KnownReplicas [repID ]; ! isReplicaExist {
412408 return string (repID )
413409 }
414410 }
415411 return ""
416412}
417413
418414// BuildScaleDownConfigData build data based on replica that needs to remove
419- func (c * CStorVolume ) BuildScaleDownConfigData (repID string ) map [string ]string {
415+ func (cv * CStorVolume ) BuildScaleDownConfigData (repID string ) map [string ]string {
420416 configData := map [string ]string {}
421- newReplicationFactor := c .Spec .DesiredReplicationFactor
417+ newReplicationFactor := cv .Spec .DesiredReplicationFactor
422418 newConsistencyFactor := (newReplicationFactor / 2 ) + 1
423419 key := fmt .Sprintf (" ReplicationFactor" )
424420 value := fmt .Sprintf (" ReplicationFactor %d" , newReplicationFactor )
@@ -428,7 +424,7 @@ func (c *CStorVolume) BuildScaleDownConfigData(repID string) map[string]string {
428424 configData [key ] = value
429425 key = fmt .Sprintf (" DesiredReplicationFactor" )
430426 value = fmt .Sprintf (" DesiredReplicationFactor %d" ,
431- c .Spec .DesiredReplicationFactor )
427+ cv .Spec .DesiredReplicationFactor )
432428 configData [key ] = value
433429 key = fmt .Sprintf (" Replica %s" , repID )
434430 value = fmt .Sprintf ("" )
@@ -486,6 +482,7 @@ func GetResizeCondition() CStorVolumeCondition {
486482//
487483//
488484// ****************************************************************************
485+
489486// SetErrorStatus sets the message and reason for the error
490487func (vs * VersionStatus ) SetErrorStatus (msg string , err error ) {
491488 vs .Message = msg
@@ -516,6 +513,7 @@ func (vd *VersionDetails) SetSuccessStatus() {
516513//
517514// **************************************************************************
518515
516+ // NewCStorVolumeReplica returns new instance of CStorVolumeReplica
519517func NewCStorVolumeReplica () * CStorVolumeReplica {
520518 return & CStorVolumeReplica {}
521519}
@@ -554,7 +552,7 @@ func (cvr *CStorVolumeReplica) WithAnnotations(annotations map[string]string) *C
554552 return cvr
555553}
556554
557- // WithLacvrelsNew sets the Lacvrels field of CV with provided arguments
555+ // WithLabelsNew sets the Lacvrels field of CV with provided arguments
558556func (cvr * CStorVolumeReplica ) WithLabelsNew (labels map [string ]string ) * CStorVolumeReplica {
559557 cvr .Labels = make (map [string ]string )
560558 for key , value := range labels {
@@ -563,7 +561,7 @@ func (cvr *CStorVolumeReplica) WithLabelsNew(labels map[string]string) *CStorVol
563561 return cvr
564562}
565563
566- // WithLacvrels appends or overwrites existing Lacvrels
564+ // WithLabels appends or overwrites existing Lacvrels
567565// values of CVC with provided arguments
568566func (cvr * CStorVolumeReplica ) WithLabels (labels map [string ]string ) * CStorVolumeReplica {
569567 if cvr .Labels == nil {
@@ -575,7 +573,7 @@ func (cvr *CStorVolumeReplica) WithLabels(labels map[string]string) *CStorVolume
575573 return cvr
576574}
577575
578- // WithFinalizer sets the finalizer field in the CV
576+ // WithFinalizers sets the finalizer field in the CV
579577func (cvr * CStorVolumeReplica ) WithFinalizers (finalizers ... string ) * CStorVolumeReplica {
580578 cvr .Finalizers = append (cvr .Finalizers , finalizers ... )
581579 return cvr
0 commit comments