Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/console/internal/app/dns-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ func (h *dnsHandler) resolver(ctx context.Context, domain string, qtype uint16)
question := m.Question[0]
sp := strings.SplitN(strings.ToLower(question.Name), fmt.Sprintf(".%s", h.kloudliteDNSSuffix), 2)
if len(sp) < 2 {
h.logger.Debug("INVALID DNS QUERY", "domain", domain, "qtype", qtype)
return nil, errInvalidDNSQuery
}

if strings.HasSuffix(sp[0], ".local") {
// INFO: domains ending with .local are supposed to be reserved for local machine only
h.logger.Debug("LOCAL DOMAIN", "domain", domain, "qtype", qtype)
return h.newRR(question.Name, 7*24*60*60, "127.0.0.1")
}

Expand All @@ -87,6 +89,7 @@ func (h *dnsHandler) resolver(ctx context.Context, domain string, qtype uint16)

sb, err := h.serviceBindingDomain.FindServiceBindingByHostname(ctx, accountName, hostname)
if err != nil {
h.logger.Debug("failed to find service binding, got", "err", err, "domain", domain, "qtype", qtype)
return nil, errors.NewEf(err, "failed to find service binding")
}

Expand Down
20 changes: 11 additions & 9 deletions apps/console/internal/domain/service-binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ func (d *domain) OnServiceBindingUpdateMessage(ctx ConsoleContext, svcb *network
return errors.Newf("no service binding found")
}

if svcb.Spec.Hostname == "" {
return nil
filter := repos.Filter{
fc.AccountName: ctx.AccountName,
fc.ServiceBindingSpecHostname: svcb.Spec.Hostname,
}

if svcb.Spec.ServiceIP == nil {
if svcb.Spec.ServiceIP == nil || svcb.Spec.Hostname == "" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding a comment explaining the rationale for deleting the service binding.

It would be helpful to clarify why we're deleting the service binding when either ServiceIP or Hostname is empty. This would improve code maintainability and make the intention clearer for future developers.

// Delete service binding if ServiceIP or Hostname is empty, as these are required fields
if svcb.Spec.ServiceIP == nil || svcb.Spec.Hostname == "" {
	if err := d.serviceBindingRepo.DeleteOne(ctx, filter); err != nil {
		if !errors.Is(err, repos.ErrNoDocuments) {
			return err
		}
	}
	return nil
}

if _, err := d.serviceBindingRepo.Upsert(ctx, filter, &entities.ServiceBinding{
	ServiceBinding: *svcb,
	AccountName:    ctx.AccountName,
	ClusterName:    opts.ClusterName,

// INFO: it means that service binding has been de-allocated
if err := d.serviceBindingRepo.DeleteOne(ctx, filter); err != nil {
if !errors.Is(err, repos.ErrNoDocuments) {
return err
}
}
return nil
}

if _, err := d.serviceBindingRepo.Upsert(ctx, repos.Filter{
fc.AccountName: ctx.AccountName,
// fc.ClusterName: opts.ClusterName,
// fc.MetadataName: svcb.Name,
fc.ServiceBindingSpecHostname: svcb.Spec.Hostname,
}, &entities.ServiceBinding{
if _, err := d.serviceBindingRepo.Upsert(ctx, filter, &entities.ServiceBinding{
ServiceBinding: *svcb,
AccountName: ctx.AccountName,
ClusterName: opts.ClusterName,
Expand Down
3 changes: 1 addition & 2 deletions apps/console/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"log/slog"
"os"
"strings"
"time"

"github.com/kloudlite/api/pkg/errors"
Expand All @@ -28,7 +27,7 @@ func main() {
flag.BoolVar(&debug, "debug", false, "--debug")
flag.Parse()

logger, err := logging.New(&logging.Options{Name: "console", ShowDebugLog: isDev || strings.ToLower(os.Getenv("LOG_LEVEL")) == "debug"})
logger, err := logging.New(&logging.Options{Name: "console", ShowDebugLog: debug})
if err != nil {
panic(err)
}
Expand Down