Skip to content

Commit 49d3ab0

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

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-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.IsFalse(os.Getenv("INCUS_DOWNLOAD_INSTANCE_TYPES")) {
167+
return nil
157168
}
158169

159170
// Get the list of instance type sources

0 commit comments

Comments
 (0)