Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for connection to cluster manager (POC, pending spec) #630

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

edlerd
Copy link

@edlerd edlerd commented Feb 10, 2025

Done

  • extend database with remotes and remote-configuration tables
  • add API endpoints to configure, show and delete cluster manager configuration
  • add CLI commands for the new API endpoints
  • add go routine that collects info from LXD and regularly sends it to cluster manager

Draft status, as below items are still unclear:

  • align on the cli command structure
  • align on the hooking of the go routine to send regular updates
  • create and distribute client certs on cluster manager configuration
  • find a way to store the server cert, this depends on:
  • generate access functions for the remote-configurations table
  • retry logic for sending updates to cluster manager
  • make the sending of updates resilient to timeouts or downtimes


// the server certificate is not signed by a CA, so we need to skip verification
// we do validate it by checking the fingerprint with VerifyPeerCertificate
tlsConfig.InsecureSkipVerify = true

Check failure

Code scanning / CodeQL

Disabled TLS certificate check High

InsecureSkipVerify should not be used in production code.
"database/sql"
"errors"
"fmt"
"github.com/canonical/microcluster/v2/cluster"
Copy link
Author

Choose a reason for hiding this comment

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

Manually fixed this one import. Any hints how to make update-schema create the file with the right import directly?

//go:generate mapper method -i -d github.com/canonical/microcluster/v2/cluster -e Remote Create table=remotes
//go:generate mapper method -i -d github.com/canonical/microcluster/v2/cluster -e Remote Update table=remotes
//go:generate mapper method -i -d github.com/canonical/microcluster/v2/cluster -e Remote DeleteOne-by-Name table=remotes

Copy link
Author

Choose a reason for hiding this comment

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

I tried to also create queries for the RemoteConfigTable, but adding

//go:generate mapper stmt -d github.com/canonical/microcluster/v2/cluster -e RemoteConfigTable objects table=remotes_config

here causes a segfaul in make update-schema:

go generate ./...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x75a7d3]

goroutine 1 [running]:
github.com/canonical/lxd/lxd/db/generate/db.(*Field).IsScalar(...)
        /home/edlerd/dev/open-source/lxd/lxd/db/generate/db/mapping.go:275
github.com/canonical/lxd/lxd/db/generate/db.(*Field).OrderBy(0x0, 0xc0000cf4a0, {0x7ffc38407a4e, 0xe})
        /home/edlerd/dev/open-source/lxd/lxd/db/generate/db/mapping.go:363 +0x133
github.com/canonical/lxd/lxd/db/generate/db.(*Stmt).objects(0xc0002e7040, 0xc0000b29f0)
        /home/edlerd/dev/open-source/lxd/lxd/db/generate/db/stmt.go:143 +0x530
github.com/canonical/lxd/lxd/db/generate/db.(*Stmt).Generate(0xc0002e7040, 0xc0000b29f0)
        /home/edlerd/dev/open-source/lxd/lxd/db/generate/db/stmt.go:84 +0x165
github.com/canonical/lxd/lxd/db/generate/file.Append({0x7ffc38407a2e?, 0x2c?}, {0x7ffc384079e4, 0x11}, {0x9edfe8, 0xc0002e7040}, 0x40?)
        /home/edlerd/dev/open-source/lxd/lxd/db/generate/file/write.go:85 +0xf4
main.newDbMapperStmt.func1(0xc000150400?, {0xc000142d80?, 0x4?, 0x90caea?})
        /home/edlerd/dev/open-source/lxd/lxd/db/generate/db.go:110 +0x106
github.com/spf13/cobra.(*Command).execute(0xc00019ef08, {0xc000142d00, 0x8, 0x8})
        /home/edlerd/go/pkg/mod/github.com/spf13/[email protected]/command.go:985 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc00019e008)
        /home/edlerd/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        /home/edlerd/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041
main.main()
        /home/edlerd/dev/open-source/lxd/lxd/db/generate/main.go:9 +0x19
database/remotes_table.go:21: running "lxd-generate": exit status 2
make: *** [Makefile:91: update-schema] Error 1

Comment on lines 236 to 241
// todo: is this the right way to trigger the update?
go func() {
api.SendClusterManagerStatusMessageTask(s, state)
time.Sleep(30 * time.Second)
}()

Copy link
Author

Choose a reason for hiding this comment

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

Should this be done with a different approach, or is this OK here?

@edlerd edlerd force-pushed the cluster-manager branch 9 times, most recently from d70c2b4 to a613ccf Compare February 10, 2025 22:39
@edlerd edlerd changed the title feat(cluster-manager) add support for connection to cluster manager Add support for connection to cluster manager (POC, pending spec) Feb 11, 2025
@edlerd edlerd force-pushed the cluster-manager branch 6 times, most recently from 2aae33b to 4b82a73 Compare February 11, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant