Skip to content

Commit ef23179

Browse files
committed
Do not download instance types if cache loadable
and environment INCUS_SKIP_INSTANCE_TYPES set to true, because most enterprise environment has no internet access, so they can put instance types in cache and set `INCUS_SKIP_INSTANCE_TYPES = true`. Signed-off-by: JUN JIE NAN <[email protected]>
1 parent 36701b9 commit ef23179

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cmd/incusd/instance_instance_types.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,18 @@ func instanceRefreshTypes(ctx context.Context, s *state.State) error {
153153

154154
// Set an initial value from the cache
155155
if instanceTypes == nil {
156-
_ = instanceLoadCache()
156+
instanceTypes = map[string]map[string]*instanceType{}
157+
}
158+
159+
if len(instanceTypes) == 0 {
160+
err := instanceLoadCache()
161+
if err != nil {
162+
logger.Error("instance load cache error", logger.Ctx{"err": err})
163+
}
164+
}
165+
166+
if len(instanceTypes) != 0 && util.IsTrue(os.Getenv("INCUS_SKIP_INSTANCE_TYPES")) {
167+
return nil
157168
}
158169

159170
// Get the list of instance type sources

doc/environment.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ Name | Description
4040
`INCUS_SECURITY_APPARMOR` | If set to `false`, forces AppArmor off
4141
`INCUS_UI` | Path to the web UI to serve through the web server
4242
`INCUS_USBIDS_PATH` | Path to the hwdata `usb.ids` file
43+
`INCUS_SKIP_INSTANCE_TYPES` | Skip loadable instance types downloading if set it to `true`

0 commit comments

Comments
 (0)