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 an api endpoint to get mon addresses #474

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ jobs:
cat /var/snap/microceph/current/conf/ceph.conf
fgrep -q "[${MON_IP}]" /var/snap/microceph/current/conf/ceph.conf

- name: API Testing
run: |
~/actionutils.sh install_hurl
~/actionutils.sh hurl test/hurl/services-mon.hurl

multi-node-tests:
name: Multi node testing
runs-on: ubuntu-22.04
Expand Down
16 changes: 16 additions & 0 deletions microceph/api/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func cmdServicesGet(s state.State, r *http.Request) response.Response {
// Service endpoints.
var monServiceCmd = rest.Endpoint{
Path: "services/mon",
Get: rest.EndpointAction{Handler: cmdMonGet, ProxyTarget: true},
Put: rest.EndpointAction{Handler: cmdEnableServicePut, ProxyTarget: true},
Delete: rest.EndpointAction{Handler: cmdDeleteService, ProxyTarget: true},
}
Expand All @@ -60,6 +61,21 @@ var rbdMirroServiceCmd = rest.Endpoint{
Delete: rest.EndpointAction{Handler: cmdDeleteService, ProxyTarget: true},
}

// cmdMonGet returns the mon service status.
func cmdMonGet(s state.State, r *http.Request) response.Response {

// fetch monitor addresses
monitors, err := ceph.GetMonitorAddresses(r.Context(), interfaces.CephState{State: s})
if err != nil {
return response.InternalError(err)
}

monStatus := types.MonitorStatus{Addresses: monitors}

return response.SyncResponse(true, monStatus)

}

func cmdEnableServicePut(s state.State, r *http.Request) response.Response {
var payload types.EnableService

Expand Down
6 changes: 6 additions & 0 deletions microceph/api/types/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ type RGWService struct {
Port int `json:"port" yaml:"port"`
Enabled bool `json:"enabled" yaml:"enabled"`
}

// MonitorStatus holds the status of all monitors
// for now, this is just the addresses of the monitors
type MonitorStatus struct {
Addresses []string `json:"addresses" yaml:"addresses"`
}
27 changes: 24 additions & 3 deletions microceph/ceph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func UpdateConfig(ctx context.Context, s interfaces.StateInterface) error {
// REF: https://docs.ceph.com/en/quincy/rados/configuration/network-config-ref/#ceph-daemons
// The mon host configuration option only needs to be sufficiently up to date such that a
// client can reach one monitor that is currently online.
monitorAddresses := getMonitorAddresses(config)
monitorAddresses := getMonitorsFromConfig(config)

// backward compat: if no mon hosts found, get them from the node addresses but don't
// insert into db, as the join logic will take care of that.
Expand Down Expand Up @@ -435,8 +435,29 @@ func GetConfigDb(ctx context.Context, s interfaces.StateInterface) (map[string]s
return config, nil
}

// getMonitorAddresses scans a provided config key/value map and returns a list of mon hosts found.
func getMonitorAddresses(configs map[string]string) []string {
// GetMonitorAddresses retrieves the monitor addresses from the database.
func GetMonitorAddresses(ctx context.Context, s interfaces.StateInterface) ([]string, error) {
config, err := GetConfigDb(ctx, s)
if err != nil {
return nil, fmt.Errorf("failed to get config db: %w", err)
}

monitorAddresses := getMonitorsFromConfig(config)

if len(monitorAddresses) == 0 {
monitorAddresses, err = backwardCompatMonitors(ctx, s)
if err != nil {
return nil, fmt.Errorf("failed to get monitor addresses: %w", err)
}
}

// Ensure that IPv6 addresses have square brackets around them (if IPv6 is used).
monitorAddresses = formatIPv6(monitorAddresses)
return monitorAddresses, nil
}

// getMonitorsFromConfig scans a provided config key/value map and returns a list of mon hosts found.
func getMonitorsFromConfig(configs map[string]string) []string {
monHosts := []string{}
for k, v := range configs {
if strings.Contains(k, "mon.host.") {
Expand Down
2 changes: 1 addition & 1 deletion microceph/ceph/services_placement_rgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (rgw *RgwServicePlacement) ServiceInit(ctx context.Context, s interfaces.St
return fmt.Errorf("failed to get config db: %w", err)
}

return EnableRGW(s, rgw.Port, rgw.SSLPort, rgw.SSLCertificate, rgw.SSLPrivateKey, getMonitorAddresses(config))
return EnableRGW(s, rgw.Port, rgw.SSLPort, rgw.SSLCertificate, rgw.SSLPrivateKey, getMonitorsFromConfig(config))
}

func (rgw *RgwServicePlacement) PostPlacementCheck(s interfaces.StateInterface) error {
Expand Down
4 changes: 4 additions & 0 deletions tests/hurl/services-mon.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GET http://localhost/1.0/services/mon
HTTP 200
[Asserts]
jsonpath "$.metadata.addresses" count == 1
11 changes: 11 additions & 0 deletions tests/scripts/actionutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ function install_store() {
done
}

function install_hurl() {
VERSION=5.0.1
downloadurl="https://github.com/Orange-OpenSource/hurl/releases/download/$VERSION/hurl_${VERSION}_amd64.deb"
curl --location --remote-name $downloadurl
sudo dpkg -i ./hurl_${VERSION}_amd64.deb
}

function hurl() {
hurl --unix-socket --test /var/snap/microceph/common/state/control.socket "$@"
}

function upgrade_multinode() {
# Refresh to local version, checking health
for container in node-wrk0 node-wrk1 node-wrk2 node-wrk3 ; do
Expand Down
Loading