Skip to content

Commit ca94f9f

Browse files
authored
Merge pull request #1747 from stgraber/main
Cleanup internal API endpoints
2 parents ddb5690 + 7244047 commit ca94f9f

File tree

6 files changed

+82
-76
lines changed

6 files changed

+82
-76
lines changed

cmd/incusd/api_cluster.go

-30
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,6 @@ var clusterNodeStateCmd = APIEndpoint{
7979
Post: APIEndpointAction{Handler: clusterNodeStatePost, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
8080
}
8181

82-
var internalClusterAcceptCmd = APIEndpoint{
83-
Path: "cluster/accept",
84-
85-
Post: APIEndpointAction{Handler: internalClusterPostAccept, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
86-
}
87-
88-
var internalClusterRebalanceCmd = APIEndpoint{
89-
Path: "cluster/rebalance",
90-
91-
Post: APIEndpointAction{Handler: internalClusterPostRebalance, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
92-
}
93-
94-
var internalClusterAssignCmd = APIEndpoint{
95-
Path: "cluster/assign",
96-
97-
Post: APIEndpointAction{Handler: internalClusterPostAssign, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
98-
}
99-
100-
var internalClusterHandoverCmd = APIEndpoint{
101-
Path: "cluster/handover",
102-
103-
Post: APIEndpointAction{Handler: internalClusterPostHandover, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
104-
}
105-
106-
var internalClusterRaftNodeCmd = APIEndpoint{
107-
Path: "cluster/raft-node/{address}",
108-
109-
Delete: APIEndpointAction{Handler: internalClusterRaftNodeDelete, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
110-
}
111-
11282
// swagger:operation GET /1.0/cluster cluster cluster_get
11383
//
11484
// Get the cluster configuration

cmd/incusd/api_internal.go

+67-31
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,71 @@ var apiInternal = []APIEndpoint{
6969
internalWarningCreateCmd,
7070
}
7171

72+
// Daemon management internal commands.
73+
var internalReadyCmd = APIEndpoint{
74+
Path: "ready",
75+
76+
Get: APIEndpointAction{Handler: internalWaitReady, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
77+
}
78+
7279
var internalShutdownCmd = APIEndpoint{
7380
Path: "shutdown",
7481

7582
Put: APIEndpointAction{Handler: internalShutdown, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
7683
}
7784

78-
var internalReadyCmd = APIEndpoint{
79-
Path: "ready",
85+
// Internal managemnt traffic.
86+
var internalImageOptimizeCmd = APIEndpoint{
87+
Path: "image-optimize",
8088

81-
Get: APIEndpointAction{Handler: internalWaitReady, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
89+
Post: APIEndpointAction{Handler: internalOptimizeImage, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
90+
}
91+
92+
var internalRebalanceLoadCmd = APIEndpoint{
93+
Path: "rebalance",
94+
95+
Get: APIEndpointAction{Handler: internalRebalanceLoad, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
96+
}
97+
98+
var internalSQLCmd = APIEndpoint{
99+
Path: "sql",
100+
101+
Get: APIEndpointAction{Handler: internalSQLGet, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
102+
Post: APIEndpointAction{Handler: internalSQLPost, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
103+
}
104+
105+
// Internal cluster traffic.
106+
var internalClusterAcceptCmd = APIEndpoint{
107+
Path: "cluster/accept",
108+
109+
Post: APIEndpointAction{Handler: internalClusterPostAccept, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
110+
}
111+
112+
var internalClusterAssignCmd = APIEndpoint{
113+
Path: "cluster/assign",
114+
115+
Post: APIEndpointAction{Handler: internalClusterPostAssign, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
116+
}
117+
118+
var internalClusterHandoverCmd = APIEndpoint{
119+
Path: "cluster/handover",
120+
121+
Post: APIEndpointAction{Handler: internalClusterPostHandover, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
82122
}
83123

124+
var internalClusterRaftNodeCmd = APIEndpoint{
125+
Path: "cluster/raft-node/{address}",
126+
127+
Delete: APIEndpointAction{Handler: internalClusterRaftNodeDelete, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
128+
}
129+
130+
var internalClusterRebalanceCmd = APIEndpoint{
131+
Path: "cluster/rebalance",
132+
133+
Post: APIEndpointAction{Handler: internalClusterPostRebalance, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
134+
}
135+
136+
// Container hooks.
84137
var internalContainerOnStartCmd = APIEndpoint{
85138
Path: "containers/{instanceRef}/onstart",
86139

@@ -99,61 +152,44 @@ var internalContainerOnStopCmd = APIEndpoint{
99152
Get: APIEndpointAction{Handler: internalContainerOnStop, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
100153
}
101154

155+
// Virtual machine hooks.
102156
var internalVirtualMachineOnResizeCmd = APIEndpoint{
103157
Path: "virtual-machines/{instanceRef}/onresize",
104158

105159
Get: APIEndpointAction{Handler: internalVirtualMachineOnResize, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
106160
}
107161

108-
var internalSQLCmd = APIEndpoint{
109-
Path: "sql",
162+
// Debugging.
163+
var internalBGPStateCmd = APIEndpoint{
164+
Path: "debug/bgp",
110165

111-
Get: APIEndpointAction{Handler: internalSQLGet, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
112-
Post: APIEndpointAction{Handler: internalSQLPost, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
166+
Get: APIEndpointAction{Handler: internalBGPState, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
113167
}
114168

115169
var internalGarbageCollectorCmd = APIEndpoint{
116-
Path: "gc",
170+
Path: "debug/gc",
117171

118172
Get: APIEndpointAction{Handler: internalGC, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
119173
}
120174

121-
var internalRAFTSnapshotCmd = APIEndpoint{
122-
Path: "raft-snapshot",
123-
124-
Get: APIEndpointAction{Handler: internalRAFTSnapshot, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
125-
}
126-
127175
var internalImageRefreshCmd = APIEndpoint{
128-
Path: "testing/image-refresh",
176+
Path: "debug/image-refresh",
129177

130178
Get: APIEndpointAction{Handler: internalRefreshImage, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
131179
}
132180

133-
var internalImageOptimizeCmd = APIEndpoint{
134-
Path: "image-optimize",
181+
var internalRAFTSnapshotCmd = APIEndpoint{
182+
Path: "debug/raft-snapshot",
135183

136-
Post: APIEndpointAction{Handler: internalOptimizeImage, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
184+
Get: APIEndpointAction{Handler: internalRAFTSnapshot, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
137185
}
138186

139187
var internalWarningCreateCmd = APIEndpoint{
140-
Path: "testing/warnings",
188+
Path: "debug/warnings",
141189

142190
Post: APIEndpointAction{Handler: internalCreateWarning, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
143191
}
144192

145-
var internalBGPStateCmd = APIEndpoint{
146-
Path: "testing/bgp",
147-
148-
Get: APIEndpointAction{Handler: internalBGPState, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
149-
}
150-
151-
var internalRebalanceLoadCmd = APIEndpoint{
152-
Path: "rebalance",
153-
154-
Get: APIEndpointAction{Handler: internalRebalanceLoad, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
155-
}
156-
157193
type internalImageOptimizePost struct {
158194
Image api.Image `json:"image" yaml:"image"`
159195
Pool string `json:"pool" yaml:"pool"`

test/suites/clustering.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,7 @@ test_clustering_image_refresh() {
27822782

27832783
# Trigger image refresh on all nodes
27842784
for incus_dir in "${INCUS_ONE_DIR}" "${INCUS_TWO_DIR}" "${INCUS_THREE_DIR}"; do
2785-
INCUS_DIR="${incus_dir}" incus query /internal/testing/image-refresh &
2785+
INCUS_DIR="${incus_dir}" incus query /internal/debug/image-refresh &
27862786
pids="$! ${pids}"
27872787
done
27882788

@@ -2820,7 +2820,7 @@ test_clustering_image_refresh() {
28202820
# Trigger image refresh on all nodes. This shouldn't do anything as the image
28212821
# is already up-to-date.
28222822
for incus_dir in "${INCUS_ONE_DIR}" "${INCUS_TWO_DIR}" "${INCUS_THREE_DIR}"; do
2823-
INCUS_DIR="${incus_dir}" incus query /internal/testing/image-refresh &
2823+
INCUS_DIR="${incus_dir}" incus query /internal/debug/image-refresh &
28242824
pids="$! ${pids}"
28252825
done
28262826

@@ -2846,7 +2846,7 @@ test_clustering_image_refresh() {
28462846

28472847
# Trigger image refresh on all nodes
28482848
for incus_dir in "${INCUS_ONE_DIR}" "${INCUS_TWO_DIR}" "${INCUS_THREE_DIR}"; do
2849-
INCUS_DIR="${incus_dir}" incus query /internal/testing/image-refresh &
2849+
INCUS_DIR="${incus_dir}" incus query /internal/debug/image-refresh &
28502850
pids="$! ${pids}"
28512851
done
28522852

test/suites/fdleak.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_fdleak() {
2222
done
2323

2424
incus list
25-
incus query /internal/gc
25+
incus query /internal/debug/gc
2626

2727
exit 0
2828
)

test/suites/network_forward.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ test_network_forward() {
3030
incus network forward show "${netName}" 198.51.100.1 | grep -q -F "description: Test network forward"
3131

3232
# Check forward is exported via BGP prefixes.
33-
incus query /internal/testing/bgp | grep "198.51.100.1/32"
33+
incus query /internal/debug/bgp | grep "198.51.100.1/32"
3434

3535
incus network forward delete "${netName}" 198.51.100.1
3636

3737
# Check deleting network forward removes forward BGP prefix.
38-
! incus query /internal/testing/bgp | grep "198.51.100.1/32" || false
38+
! incus query /internal/debug/bgp | grep "198.51.100.1/32" || false
3939

4040
# Check creating forward with default target creates valid firewall rules.
4141
incus network forward create "${netName}" 198.51.100.1 target_address=192.0.2.2
@@ -140,13 +140,13 @@ test_network_forward() {
140140
fi
141141

142142
# Check forward is exported via BGP prefixes before network delete.
143-
incus query /internal/testing/bgp | grep "198.51.100.1/32"
143+
incus query /internal/debug/bgp | grep "198.51.100.1/32"
144144

145145
# Check deleting the network clears the forward firewall rules.
146146
incus network delete "${netName}"
147147

148148
# Check deleting network removes forward BGP prefix.
149-
! incus query /internal/testing/bgp | grep "198.51.100.1/32" || false
149+
! incus query /internal/debug/bgp | grep "198.51.100.1/32" || false
150150

151151
if [ "$firewallDriver" = "xtables" ]; then
152152
! iptables -w -t nat -S | grep -c "generated for Incus network-forward ${netName}" || false

test/suites/warnings.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ test_warnings() {
33
incus query --wait /1.0/warnings\?recursion=1 | jq -r '.[].uuid' | xargs -n1 incus warning delete
44

55
# Create a global warning (no node and no project)
6-
incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\"}' /internal/testing/warnings
6+
incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\"}' /internal/debug/warnings
77

88
# More valid queries
9-
incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\", \"project\": \"default\"}' /internal/testing/warnings
9+
incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\", \"project\": \"default\"}' /internal/debug/warnings
1010

1111
# Update the last warning. This will not create a new warning.
12-
incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning 2\", \"project\": \"default\"}' /internal/testing/warnings
12+
incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning 2\", \"project\": \"default\"}' /internal/debug/warnings
1313

1414
# There should be two warnings now.
1515
count=$(incus query --wait /1.0/warnings | jq 'length')
@@ -19,21 +19,21 @@ test_warnings() {
1919
[ "${count}" -eq 2 ] || false
2020

2121
# Invalid query (unknown project)
22-
! incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\", \"project\": \"foo\"}' /internal/testing/warnings || false
22+
! incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\", \"project\": \"foo\"}' /internal/debug/warnings || false
2323

2424
# Invalid query (unknown type code)
25-
! incus query --wait -X POST -d '{\"type_code\": 999, \"message\": \"global warning\"}' /internal/testing/warnings || false
25+
! incus query --wait -X POST -d '{\"type_code\": 999, \"message\": \"global warning\"}' /internal/debug/warnings || false
2626

2727
# Both entity type code as entity ID need to be valid otherwise no warning will be created. Note that empty/null values are valid as well.
28-
! incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\", \"entity_type_code\": 0, \"entity_id\": 0}' /internal/testing/warnings || false
28+
! incus query --wait -X POST -d '{\"type_code\": 0, \"message\": \"global warning\", \"entity_type_code\": 0, \"entity_id\": 0}' /internal/debug/warnings || false
2929

3030
ensure_import_testimage
3131

3232
# Get image ID from database instead of assuming it
3333
image_id=$(echo 'select image_id from images_aliases where name="testimage"' | incus admin sql global - | grep -Eo '[[:digit:]]+')
3434

3535
# Create a warning with entity type "image" and entity ID ${image_id} (the imported testimage)
36-
incus query --wait -X POST -d "{\\\"type_code\\\": 0, \\\"message\\\": \\\"global warning\\\", \\\"entity_type_code\\\": 1, \\\"entity_id\\\": ${image_id}}" /internal/testing/warnings
36+
incus query --wait -X POST -d "{\\\"type_code\\\": 0, \\\"message\\\": \\\"global warning\\\", \\\"entity_type_code\\\": 1, \\\"entity_id\\\": ${image_id}}" /internal/debug/warnings
3737

3838
# There should be three warnings now.
3939
count=$(incus warning list --format json | jq 'length')

0 commit comments

Comments
 (0)