Skip to content

Commit 378c362

Browse files
authored
cmd: Handle case when deployment template does not include kibana (#206)
Fixes a bug where the application would panic if it could not find the desired resource kind in the deployment template.
1 parent 7a67954 commit 378c362

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/deployment/depresource/kibana.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package depresource
1919

2020
import (
21+
"fmt"
22+
2123
"github.com/elastic/cloud-sdk-go/pkg/api"
2224
"github.com/elastic/cloud-sdk-go/pkg/client/platform_configuration_templates"
2325
"github.com/elastic/cloud-sdk-go/pkg/models"
@@ -56,6 +58,11 @@ func NewKibana(params NewStateless) (*models.KibanaPayload, error) {
5658
return nil, api.UnwrapError(err)
5759
}
5860

61+
if res.Payload.ClusterTemplate.Kibana == nil {
62+
return nil, fmt.Errorf("deployment: the %s template is not configured for Kibana. Please use another template if you wish to start Kibana instances",
63+
params.TemplateID)
64+
}
65+
5966
var clusterTopology = res.Payload.ClusterTemplate.Kibana.Plan.ClusterTopology
6067
var topology = models.KibanaClusterTopologyElement{Size: new(models.TopologySize)}
6168
if len(clusterTopology) > 0 {

pkg/deployment/depresource/kibana_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ var kibanaTemplateResponse = models.DeploymentTemplateInfo{
5454
},
5555
}
5656

57+
var invalidTemplateResponse = models.DeploymentTemplateInfo{
58+
ID: "invalid",
59+
ClusterTemplate: &models.DeploymentTemplateDefinitionRequest{
60+
Plan: &models.ElasticsearchClusterPlan{
61+
ClusterTopology: defaultESTopologies,
62+
},
63+
},
64+
}
65+
5766
func TestNewKibana(t *testing.T) {
5867
var internalError = models.BasicFailedReply{
5968
Errors: []*models.BasicFailedReplyElement{
@@ -139,6 +148,18 @@ func TestNewKibana(t *testing.T) {
139148
}},
140149
err: errors.New(string(internalErrorBytes)),
141150
},
151+
{
152+
name: "obtains the deployment template but it's an invalid template for kibana",
153+
args: args{params: NewStateless{
154+
DeploymentID: util.ValidClusterID,
155+
API: api.NewMock(
156+
mock.New200Response(mock.NewStructBody(getResponse)),
157+
mock.New200Response(mock.NewStructBody(invalidTemplateResponse)),
158+
),
159+
Region: "ece-region",
160+
}},
161+
err: errors.New("deployment: the an ID template is not configured for Kibana. Please use another template if you wish to start Kibana instances"),
162+
},
142163
{
143164
name: "succeeds with no argument override",
144165
args: args{params: NewStateless{

0 commit comments

Comments
 (0)