mirror of
https://github.com/openziti/zrok.git
synced 2024-11-26 01:54:09 +01:00
lint; assert 'metrics' service (#131)
This commit is contained in:
parent
15d289cc87
commit
4d75e2da4f
@ -11,6 +11,7 @@ import (
|
||||
"github.com/openziti/edge/rest_management_api_client/config"
|
||||
"github.com/openziti/edge/rest_management_api_client/edge_router_policy"
|
||||
"github.com/openziti/edge/rest_management_api_client/identity"
|
||||
"github.com/openziti/edge/rest_management_api_client/service"
|
||||
"github.com/openziti/edge/rest_model"
|
||||
rest_model_edge "github.com/openziti/edge/rest_model"
|
||||
"github.com/openziti/sdk-golang/ziti"
|
||||
@ -68,6 +69,10 @@ func Bootstrap(skipCtrl, skipFrontend bool, inCfg *Config) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := assertMetricsService(edge); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -145,13 +150,13 @@ func assertIdentity(zId string, edge *rest_management_api_client.ZitiEdgeManagem
|
||||
func bootstrapIdentity(name string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
idc, err := createIdentity(name, rest_model_edge.IdentityTypeDevice, nil, edge)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error creating 'ctrl' identity")
|
||||
return "", errors.Wrapf(err, "error creating '%v' identity", name)
|
||||
}
|
||||
|
||||
zId := idc.Payload.Data.ID
|
||||
cfg, err := enrollIdentity(zId, edge)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error enrolling 'ctrl' identity")
|
||||
return "", errors.Wrapf(err, "error enrolling '%v' identity", name)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
@ -168,7 +173,6 @@ func bootstrapIdentity(name string, edge *rest_management_api_client.ZitiEdgeMan
|
||||
}
|
||||
|
||||
func assertErpForIdentity(name, zId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
logrus.Infof("asserting erps for '%v'", name)
|
||||
filter := fmt.Sprintf("name=\"%v\" and tags.zrok != null", name)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
@ -191,3 +195,28 @@ func assertErpForIdentity(name, zId string, edge *rest_management_api_client.Zit
|
||||
logrus.Infof("asserted erps for '%v' (%v)", name, zId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func assertMetricsService(edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := "name=\"metrics\" and tags.zrok != null"
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
listReq := &service.ListServicesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
}
|
||||
listReq.SetTimeout(30 * time.Second)
|
||||
listResp, err := edge.Service.ListServices(listReq, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing metrics service")
|
||||
}
|
||||
if len(listResp.Payload.Data) != 1 {
|
||||
logrus.Infof("creating 'metrics' service")
|
||||
_, err := createService("metrics", nil, nil, edge)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating metrics service")
|
||||
}
|
||||
}
|
||||
logrus.Infof("asserted metrics service")
|
||||
return nil
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
rest_model_edge "github.com/openziti/edge/rest_model"
|
||||
sdk_config "github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/openziti/sdk-golang/ziti/enroll"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
@ -252,14 +253,29 @@ func deleteConfig(envZId, svcToken string, edge *rest_management_api_client.Ziti
|
||||
return nil
|
||||
}
|
||||
|
||||
func createService(envZId, svcToken, cfgId string, edge *rest_management_api_client.ZitiEdgeManagement) (serviceId string, err error) {
|
||||
func createShareService(envZId, svcToken, cfgId string, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, err error) {
|
||||
configs := []string{cfgId}
|
||||
tags := zrokServiceTags(svcToken)
|
||||
svcZId, err = createService(svcToken, configs, tags.SubTags, edge)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error creating service '%v'", svcToken)
|
||||
}
|
||||
logrus.Infof("created zrok service named '%v' (with ziti id '%v') for environment '%v'", svcToken, svcZId, envZId)
|
||||
return svcZId, nil
|
||||
}
|
||||
|
||||
func createService(name string, cfgIds []string, moreTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, err error) {
|
||||
encryptionRequired := true
|
||||
svc := &rest_model.ServiceCreate{
|
||||
Configs: configs,
|
||||
EncryptionRequired: &encryptionRequired,
|
||||
Name: &svcToken,
|
||||
Tags: zrokServiceTags(svcToken),
|
||||
Name: &name,
|
||||
}
|
||||
if cfgIds != nil {
|
||||
svc.Configs = cfgIds
|
||||
}
|
||||
tags := zrokTags()
|
||||
for k, v := range moreTags {
|
||||
tags.SubTags[k] = v
|
||||
}
|
||||
req := &edge_service.CreateServiceParams{
|
||||
Service: svc,
|
||||
@ -270,7 +286,6 @@ func createService(envZId, svcToken, cfgId string, edge *rest_management_api_cli
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
logrus.Infof("created zrok service named '%v' (with ziti id '%v') for environment '%v'", svcToken, resp.Payload.Data.ID, envZId)
|
||||
return resp.Payload.Data.ID, nil
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ func (a *privateResourceAllocator) allocate(envZId, svcToken string, params serv
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
svcZId, err = createService(envZId, svcToken, cfgId, edge)
|
||||
svcZId, err = createShareService(envZId, svcToken, cfgId, edge)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func (a *publicResourceAllocator) allocate(envZId, svcToken string, params servi
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
svcZId, err = createService(envZId, svcToken, cfgId, edge)
|
||||
svcZId, err = createShareService(envZId, svcToken, cfgId, edge)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user