mirror of
https://github.com/openziti/zrok.git
synced 2024-12-31 19:22:37 +01:00
assert metrics serp (#131)
This commit is contained in:
parent
4d75e2da4f
commit
6e42fa0225
@ -12,6 +12,7 @@ import (
|
||||
"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_management_api_client/service_edge_router_policy"
|
||||
"github.com/openziti/edge/rest_model"
|
||||
rest_model_edge "github.com/openziti/edge/rest_model"
|
||||
"github.com/openziti/sdk-golang/ziti"
|
||||
@ -69,7 +70,12 @@ func Bootstrap(skipCtrl, skipFrontend bool, inCfg *Config) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := assertMetricsService(edge); err != nil {
|
||||
var metricsSvcZId string
|
||||
if metricsSvcZId, err = assertMetricsService(cfg, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := assertMetricsSerp(metricsSvcZId, cfg, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -196,8 +202,8 @@ func assertErpForIdentity(name, zId string, edge *rest_management_api_client.Zit
|
||||
return nil
|
||||
}
|
||||
|
||||
func assertMetricsService(edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := "name=\"metrics\" and tags.zrok != null"
|
||||
func assertMetricsService(cfg *Config, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
filter := fmt.Sprintf("name=\"%v\" and tags.zrok != null", cfg.Metrics.ServiceName)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
listReq := &service.ListServicesParams{
|
||||
@ -208,15 +214,44 @@ func assertMetricsService(edge *rest_management_api_client.ZitiEdgeManagement) e
|
||||
listReq.SetTimeout(30 * time.Second)
|
||||
listResp, err := edge.Service.ListServices(listReq, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing metrics service")
|
||||
return "", errors.Wrapf(err, "error listing '%v' service", cfg.Metrics.ServiceName)
|
||||
}
|
||||
var svcZId string
|
||||
if len(listResp.Payload.Data) != 1 {
|
||||
logrus.Infof("creating '%v' service", cfg.Metrics.ServiceName)
|
||||
svcZId, err = createService("metrics", nil, nil, edge)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error creating '%v' service", cfg.Metrics.ServiceName)
|
||||
}
|
||||
} else {
|
||||
svcZId = *listResp.Payload.Data[0].ID
|
||||
}
|
||||
|
||||
logrus.Infof("asserted '%v' service (%v)", cfg.Metrics.ServiceName, svcZId)
|
||||
return svcZId, nil
|
||||
}
|
||||
|
||||
func assertMetricsSerp(metricsSvcZId string, cfg *Config, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("allOf(serviceRoles) = \"@%v\" and allOf(edgeRouterRoles) = \"#all\" and tags.zrok != null", metricsSvcZId)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
listReq := &service_edge_router_policy.ListServiceEdgeRouterPoliciesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
}
|
||||
listReq.SetTimeout(30 * time.Second)
|
||||
listResp, err := edge.ServiceEdgeRouterPolicy.ListServiceEdgeRouterPolicies(listReq, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error listing '%v' serps", cfg.Metrics.ServiceName)
|
||||
}
|
||||
if len(listResp.Payload.Data) != 1 {
|
||||
logrus.Infof("creating 'metrics' service")
|
||||
_, err := createService("metrics", nil, nil, edge)
|
||||
logrus.Infof("creating '%v' serp", cfg.Metrics.ServiceName)
|
||||
_, err := createServiceEdgeRouterPolicy(cfg.Metrics.ServiceName, metricsSvcZId, nil, edge)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating metrics service")
|
||||
return errors.Wrapf(err, "error creating '%v' serp", cfg.Metrics.ServiceName)
|
||||
}
|
||||
}
|
||||
logrus.Infof("asserted metrics service")
|
||||
logrus.Infof("asserted '%v' serp", cfg.Metrics.ServiceName)
|
||||
return nil
|
||||
}
|
||||
|
@ -22,16 +22,29 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func createServiceEdgeRouterPolicy(envZId, svcToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
func createShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
serpZId, err := createServiceEdgeRouterPolicy(svcToken, svcZId, zrokServiceTags(svcToken).SubTags, edge)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("created service edge router policy '%v' for service '%v' for environment '%v'", serpZId, svcZId, envZId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func createServiceEdgeRouterPolicy(name, svcZId string, moreTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
edgeRouterRoles := []string{"#all"}
|
||||
semantic := rest_model.SemanticAllOf
|
||||
serviceRoles := []string{fmt.Sprintf("@%v", svcZId)}
|
||||
tags := zrokTags()
|
||||
for k, v := range moreTags {
|
||||
tags.SubTags[k] = v
|
||||
}
|
||||
serp := &rest_model.ServiceEdgeRouterPolicyCreate{
|
||||
EdgeRouterRoles: edgeRouterRoles,
|
||||
Name: &svcToken,
|
||||
Name: &name,
|
||||
Semantic: &semantic,
|
||||
ServiceRoles: serviceRoles,
|
||||
Tags: zrokServiceTags(svcToken),
|
||||
Tags: tags,
|
||||
}
|
||||
serpParams := &service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{
|
||||
Policy: serp,
|
||||
@ -40,10 +53,9 @@ func createServiceEdgeRouterPolicy(envZId, svcToken, svcZId string, edge *rest_m
|
||||
serpParams.SetTimeout(30 * time.Second)
|
||||
resp, err := edge.ServiceEdgeRouterPolicy.CreateServiceEdgeRouterPolicy(serpParams, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
return "", errors.Wrapf(err, "error creating serp '%v' for service '%v'", name, svcZId)
|
||||
}
|
||||
logrus.Infof("created service edge router policy '%v' for service '%v' for environment '%v'", resp.Payload.Data.ID, svcZId, envZId)
|
||||
return nil
|
||||
return resp.Payload.Data.ID, nil
|
||||
}
|
||||
|
||||
func deleteServiceEdgeRouterPolicy(envZId, svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
@ -277,6 +289,7 @@ func createService(name string, cfgIds []string, moreTags map[string]interface{}
|
||||
for k, v := range moreTags {
|
||||
tags.SubTags[k] = v
|
||||
}
|
||||
svc.Tags = tags
|
||||
req := &edge_service.CreateServiceParams{
|
||||
Service: svc,
|
||||
Context: context.Background(),
|
||||
|
@ -31,7 +31,7 @@ func (a *privateResourceAllocator) allocate(envZId, svcToken string, params serv
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := createServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil {
|
||||
if err := createShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ func (a *publicResourceAllocator) allocate(envZId, svcToken string, params servi
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := createServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil {
|
||||
if err := createShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user