Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
02a879e
Generate stack files
jsoriano May 3, 2022
97a3ce7
It builds
jsoriano May 3, 2022
935a90d
Fix docker compose file
jsoriano May 3, 2022
a1abf89
Merge remote-tracking branch 'origin/main' into profile-resources
jsoriano Nov 28, 2022
36af266
Fix profile creation
jsoriano Nov 29, 2022
6096b2d
Allow to select the current profile
jsoriano Nov 29, 2022
987028d
Move kibana healthcheck to stack
jsoriano Nov 29, 2022
8a8f8da
Remove code for service deployers from installation
jsoriano Nov 29, 2022
5fefa3c
Move service tokens and geoip to profile
jsoriano Nov 29, 2022
6a89b90
Fix tests
jsoriano Nov 29, 2022
ae24022
Unify code to load profiles in stack subcommands
jsoriano Nov 30, 2022
3d73ed7
Move stack files to stack package
jsoriano Nov 30, 2022
e164209
Add TODO
jsoriano Nov 30, 2022
01f754b
Use public go-resource
jsoriano Dec 1, 2022
dd40411
Merge remote-tracking branch 'origin/main' into profile-resources
jsoriano Dec 1, 2022
d22311c
Linting
jsoriano Dec 1, 2022
5c31959
Fix username and password
jsoriano Dec 1, 2022
200b4d7
Compose provider
jsoriano Dec 1, 2022
57c3e97
Persist stack configuration
jsoriano Dec 1, 2022
a24368c
Create a cluster
jsoriano Dec 1, 2022
ebf5d95
Cloud deployment creation
jsoriano Dec 2, 2022
592d610
Tear down and status
jsoriano Dec 2, 2022
118362e
Wait for cluster to be ready
jsoriano Dec 2, 2022
280b0ab
Print urls only when available
jsoriano Dec 2, 2022
092eeee
Get provider from profile, not from flag, except for stack up
jsoriano Dec 2, 2022
210a2f1
Return hard-coded shellinit default for backwards compatibility
jsoriano Dec 2, 2022
315dd92
Fix go mod
jsoriano Dec 5, 2022
7737fec
Linting
jsoriano Dec 5, 2022
1ef359b
Merge remote-tracking branch 'origin/main' into profile-resources
jsoriano Dec 14, 2022
8b8e82a
Merge remote-tracking branch 'origin/main' into profile-resources
jsoriano Dec 19, 2022
060b76f
Fix nil pointer dereference
jsoriano Dec 19, 2022
ed1e62b
Update go-resource
jsoriano Dec 19, 2022
aa10373
Merge remote-tracking branch 'origin/main' into profile-resources
jsoriano Dec 20, 2022
b5dbf6a
Update gobuffalo/packr
jsoriano Dec 20, 2022
d400e9d
Fix custom agent deployer
jsoriano Dec 21, 2022
a17fcdd
Add variant for Kibana >= 8.7.0 with Fleet experimental toggles enabl…
jsoriano Feb 1, 2023
d964ab5
Merge remote-tracking branch 'origin/main' into profile-resources
jsoriano Feb 3, 2023
12e4139
Fix terraform deployer
jsoriano Feb 9, 2023
3657f9f
Merge remote-tracking branch 'origin/main' into profile-resources
jsoriano Feb 9, 2023
1b9fb1e
Fix terraform deployer dockerfile
jsoriano Feb 9, 2023
77bc1d5
Remove unused kibana config
jsoriano Feb 9, 2023
0655713
Fix linting
jsoriano Feb 9, 2023
b5b5b26
Fix creation of parent directories
jsoriano Feb 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Wait for cluster to be ready
  • Loading branch information
jsoriano committed Dec 2, 2022
commit 118362ea964ff34184f35e3af8359d91365cd4ef
102 changes: 52 additions & 50 deletions internal/stack/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (
"net/http"
"net/url"
"os"
"time"

"github.com/elastic/cloud-sdk-go/pkg/api"
"github.com/elastic/cloud-sdk-go/pkg/api/deploymentapi"
"github.com/elastic/cloud-sdk-go/pkg/api/deploymentapi/deptemplateapi"
"github.com/elastic/cloud-sdk-go/pkg/auth"
"github.com/elastic/cloud-sdk-go/pkg/models"
"github.com/elastic/cloud-sdk-go/pkg/plan"
"github.com/elastic/cloud-sdk-go/pkg/plan/planutil"

"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/profile"
"github.com/elastic/elastic-package/internal/signal"
)

const (
Expand Down Expand Up @@ -89,6 +89,7 @@ func (cp *cloudProvider) BootUp(options Options) error {
region := "gcp-europe-west3"
templateID := "gcp-io-optimized"

logger.Debugf("Getting deployment template %q", templateID)
template, err := deptemplateapi.Get(deptemplateapi.GetParams{
API: cp.api,
TemplateID: templateID,
Expand All @@ -115,6 +116,7 @@ func (cp *cloudProvider) BootUp(options Options) error {
plan.DeploymentTemplate.ID = &templateID
}

logger.Debugf("Creating deployment %q", name)
res, err := deploymentapi.Create(deploymentapi.CreateParams{
API: cp.api,
Request: payload,
Expand All @@ -138,6 +140,7 @@ func (cp *cloudProvider) BootUp(options Options) error {
return fmt.Errorf("deployment created, but couldn't get its ID, check in the console UI")
}
config.Parameters["cloud_deployment_id"] = *deploymentID

for _, resource := range res.Resources {
kind := resource.Kind
if kind == nil {
Expand All @@ -155,53 +158,45 @@ func (cp *cloudProvider) BootUp(options Options) error {
}
}

// Storing once before getting the endpoints, so we have the ID.
err = storeConfig(cp.profile, config)
deployment, err := deploymentapi.Get(deploymentapi.GetParams{
API: cp.api,
DeploymentID: *deploymentID,
})
if err != nil {
return fmt.Errorf("failed to store config: %w", err)
return fmt.Errorf("couldn't check deployment health: %w", err)
}

for {
deployment, err := deploymentapi.Get(deploymentapi.GetParams{
API: cp.api,
DeploymentID: *deploymentID,
})
if err != nil {
return fmt.Errorf("couldn't check deployment health: %w", err)
}

if healthy := deployment.Healthy; healthy == nil || !*healthy {
if signal.SIGINT() {
return fmt.Errorf("wait interrupted")
}
time.Sleep(1 * time.Second)
continue
}

// TODO: Check that resources are healthy too.

config.ElasticsearchHost, err = cp.getServiceURL(deployment.Resources.Elasticsearch)
if err != nil {
return fmt.Errorf("failed to get elasticsearch host: %w", err)
}
config.KibanaHost, err = cp.getServiceURL(deployment.Resources.Kibana)
if err != nil {
return fmt.Errorf("failed to get kibana host: %w", err)
}
config.Parameters["fleet_url"], err = cp.getServiceURL(deployment.Resources.IntegrationsServer)
if err != nil {
return fmt.Errorf("failed to get fleet host: %w", err)
}

break
config.ElasticsearchHost, err = cp.getServiceURL(deployment.Resources.Elasticsearch)
if err != nil {
return fmt.Errorf("failed to get elasticsearch host: %w", err)
}
config.KibanaHost, err = cp.getServiceURL(deployment.Resources.Kibana)
if err != nil {
return fmt.Errorf("failed to get kibana host: %w", err)
}
config.Parameters["fleet_url"], err = cp.getServiceURL(deployment.Resources.IntegrationsServer)
if err != nil {
return fmt.Errorf("failed to get fleet host: %w", err)
}

// Store the configuration again now with the service urls.
err = storeConfig(cp.profile, config)
if err != nil {
return fmt.Errorf("failed to store config: %w", err)
}

logger.Debug("Waiting for creation plan to be completed")
err = planutil.TrackChange(planutil.TrackChangeParams{
TrackChangeParams: plan.TrackChangeParams{
API: cp.api,
DeploymentID: *deploymentID,
},
Writer: &cloudTrackWriter{},
Format: "text",
})
if err != nil {
return fmt.Errorf("failed to track cluster creation", err)
}

return nil
}

Expand All @@ -225,16 +220,6 @@ func (cp *cloudProvider) TearDown(options Options) error {
return fmt.Errorf("failed to shutdown deployment: %w", err)
}

/*
_, err = deploymentapi.Delete(deploymentapi.DeleteParams{
API: cp.api,
DeploymentID: *deployment.ID,
})
if err != nil {
return fmt.Errorf("failed to remove deployment: %w", err)
}
*/

return nil
}

Expand All @@ -253,12 +238,22 @@ func (cp *cloudProvider) Status(options Options) ([]ServiceStatus, error) {
return nil, err
}

status, _ := cp.deploymentStatus(deployment)
return status, nil
}

func (*cloudProvider) deploymentStatus(deployment *models.DeploymentGetResponse) ([]ServiceStatus, bool) {
allHealthy := true
healthStatus := func(healthy *bool) string {
if healthy != nil && *healthy {
return "healthy"
}
allHealthy = false
return "unhealthy"
}
if healthy := deployment.Healthy; healthy == nil || !*healthy {
allHealthy = false
}

var status []ServiceStatus
for _, resource := range deployment.Resources.Elasticsearch {
Expand Down Expand Up @@ -306,7 +301,7 @@ func (cp *cloudProvider) Status(options Options) ([]ServiceStatus, error) {
})
}
}
return status, nil
return status, allHealthy
}

func (cp *cloudProvider) currentDeployment() (*models.DeploymentGetResponse, error) {
Expand Down Expand Up @@ -360,3 +355,10 @@ func (*cloudProvider) getServiceURL(resourcesResponse any) (string, error) {
}
return "", fmt.Errorf("url not found")
}

type cloudTrackWriter struct{}

func (*cloudTrackWriter) Write(p []byte) (n int, err error) {
logger.Debug(string(p))
return len(p), nil
}