Skip to content

Commit

Permalink
(feat): Move layer success warnings into method
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg committed Nov 28, 2023
1 parent 99a0c4e commit 6c17911
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
6 changes: 4 additions & 2 deletions internal/layer/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"fmt"
"log"
"os"

"github.com/reecetech/ebs-bootstrap/internal/action"
Expand Down Expand Up @@ -65,10 +64,13 @@ func (fdl *CreateDirectoryLayer) Validate(c *config.Config) error {
return fmt.Errorf("🔴 %s: Failed directory validation checks. %s does not exist or is not a directory", name, cd.MountPoint)
}
}
log.Println("🟢 Passed directory validation checks")
return nil
}

func (fdl *CreateDirectoryLayer) Warning() string {
return DisableWarning
}

func (fdl *CreateDirectoryLayer) Success() string {
return "Passed directory validation checks"
}
6 changes: 4 additions & 2 deletions internal/layer/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"fmt"
"log"

"github.com/reecetech/ebs-bootstrap/internal/action"
"github.com/reecetech/ebs-bootstrap/internal/backend"
Expand Down Expand Up @@ -59,10 +58,13 @@ func (fdl *FormatDeviceLayer) Validate(c *config.Config) error {
return fmt.Errorf("🔴 %s: Failed file system validation checks. Expected=%s, Actual=%s", name, cd.Fs, d.FileSystem)
}
}
log.Println("🟢 Passed file system validation checks")
return nil
}

func (fdl *FormatDeviceLayer) Warning() string {
return "Formatting larger disks can take several seconds ⌛"
}

func (fdl *FormatDeviceLayer) Success() string {
return "Passed file system validation checks"
}
6 changes: 4 additions & 2 deletions internal/layer/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"fmt"
"log"

"github.com/reecetech/ebs-bootstrap/internal/action"
"github.com/reecetech/ebs-bootstrap/internal/backend"
Expand Down Expand Up @@ -62,10 +61,13 @@ func (fdl *LabelDeviceLayer) Validate(c *config.Config) error {
return fmt.Errorf("🔴 %s: Failed label validation checks. Expected=%s, Actual=%s", name, cd.Label, d.Label)
}
}
log.Println("🟢 Passed label validation checks")
return nil
}

func (fdl *LabelDeviceLayer) Warning() string {
return "Certain file systems require that devices be unmounted prior to labeling"
}

func (fdl *LabelDeviceLayer) Success() string {
return "Passed label validation checks"
}
4 changes: 4 additions & 0 deletions internal/layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Layer interface {
Modify(c *config.Config) ([]action.Action, error)
Validate(config *config.Config) error
Warning() string
Success() string
}

type LayerExecutor interface {
Expand All @@ -47,6 +48,7 @@ func NewExponentialBackoffLayerExecutor(layers []Layer, ae *action.ActionExecuto
// Calculate the maximum elapsed time for the backoff strategy based on the provided MaxRetries and InitialInterval.
// This formula calculates the maximum elapsed time as a geometric series sum for a given number of retries and interval.
bo.MaxElapsedTime = time.Duration((math.Pow(Multiplier, MaxRetries)-1)/(Multiplier-1)) * InitialInterval
bo.MaxInterval = InitialInterval * time.Duration(math.Pow(Multiplier, MaxRetries-1))
return &ExponentialBackoffLayerExecutor{
backoff: bo,
actionExecutor: ae,
Expand All @@ -73,13 +75,15 @@ func (le *ExponentialBackoffLayerExecutor) Execute(config *config.Config) error
if err != nil {
return err
}
// Reset exponential backoff timer
le.backoff.Reset()
err = backoff.Retry(func() error {
return le.validate(layer, config)
}, le.backoff)
if err != nil {
return err
}
log.Printf("🟢 %s", layer.Success())
}
return nil
}
Expand Down
8 changes: 5 additions & 3 deletions internal/layer/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"fmt"
"log"

"github.com/reecetech/ebs-bootstrap/internal/action"
"github.com/reecetech/ebs-bootstrap/internal/backend"
Expand Down Expand Up @@ -84,10 +83,13 @@ func (fdl *MountDeviceLayer) Validate(c *config.Config) error {
return fmt.Errorf("🔴 %s: Failed mountpoint validation checks. Device not mounted to %s", name, bd.MountPoint)
}
}
log.Printf("🟢 Passed mountpoint validation checks")
return nil
}

func (fdl *MountDeviceLayer) Warning() string {
return "Devices mounted to a location not specified in the configuration will be unmounted"
return "Devices mounted to a location, not specified in the configuration, will be unmounted"
}

func (fdl *MountDeviceLayer) Success() string {
return "Passed mountpoint validation checks"
}
6 changes: 4 additions & 2 deletions internal/layer/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"fmt"
"log"

"github.com/reecetech/ebs-bootstrap/internal/action"
"github.com/reecetech/ebs-bootstrap/internal/backend"
Expand Down Expand Up @@ -116,10 +115,13 @@ func (fdl *ChangeOwnerLayer) Validate(c *config.Config) error {
return fmt.Errorf("🔴 %s: Failed ownership validation checks. %s Group Expected=%d, Actual=%d", name, cd.MountPoint, d.Gid, gid)
}
}
log.Printf("🟢 Passed ownership validation checks")
return nil
}

func (fdl *ChangeOwnerLayer) Warning() string {
return DisableWarning
}

func (fdl *ChangeOwnerLayer) Success() string {
return "Passed ownership validation checks"
}
6 changes: 4 additions & 2 deletions internal/layer/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"fmt"
"log"

"github.com/reecetech/ebs-bootstrap/internal/action"
"github.com/reecetech/ebs-bootstrap/internal/backend"
Expand Down Expand Up @@ -67,10 +66,13 @@ func (fdl *ChangePermissionsLayer) Validate(c *config.Config) error {
return fmt.Errorf("🔴 %s: Failed permissions validation checks. %s Permissions Expected=%s, Actual=%s", name, cd.MountPoint, cd.Permissions, d.Permissions)
}
}
log.Printf("🟢 Passed permissions validation checks")
return nil
}

func (fdl *ChangePermissionsLayer) Warning() string {
return DisableWarning
}

func (fdl *ChangePermissionsLayer) Success() string {
return "Passed permissions validation checks"
}
6 changes: 4 additions & 2 deletions internal/layer/resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"fmt"
"log"

"github.com/reecetech/ebs-bootstrap/internal/action"
"github.com/reecetech/ebs-bootstrap/internal/backend"
Expand Down Expand Up @@ -61,10 +60,13 @@ func (fdl *ResizeDeviceLayer) Validate(c *config.Config) error {
return fmt.Errorf("🔴 %s: Failed to resize file system. File System=%d Block Device=%d (bytes)", name, metrics.FileSystemSize, metrics.BlockDeviceSize)
}
}
log.Println("🟢 Passed file system resize checks")
return nil
}

func (fdl *ResizeDeviceLayer) Warning() string {
return DisableWarning
}

func (fdl *ResizeDeviceLayer) Success() string {
return "Passed file system resize checks"
}

0 comments on commit 6c17911

Please sign in to comment.