Skip to content

Commit

Permalink
chore: remove debug
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed May 15, 2024
1 parent 9eecd41 commit 81b206e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 166 deletions.
2 changes: 1 addition & 1 deletion cmd/beekeeper/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func setupNodes(ctx context.Context, clusterConfig config.Cluster, cfg *config.C

if clusterConfig.IsUsingStaticEndpoints() {
for nodeName, endpoint := range v.GetEndpoints() {
beeOpt := orchestration.WithURLs(endpoint.APIURL, endpoint.DebugAPIURL)
beeOpt := orchestration.WithURL(endpoint.APIURL)
nodeCount++
go setupOrAddNode(ctx, false, ng, nodeName, orchestration.NodeOptions{
Config: &bConfig,
Expand Down
Empty file removed pkg/bee/debugapi/debugapi.go
Empty file.
28 changes: 12 additions & 16 deletions pkg/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ type Cluster struct {
// parent to inherit settings from
*Inherit `yaml:",inline"`
// Cluster configuration
Name *string `yaml:"name"`
Namespace *string `yaml:"namespace"`
DisableNamespace *bool `yaml:"disable-namespace"`
UseStaticEndpoints *bool `yaml:"use-static-endpoints"`
APIDomain *string `yaml:"api-domain"`
APIInsecureTLS *bool `yaml:"api-insecure-tls"`
APIScheme *string `yaml:"api-scheme"`
DebugAPIDomain *string `yaml:"debug-api-domain"`
DebugAPIInsecureTLS *bool `yaml:"debug-api-insecure-tls"`
DebugAPIScheme *string `yaml:"debug-api-scheme"`
Funding *Funding `yaml:"funding"`
NodeGroups *map[string]ClusterNodeGroup `yaml:"node-groups"`
AdminPassword *string `yaml:"admin-password"`
Name *string `yaml:"name"`
Namespace *string `yaml:"namespace"`
DisableNamespace *bool `yaml:"disable-namespace"`
UseStaticEndpoints *bool `yaml:"use-static-endpoints"`
APIDomain *string `yaml:"api-domain"`
APIInsecureTLS *bool `yaml:"api-insecure-tls"`
APIScheme *string `yaml:"api-scheme"`
Funding *Funding `yaml:"funding"`
NodeGroups *map[string]ClusterNodeGroup `yaml:"node-groups"`
AdminPassword *string `yaml:"admin-password"`
}

// ClusterNodeGroup represents node group in the cluster
Expand All @@ -47,9 +44,8 @@ type ClusterNode struct {
}

type NodeEndpoint struct {
Name string `yaml:"name"`
APIURL string `yaml:"api-url"`
DebugAPIURL string `yaml:"debug-api-url"`
Name string `yaml:"name"`
APIURL string `yaml:"api-url"`
}

type Clef struct {
Expand Down
21 changes: 0 additions & 21 deletions pkg/orchestration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,3 @@ func (c ClusterOptions) IngressHost(name string) string {
}
return fmt.Sprintf("%s.%s.%s", name, c.Namespace, c.APIDomain)
}

// DebugAPIURL generates URL for node's DebugAPI
func (c ClusterOptions) DebugAPIURL(name string) (u *url.URL, err error) {
if c.DisableNamespace {
u, err = url.Parse(fmt.Sprintf("%s://%s-debug.%s", c.DebugAPIScheme, name, c.DebugAPIDomain))
} else {
u, err = url.Parse(fmt.Sprintf("%s://%s-debug.%s.%s", c.DebugAPIScheme, name, c.Namespace, c.DebugAPIDomain))
}
if err != nil {
return nil, fmt.Errorf("bad debug API url for node %s: %w", name, err)
}
return
}

// IngressDebugHost generates host for node's DebugAPI ingress
func (c ClusterOptions) IngressDebugHost(name string) string {
if c.DisableNamespace {
return fmt.Sprintf("%s-debug.%s", name, c.DebugAPIDomain)
}
return fmt.Sprintf("%s-debug.%s.%s", name, c.Namespace, c.DebugAPIDomain)
}
107 changes: 0 additions & 107 deletions pkg/orchestration/k8s/node_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,85 +200,6 @@ func (n *nodeOrchestrator) Create(ctx context.Context, o orchestration.CreateOpt
n.log.Infof("ingress %s is set in namespace %s", apiIn, o.Namespace)
}

// debug API
portDebug, err := parsePort(o.Config.DebugAPIAddr)
if err != nil {
return fmt.Errorf("parsing Debug port from config: %s", err)
}

// debug service
debugSvc := fmt.Sprintf("%s-debug", o.Name)
if _, err := n.k8s.Service.Set(ctx, debugSvc, o.Namespace, service.Options{
Annotations: o.Annotations,
Labels: o.Labels,
ServiceSpec: service.Spec{
Ports: service.Ports{{
AppProtocol: "TCP",
Name: "debug",
Protocol: "TCP",
Port: portDebug,
TargetPort: "debug",
}},
Selector: o.Selector,
Type: "ClusterIP",
},
}); err != nil {
return fmt.Errorf("set service in namespace %s: %w", o.Namespace, err)
}
n.log.Infof("service %s is set in namespace %s", debugSvc, o.Namespace)

if o.IngressDebugClass == "traefik" {
// debug service's ingressroute
debugIn := fmt.Sprintf("%s-debug", o.Name)
if _, err := n.k8s.IngressRoute.Set(ctx, debugIn, o.Namespace, ingressroute.Options{
Annotations: mergeMaps(o.Annotations, o.IngressAnnotations),
Labels: o.Labels,
Spec: ingressroute.IngressRouteSpec{
Routes: []ingressroute.Route{
{
Kind: "Rule",
Match: fmt.Sprintf("Host(\"%s.localhost\") && PathPrefix(\"/\")", debugIn),
Services: []ingressroute.Service{
{
Kind: "Service",
Name: debugIn,
Namespace: "local",
Port: "debug",
},
},
},
},
},
}); err != nil {
return fmt.Errorf("set ingressroute in namespace %s: %w", o.Namespace, err)
}
n.log.Infof("ingressroute %s is set in namespace %s", debugIn, o.Namespace)
} else {
// debug service's ingress
debugIn := fmt.Sprintf("%s-debug", o.Name)
if _, err := n.k8s.Ingress.Set(ctx, debugIn, o.Namespace, ingress.Options{
Annotations: mergeMaps(o.Annotations, o.IngressDebugAnnotations),
Labels: o.Labels,
Spec: ingress.Spec{
Class: o.IngressDebugClass,
Rules: ingress.Rules{{
Host: o.IngressDebugHost,
Paths: ingress.Paths{{
Backend: ingress.Backend{
ServiceName: debugSvc,
ServicePortName: "debug",
},
Path: "/",
PathType: "ImplementationSpecific",
}},
}},
},
}); err != nil {
return fmt.Errorf("set ingress in namespace %s: %w", o.Namespace, err)
}
n.log.Infof("ingress %s is set in namespace %s", debugIn, o.Namespace)
}

// p2p service
portP2P, err := parsePort(o.Config.P2PAddr)
if err != nil {
Expand Down Expand Up @@ -329,13 +250,6 @@ func (n *nodeOrchestrator) Create(ctx context.Context, o orchestration.CreateOpt
Port: portAPI,
TargetPort: "api",
},
{
AppProtocol: "TCP",
Name: "debug",
Protocol: "TCP",
Port: portDebug,
TargetPort: "debug",
},
{
AppProtocol: "TCP",
Name: "p2p",
Expand Down Expand Up @@ -386,7 +300,6 @@ func (n *nodeOrchestrator) Create(ctx context.Context, o orchestration.CreateOpt
Image: o.Image,
ImagePullPolicy: o.ImagePullPolicy,
PortAPI: portAPI,
PortDebug: portDebug,
PortP2P: portP2P,
PersistenceEnabled: o.PersistenceEnabled,
ResourcesLimitCPU: o.ResourcesLimitCPU,
Expand Down Expand Up @@ -457,26 +370,6 @@ func (n *nodeOrchestrator) Delete(ctx context.Context, name string, namespace st
}
n.log.Infof("service %s is deleted in namespace %s", p2pSvc, namespace)

// debug service's ingress
debugIn := fmt.Sprintf("%s-debug", name)
if err := n.k8s.Ingress.Delete(ctx, debugIn, namespace); err != nil {
return fmt.Errorf("deleting ingress in namespace %s: %w", namespace, err)
}
n.log.Infof("ingress %s is deleted in namespace %s", debugIn, namespace)

// debug service's ingress route
if err := n.k8s.IngressRoute.Delete(ctx, debugIn, namespace); err != nil {
return fmt.Errorf("deleting ingress route in namespace %s: %w", namespace, err)
}
n.log.Infof("ingress route %s is deleted in namespace %s", debugIn, namespace)

// debug service
debugSvc := fmt.Sprintf("%s-debug", name)
if err := n.k8s.Service.Delete(ctx, debugSvc, namespace); err != nil {
return fmt.Errorf("deleting service in namespace %s: %w", namespace, err)
}
n.log.Infof("service %s is deleted in namespace %s", debugSvc, namespace)

// api service's ingress
apiIn := fmt.Sprintf("%s-api", name)
if err := n.k8s.Ingress.Delete(ctx, apiIn, namespace); err != nil {
Expand Down
17 changes: 4 additions & 13 deletions pkg/orchestration/k8s/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ func NewNodeGroup(name string, copts orchestration.ClusterOptions, no orchestrat
// AddNode adss new node to the node group
func (g *NodeGroup) AddNode(ctx context.Context, name string, o orchestration.NodeOptions, opts ...orchestration.BeeClientOption) (err error) {
var aURL *url.URL
var dURL *url.URL

aURL, err = g.clusterOpts.ApiURL(name)
if err != nil {
return fmt.Errorf("API URL %s: %w", name, err)
}
dURL, err = g.clusterOpts.DebugAPIURL(name)
if err != nil {
return fmt.Errorf("debug API URL %s: %w", name, err)
}

// TODO: make more granular, check every sub-option
var config *orchestration.Config
Expand All @@ -71,12 +66,10 @@ func (g *NodeGroup) AddNode(ctx context.Context, name string, o orchestration.No
}

beeClientOpts := bee.ClientOptions{
APIURL: aURL,
APIInsecureTLS: g.clusterOpts.APIInsecureTLS,
DebugAPIURL: dURL,
DebugAPIInsecureTLS: g.clusterOpts.DebugAPIInsecureTLS,
Retry: 5,
Restricted: config.Restricted,
APIURL: aURL,
APIInsecureTLS: g.clusterOpts.APIInsecureTLS,
Retry: 5,
Restricted: config.Restricted,
}

for _, opt := range opts {
Expand Down Expand Up @@ -345,8 +338,6 @@ func (g *NodeGroup) CreateNode(ctx context.Context, name string) (err error) {
IngressAnnotations: g.opts.IngressAnnotations,
IngressClass: g.opts.IngressClass,
IngressHost: g.clusterOpts.IngressHost(name),
IngressDebugAnnotations: g.opts.IngressDebugAnnotations,
IngressDebugClass: g.opts.IngressDebugClass,
Labels: labels,
LibP2PKey: n.LibP2PKey(),
NodeSelector: g.opts.NodeSelector,
Expand Down
10 changes: 2 additions & 8 deletions pkg/orchestration/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,15 @@ type NodeGroupTopologies map[string]bee.Topology
// BeeClientOption represents bee client option
type BeeClientOption func(*bee.ClientOptions) error

// WithAPIURL returns BeeClientOption with given api url and debug api url
func WithURLs(apiURL, debugAPIURL string) BeeClientOption {
// WithURL returns BeeClientOption with given api url
func WithURL(apiURL string) BeeClientOption {
return func(o *bee.ClientOptions) error {
api, err := url.Parse(apiURL)
if err != nil {
return fmt.Errorf("invalid api url: %w", err)
}

debug, err := url.Parse(debugAPIURL)
if err != nil {
return fmt.Errorf("invalid debug api url: %w", err)
}

o.APIURL = api
o.DebugAPIURL = debug
return nil
}
}
Expand Down

0 comments on commit 81b206e

Please sign in to comment.