mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00
Merge pull request #12862 from matejvasek/fix-info-ep
Add IndexConfigs info to compat /info endpoint
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
"github.com/containers/common/pkg/sysinfo"
|
"github.com/containers/common/pkg/sysinfo"
|
||||||
|
"github.com/containers/image/v5/pkg/sysregistriesv2"
|
||||||
"github.com/containers/podman/v4/libpod"
|
"github.com/containers/podman/v4/libpod"
|
||||||
"github.com/containers/podman/v4/libpod/define"
|
"github.com/containers/podman/v4/libpod/define"
|
||||||
"github.com/containers/podman/v4/pkg/api/handlers"
|
"github.com/containers/podman/v4/pkg/api/handlers"
|
||||||
@ -108,7 +109,7 @@ func GetInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
Log: infoData.Plugins.Log,
|
Log: infoData.Plugins.Log,
|
||||||
},
|
},
|
||||||
ProductLicense: "Apache-2.0",
|
ProductLicense: "Apache-2.0",
|
||||||
RegistryConfig: new(registry.ServiceConfig),
|
RegistryConfig: getServiceConfig(runtime),
|
||||||
RuncCommit: docker.Commit{},
|
RuncCommit: docker.Commit{},
|
||||||
Runtimes: getRuntimes(configInfo),
|
Runtimes: getRuntimes(configInfo),
|
||||||
SecurityOptions: getSecOpts(sysInfo),
|
SecurityOptions: getSecOpts(sysInfo),
|
||||||
@ -133,6 +134,37 @@ func GetInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.WriteResponse(w, http.StatusOK, info)
|
utils.WriteResponse(w, http.StatusOK, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getServiceConfig(runtime *libpod.Runtime) *registry.ServiceConfig {
|
||||||
|
var indexConfs map[string]*registry.IndexInfo
|
||||||
|
|
||||||
|
regs, err := sysregistriesv2.GetRegistries(runtime.SystemContext())
|
||||||
|
if err == nil {
|
||||||
|
indexConfs = make(map[string]*registry.IndexInfo, len(regs))
|
||||||
|
for _, reg := range regs {
|
||||||
|
mirrors := make([]string, len(reg.Mirrors))
|
||||||
|
for i, mirror := range reg.Mirrors {
|
||||||
|
mirrors[i] = mirror.Location
|
||||||
|
}
|
||||||
|
indexConfs[reg.Prefix] = ®istry.IndexInfo{
|
||||||
|
Name: reg.Prefix,
|
||||||
|
Mirrors: mirrors,
|
||||||
|
Secure: !reg.Insecure,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Warnf("failed to get registries configuration: %v", err)
|
||||||
|
indexConfs = make(map[string]*registry.IndexInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ®istry.ServiceConfig{
|
||||||
|
AllowNondistributableArtifactsCIDRs: make([]*registry.NetIPNet, 0),
|
||||||
|
AllowNondistributableArtifactsHostnames: make([]string, 0),
|
||||||
|
InsecureRegistryCIDRs: make([]*registry.NetIPNet, 0),
|
||||||
|
IndexConfigs: indexConfs,
|
||||||
|
Mirrors: make([]string, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getGraphStatus(storeInfo map[string]string) [][2]string {
|
func getGraphStatus(storeInfo map[string]string) [][2]string {
|
||||||
graphStatus := make([][2]string, 0, len(storeInfo))
|
graphStatus := make([][2]string, 0, len(storeInfo))
|
||||||
for k, v := range storeInfo {
|
for k, v := range storeInfo {
|
||||||
|
@ -42,16 +42,19 @@ class Podman(object):
|
|||||||
os.environ["CONTAINERS_REGISTRIES_CONF"] = os.path.join(
|
os.environ["CONTAINERS_REGISTRIES_CONF"] = os.path.join(
|
||||||
self.anchor_directory, "registry.conf"
|
self.anchor_directory, "registry.conf"
|
||||||
)
|
)
|
||||||
p = configparser.ConfigParser()
|
conf = """unqualified-search-registries = ["docker.io", "quay.io"]
|
||||||
p.read_dict(
|
|
||||||
{
|
[[registry]]
|
||||||
"registries.search": {"registries": "['quay.io', 'docker.io']"},
|
location="localhost:5000"
|
||||||
"registries.insecure": {"registries": "[]"},
|
insecure=true
|
||||||
"registries.block": {"registries": "[]"},
|
|
||||||
}
|
[[registry.mirror]]
|
||||||
)
|
location = "mirror.localhost:5000"
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
with open(os.environ["CONTAINERS_REGISTRIES_CONF"], "w") as w:
|
with open(os.environ["CONTAINERS_REGISTRIES_CONF"], "w") as w:
|
||||||
p.write(w)
|
w.write(conf)
|
||||||
|
|
||||||
os.environ["CNI_CONFIG_PATH"] = os.path.join(
|
os.environ["CNI_CONFIG_PATH"] = os.path.join(
|
||||||
self.anchor_directory, "cni", "net.d"
|
self.anchor_directory, "cni", "net.d"
|
||||||
|
@ -54,7 +54,10 @@ class TestSystem(unittest.TestCase):
|
|||||||
return super().tearDownClass()
|
return super().tearDownClass()
|
||||||
|
|
||||||
def test_Info(self):
|
def test_Info(self):
|
||||||
self.assertIsNotNone(self.client.info())
|
info = self.client.info()
|
||||||
|
self.assertIsNotNone(info)
|
||||||
|
self.assertEqual(info["RegistryConfig"]["IndexConfigs"]["localhost:5000"]["Secure"], False)
|
||||||
|
self.assertEqual(info["RegistryConfig"]["IndexConfigs"]["localhost:5000"]["Mirrors"], ["mirror.localhost:5000"])
|
||||||
|
|
||||||
def test_info_container_details(self):
|
def test_info_container_details(self):
|
||||||
info = self.client.info()
|
info = self.client.info()
|
||||||
|
Reference in New Issue
Block a user