Skip to content

Commit

Permalink
preflight: larger disk space check for builder (chef#1967)
Browse files Browse the repository at this point in the history
- add new builder collection
- require an additional 15 GB if builder is deployed
- allow passing config to preflight check command

Signed-off-by: Steven Danna <[email protected]>
  • Loading branch information
stevendanna authored Oct 24, 2019
1 parent ca6aab3 commit caf2a67
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 37 deletions.
29 changes: 26 additions & 3 deletions components/automate-cli/cmd/chef-automate/pre_flight_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ func init() {
"airgap",
false,
"Pass this flag when the environment is airgapped")
preflightCheckCmd.PersistentFlags().StringVar(
&preflightCmdFlags.configPath,
"config",
"",
"Optional config file to use")
RootCmd.AddCommand(preflightCheckCmd)

preflightCheckCmd.AddCommand(newMigratePreflightCmd())
}

var preflightCmdFlags = struct {
airgap bool
airgap bool
configPath string
}{}

var preflightCheckCmd = &cobra.Command{
Expand All @@ -41,8 +47,20 @@ var preflightCheckCmd = &cobra.Command{
RunE: runPreflightCheckCmd,
}

func loadMergedConfigForPreflight() (*deployment.AutomateConfig, error) {
if preflightCmdFlags.configPath == "" {
return deployment.DefaultAutomateConfig(), nil
} else {
return deployment.LoadUserOverrideConfigFile(preflightCmdFlags.configPath)
}
}

func runPreflightCheckCmd(cmd *cobra.Command, args []string) error {
if err := client.Preflight(writer, deployment.DefaultAutomateConfig(), version.BuildTime, preflightCmdFlags.airgap); err != nil {
cfg, err := loadMergedConfigForPreflight()
if err != nil {
return err
}
if err := client.Preflight(writer, cfg, version.BuildTime, preflightCmdFlags.airgap); err != nil {
return err
}

Expand Down Expand Up @@ -173,7 +191,12 @@ func runMigratePreflight(cmd *cobra.Command, args []string) error {
return status.Wrap(err, status.PreflightError, "could not set SKIP_SHARED_PORTS environment variable")
}

if err := client.Preflight(writer, deployment.DefaultAutomateConfig(), version.BuildTime, migratePreflightCmdFlags.airgapPreflight); err != nil {
cfg, err := loadMergedConfigForPreflight()
if err != nil {
return err
}

if err := client.Preflight(writer, cfg, version.BuildTime, migratePreflightCmdFlags.airgapPreflight); err != nil {
return status.Annotate(err, status.PreflightError)
}

Expand Down
24 changes: 9 additions & 15 deletions components/automate-deployment/pkg/assets/assets.bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions components/automate-deployment/pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,32 +155,37 @@ func (d *Deployment) ReplaceUserOverrideConfig(config *dc.AutomateConfig) error
func ContainsAutomateCollection(c *dc.ConfigRequest) bool {
products := c.GetV1().GetSvc().GetProducts()
if len(products) > 0 {
return services.ContainsCollection("automate", products)
return services.ContainsCollection(services.AutomateCollectionName, products)
}
return true
}

func ExpectedServiceIDsForConfig(c *dc.ConfigRequest) ([]habpkg.HabPkg, error) {
func CollectionsForConfig(c *dc.ConfigRequest) []string {
var collections []string

if len(c.GetV1().GetSvc().GetProducts()) > 0 {
collections = c.GetV1().GetSvc().GetProducts()
c := c.GetV1().GetSvc().GetProducts()
collections = make([]string, len(c))
copy(collections, c)
} else {
collections = []string{"automate"}
collections = []string{services.AutomateCollectionName}

if c.GetV1().GetSvc().GetEnableChefServer().GetValue() {
collections = append(collections, "chef-server")
collections = append(collections, services.ChefServerCollectionName)
}

if c.GetV1().GetSvc().GetEnableWorkflow().GetValue() {
collections = append(collections, "workflow")
collections = append(collections, services.WorkflowCollectionName)
}

if c.GetV1().GetSvc().GetEnableDevMonitoring().GetValue() {
collections = append(collections, "monitoring")
collections = append(collections, services.MonitoringCollectionName)
}
}
return collections
}

func ExpectedServiceIDsForConfig(c *dc.ConfigRequest) ([]habpkg.HabPkg, error) {
collections := CollectionsForConfig(c)
serviceIDs, err := services.ServicesInCollections(collections)
if err != nil {
collectionsList := strings.Join(collections, ", ")
Expand Down
29 changes: 20 additions & 9 deletions components/automate-deployment/pkg/preflight/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"reflect"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"

dc "github.com/chef/automate/api/config/deployment"
"github.com/chef/automate/components/automate-deployment/pkg/deployment"
"github.com/chef/automate/components/automate-deployment/pkg/habpkg"
"github.com/chef/automate/components/automate-deployment/pkg/services"
"github.com/chef/automate/components/automate-grpc/protoc-gen-a2-config/api/a2conf"
"github.com/chef/automate/lib/proc"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func RootUserRequiredCheck() Check {
Expand All @@ -33,8 +34,22 @@ func RootUserRequiredCheck() Check {
}
}

func DefaultMinimumDiskCheck() Check {
return MinimumDiskCheck(5 * (1 << 30))
const GB = 1 << 30

func minDiskBytesForConfig(c *dc.AutomateConfig) uint64 {
collections := deployment.CollectionsForConfig(c.GetDeployment())
minSize := uint64(0)
if services.ContainsCollection(services.BuilderCollectionName, collections) {
minSize += 15 * GB
}
if services.ContainsCollection(services.AutomateCollectionName, collections) {
minSize += 5 * GB
}
return minSize
}

func DefaultMinimumDiskCheck(c *dc.AutomateConfig) Check {
return MinimumDiskCheck(minDiskBytesForConfig(c))
}

func MinimumDiskCheck(minimumBytes uint64) Check {
Expand Down Expand Up @@ -381,10 +396,6 @@ func skippablePort(port uint16) bool {
}

func requiredPortsForConfig(skipShared bool, config *dc.AutomateConfig) ([]int, error) {
if config == nil {
config = dc.DefaultAutomateConfig()
}

servicesToCheck, err := deployment.ExpectedServiceIDsForConfig(config.GetDeployment())
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion components/automate-deployment/pkg/preflight/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func NewDeployPreflightChecker(opts DeployPreflightCheckOptions) *DeployPrefligh
}

func (c *DeployPreflightChecker) Run(probe TestProbe) error {
if c.automateConfig == nil {
c.automateConfig = dc.DefaultAutomateConfig()
}

portCheck, err := DefaultPortCheck(c.skipSharedPorts, c.automateConfig)
if err != nil {
return errors.Wrap(err, "failed to configure preflight checks")
Expand All @@ -60,7 +64,7 @@ func (c *DeployPreflightChecker) Run(probe TestProbe) error {

checks := []Check{
RootUserRequiredCheck(),
DefaultMinimumDiskCheck(),
DefaultMinimumDiskCheck(c.automateConfig),
chefAutomateInBinCheck,
isA2DeployedCheck,
IsSystemdCheck(),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion components/automate-deployment/pkg/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"encoding/json"
"strings"

"github.com/chef/automate/lib/product"
"github.com/pkg/errors"

"github.com/chef/automate/components/automate-deployment/pkg/assets"
"github.com/chef/automate/components/automate-deployment/pkg/bind"
"github.com/chef/automate/components/automate-deployment/pkg/habpkg"
"github.com/chef/automate/components/automate-deployment/pkg/services/internal/generated"
"github.com/chef/automate/lib/product"
)

//go:generate go run ../../tools/services-pkg-gen/main.go ../../../../ internal/generated/gen.go
Expand All @@ -25,6 +25,15 @@ var productList []string
var packageMetadataMap map[string]*product.Package
var collectionMap map[string]*product.Collection

// well-known collections
const (
AutomateCollectionName = "automate"
BuilderCollectionName = "builder"
ChefServerCollectionName = "chef-server"
WorkflowCollectionName = "workflow"
MonitoringCollectionName = "monitoring"
)

func AllServices() ([]habpkg.HabPkg, error) {
return serviceList, nil
}
Expand Down
8 changes: 8 additions & 0 deletions products.meta
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@
"chef/automate-gateway"
]
},
{
"name": "builder",
"type": "product",
"aliases": ["depot"],
"hidden": true,
"dependencies": ["core", "postgresql", "auth"],
"services": []
},
{
"name": "chef-server",
"type": "product",
Expand Down

0 comments on commit caf2a67

Please sign in to comment.