diff --git a/components/automate-cli/cmd/chef-automate/pre_flight_check.go b/components/automate-cli/cmd/chef-automate/pre_flight_check.go index ae5ed4b1932..33a56eb0aae 100644 --- a/components/automate-cli/cmd/chef-automate/pre_flight_check.go +++ b/components/automate-cli/cmd/chef-automate/pre_flight_check.go @@ -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{ @@ -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 } @@ -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) } diff --git a/components/automate-deployment/pkg/assets/assets.bindata.go b/components/automate-deployment/pkg/assets/assets.bindata.go index 28d5a4a14bf..c2b4a4a0cce 100644 --- a/components/automate-deployment/pkg/assets/assets.bindata.go +++ b/components/automate-deployment/pkg/assets/assets.bindata.go @@ -90,7 +90,7 @@ func dataA1_elasticsearch_mappingsComplianceTemplateJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "data/a1_elasticsearch_mappings/compliance-template.json", size: 5111, mode: os.FileMode(0644), modTime: time.Unix(1566504744, 0)} + info := bindataFileInfo{name: "data/a1_elasticsearch_mappings/compliance-template.json", size: 5111, mode: os.FileMode(0664), modTime: time.Unix(1553885095, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x80, 0x73, 0x93, 0x83, 0xd, 0xe8, 0x6a, 0x41, 0xce, 0x60, 0x54, 0x83, 0x5f, 0xfe, 0xad, 0x90, 0x12, 0x3a, 0x91, 0xf0, 0xf9, 0xae, 0x1e, 0x49, 0x0, 0x92, 0x72, 0xd8, 0xd2, 0x98, 0x5d, 0xbe}} return a, nil } @@ -110,7 +110,7 @@ func dataA1_elasticsearch_mappingsInsightsTemplateJson() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "data/a1_elasticsearch_mappings/insights-template.json", size: 2705, mode: os.FileMode(0644), modTime: time.Unix(1566504744, 0)} + info := bindataFileInfo{name: "data/a1_elasticsearch_mappings/insights-template.json", size: 2705, mode: os.FileMode(0664), modTime: time.Unix(1553885095, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x30, 0xf6, 0x70, 0xce, 0xf, 0x2b, 0x35, 0x79, 0x84, 0x27, 0x45, 0xe3, 0xc7, 0x5e, 0x15, 0x7c, 0x9f, 0x57, 0x4e, 0x57, 0x88, 0x17, 0x40, 0x66, 0x91, 0x8a, 0x58, 0x66, 0x54, 0xb5, 0xed, 0xe6}} return a, nil } @@ -130,7 +130,7 @@ func dataA1stub_certsChefautomateupgradefromv1selftestCrl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.crl", size: 958, mode: os.FileMode(0644), modTime: time.Unix(1566504744, 0)} + info := bindataFileInfo{name: "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.crl", size: 958, mode: os.FileMode(0664), modTime: time.Unix(1553885095, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x77, 0xcc, 0x17, 0xf2, 0xe5, 0x86, 0x17, 0x26, 0xf6, 0x6, 0xa9, 0x30, 0x16, 0xf, 0x54, 0x6, 0x44, 0xf, 0x27, 0xb2, 0xdd, 0x5a, 0x31, 0x5a, 0x52, 0x7b, 0xac, 0x66, 0x40, 0x9d, 0x2e, 0x5a}} return a, nil } @@ -150,7 +150,7 @@ func dataA1stub_certsChefautomateupgradefromv1selftestCrt() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.crt", size: 1826, mode: os.FileMode(0644), modTime: time.Unix(1566504744, 0)} + info := bindataFileInfo{name: "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.crt", size: 1826, mode: os.FileMode(0664), modTime: time.Unix(1553885095, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x87, 0xb1, 0x2b, 0x70, 0xe3, 0xf2, 0x57, 0x2e, 0xdf, 0x85, 0xbb, 0x15, 0x84, 0x2d, 0x64, 0xa9, 0x16, 0xf6, 0x5e, 0x3f, 0xaf, 0x88, 0x2f, 0x24, 0xd7, 0x17, 0xf3, 0xf5, 0x4c, 0x1d, 0xe, 0x6}} return a, nil } @@ -170,7 +170,7 @@ func dataA1stub_certsChefautomateupgradefromv1selftestKey() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.key", size: 3243, mode: os.FileMode(0644), modTime: time.Unix(1566504744, 0)} + info := bindataFileInfo{name: "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.key", size: 3243, mode: os.FileMode(0664), modTime: time.Unix(1553885095, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4, 0x32, 0x66, 0x33, 0x9a, 0xb6, 0xc1, 0xae, 0x6e, 0x1a, 0x57, 0xe, 0xe2, 0x12, 0x25, 0xed, 0x8d, 0xc, 0x2d, 0x1c, 0x84, 0xac, 0xbd, 0xa4, 0x93, 0x9c, 0x43, 0xe0, 0x2d, 0x9b, 0xdf, 0x18}} return a, nil } @@ -190,7 +190,7 @@ func dataBindsTxt() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "data/binds.txt", size: 4607, mode: os.FileMode(0644), modTime: time.Unix(1571076827, 0)} + info := bindataFileInfo{name: "data/binds.txt", size: 4607, mode: os.FileMode(0664), modTime: time.Unix(1571570031, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x75, 0xbe, 0x5c, 0x3, 0x53, 0x63, 0xbd, 0xd6, 0xc7, 0x4c, 0xd4, 0x9f, 0x17, 0x81, 0x74, 0x9f, 0xe6, 0xa0, 0x31, 0x81, 0xa6, 0xfc, 0x27, 0xf1, 0x34, 0x92, 0xdc, 0xdc, 0xe3, 0xaf, 0xf0, 0x47}} return a, nil } @@ -210,7 +210,7 @@ func dataInitConfigToml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "data/init-config.toml", size: 1823, mode: os.FileMode(0644), modTime: time.Unix(1566504744, 0)} + info := bindataFileInfo{name: "data/init-config.toml", size: 1823, mode: os.FileMode(0664), modTime: time.Unix(1564097685, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4b, 0x1f, 0x79, 0x32, 0x71, 0x8, 0xfa, 0xed, 0x21, 0xb5, 0x8a, 0x2, 0x69, 0x5, 0x75, 0xdf, 0xf7, 0xf9, 0xdb, 0xa0, 0x0, 0xbd, 0x89, 0xda, 0xdd, 0x66, 0x5e, 0xe3, 0xd0, 0x57, 0xee, 0x8e}} return a, nil } @@ -307,17 +307,11 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ "data/a1_elasticsearch_mappings/compliance-template.json": dataA1_elasticsearch_mappingsComplianceTemplateJson, - - "data/a1_elasticsearch_mappings/insights-template.json": dataA1_elasticsearch_mappingsInsightsTemplateJson, - + "data/a1_elasticsearch_mappings/insights-template.json": dataA1_elasticsearch_mappingsInsightsTemplateJson, "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.crl": dataA1stub_certsChefautomateupgradefromv1selftestCrl, - "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.crt": dataA1stub_certsChefautomateupgradefromv1selftestCrt, - "data/a1stub_certs/ChefAutomateUpgradeFromv1SelfTest.key": dataA1stub_certsChefautomateupgradefromv1selftestKey, - - "data/binds.txt": dataBindsTxt, - + "data/binds.txt": dataBindsTxt, "data/init-config.toml": dataInitConfigToml, } diff --git a/components/automate-deployment/pkg/deployment/deployment.go b/components/automate-deployment/pkg/deployment/deployment.go index 0bccb09763f..d1e3e561dd2 100644 --- a/components/automate-deployment/pkg/deployment/deployment.go +++ b/components/automate-deployment/pkg/deployment/deployment.go @@ -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, ", ") diff --git a/components/automate-deployment/pkg/preflight/checks.go b/components/automate-deployment/pkg/preflight/checks.go index dced228a8fd..5bcee63465f 100644 --- a/components/automate-deployment/pkg/preflight/checks.go +++ b/components/automate-deployment/pkg/preflight/checks.go @@ -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 { @@ -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 { @@ -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 diff --git a/components/automate-deployment/pkg/preflight/preflight.go b/components/automate-deployment/pkg/preflight/preflight.go index 77568a64b07..edbf346f2ed 100644 --- a/components/automate-deployment/pkg/preflight/preflight.go +++ b/components/automate-deployment/pkg/preflight/preflight.go @@ -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") @@ -60,7 +64,7 @@ func (c *DeployPreflightChecker) Run(probe TestProbe) error { checks := []Check{ RootUserRequiredCheck(), - DefaultMinimumDiskCheck(), + DefaultMinimumDiskCheck(c.automateConfig), chefAutomateInBinCheck, isA2DeployedCheck, IsSystemdCheck(), diff --git a/components/automate-deployment/pkg/services/internal/generated/gen.go b/components/automate-deployment/pkg/services/internal/generated/gen.go index 923f1652fc5..b617d25d701 100644 --- a/components/automate-deployment/pkg/services/internal/generated/gen.go +++ b/components/automate-deployment/pkg/services/internal/generated/gen.go @@ -461,6 +461,21 @@ var ProductMetadataJSON = ` ], "hidden": false }, + { + "name": "builder", + "aliases": [ + "depot" + ], + "type": "product", + "services": [], + "packages": null, + "dependencies": [ + "core", + "postgresql", + "auth" + ], + "hidden": true + }, { "name": "chef-server", "aliases": [ diff --git a/components/automate-deployment/pkg/services/services.go b/components/automate-deployment/pkg/services/services.go index 12b1b428f88..cbec2f8428c 100644 --- a/components/automate-deployment/pkg/services/services.go +++ b/components/automate-deployment/pkg/services/services.go @@ -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 @@ -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 } diff --git a/products.meta b/products.meta index a6fae008274..24ab6c3bf1b 100644 --- a/products.meta +++ b/products.meta @@ -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",