Skip to content

Commit

Permalink
cmd: Handle case when deployment template does not include kibana (#206)
Browse files Browse the repository at this point in the history
Fixes a bug where the application would panic if it could not find the desired resource kind in the deployment template.
  • Loading branch information
karencfv committed Mar 11, 2020
1 parent 7a67954 commit 378c362
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/deployment/depresource/kibana.go
Expand Up @@ -18,6 +18,8 @@
package depresource

import (
"fmt"

"github.com/elastic/cloud-sdk-go/pkg/api"
"github.com/elastic/cloud-sdk-go/pkg/client/platform_configuration_templates"
"github.com/elastic/cloud-sdk-go/pkg/models"
Expand Down Expand Up @@ -56,6 +58,11 @@ func NewKibana(params NewStateless) (*models.KibanaPayload, error) {
return nil, api.UnwrapError(err)
}

if res.Payload.ClusterTemplate.Kibana == nil {
return nil, fmt.Errorf("deployment: the %s template is not configured for Kibana. Please use another template if you wish to start Kibana instances",
params.TemplateID)
}

var clusterTopology = res.Payload.ClusterTemplate.Kibana.Plan.ClusterTopology
var topology = models.KibanaClusterTopologyElement{Size: new(models.TopologySize)}
if len(clusterTopology) > 0 {
Expand Down
21 changes: 21 additions & 0 deletions pkg/deployment/depresource/kibana_test.go
Expand Up @@ -54,6 +54,15 @@ var kibanaTemplateResponse = models.DeploymentTemplateInfo{
},
}

var invalidTemplateResponse = models.DeploymentTemplateInfo{
ID: "invalid",
ClusterTemplate: &models.DeploymentTemplateDefinitionRequest{
Plan: &models.ElasticsearchClusterPlan{
ClusterTopology: defaultESTopologies,
},
},
}

func TestNewKibana(t *testing.T) {
var internalError = models.BasicFailedReply{
Errors: []*models.BasicFailedReplyElement{
Expand Down Expand Up @@ -139,6 +148,18 @@ func TestNewKibana(t *testing.T) {
}},
err: errors.New(string(internalErrorBytes)),
},
{
name: "obtains the deployment template but it's an invalid template for kibana",
args: args{params: NewStateless{
DeploymentID: util.ValidClusterID,
API: api.NewMock(
mock.New200Response(mock.NewStructBody(getResponse)),
mock.New200Response(mock.NewStructBody(invalidTemplateResponse)),
),
Region: "ece-region",
}},
err: errors.New("deployment: the an ID template is not configured for Kibana. Please use another template if you wish to start Kibana instances"),
},
{
name: "succeeds with no argument override",
args: args{params: NewStateless{
Expand Down

0 comments on commit 378c362

Please sign in to comment.