-
Notifications
You must be signed in to change notification settings - Fork 22
/
registry.go
156 lines (141 loc) · 4.21 KB
/
registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package common
import (
"strings"
"github.com/sirupsen/logrus"
"kubevirt.io/containerdisks/artifacts/centosstream"
"kubevirt.io/containerdisks/artifacts/fedora"
"kubevirt.io/containerdisks/artifacts/generic"
"kubevirt.io/containerdisks/artifacts/opensuse/leap"
"kubevirt.io/containerdisks/artifacts/opensuse/tumbleweed"
"kubevirt.io/containerdisks/artifacts/ubuntu"
"kubevirt.io/containerdisks/pkg/api"
"kubevirt.io/containerdisks/pkg/common"
"kubevirt.io/containerdisks/pkg/docs"
)
type Entry struct {
Artifacts []api.Artifact
UseForDocs bool
UseForLatest bool
SkipWhenNotFocused bool
}
var staticRegistry = []Entry{
{
Artifacts: []api.Artifact{
centosstream.New("9", "x86_64", &docs.UserData{Username: "cloud-user"}, defaultEnvVariables("u1.medium", "centos.stream9")),
centosstream.New("9", "aarch64", &docs.UserData{Username: "cloud-user"}, defaultEnvVariables("u1.medium", "centos.stream9")),
},
UseForDocs: true,
},
{
Artifacts: []api.Artifact{
ubuntu.New("24.04", "x86_64", defaultEnvVariables("u1.medium", "ubuntu")),
ubuntu.New("24.04", "aarch64", defaultEnvVariables("u1.medium", "ubuntu")),
},
UseForDocs: true,
},
{
Artifacts: []api.Artifact{
ubuntu.New("22.04", "x86_64", defaultEnvVariables("u1.medium", "ubuntu")),
ubuntu.New("22.04", "aarch64", defaultEnvVariables("u1.medium", "ubuntu")),
},
UseForDocs: false,
},
{
Artifacts: []api.Artifact{
ubuntu.New("20.04", "x86_64", defaultEnvVariables("u1.medium", "ubuntu")),
ubuntu.New("20.04", "aarch64", defaultEnvVariables("u1.medium", "ubuntu")),
},
UseForDocs: false,
},
{
Artifacts: []api.Artifact{
tumbleweed.New("x86_64", defaultEnvVariables("u1.medium", "opensuse.tumbleweed")),
},
UseForDocs: true,
},
{
Artifacts: []api.Artifact{
leap.New("x86_64", "15.6", defaultEnvVariables("u1.medium", "opensuse.leap")),
leap.New("aarch64", "15.6", defaultEnvVariables("u1.medium", "opensuse.leap")),
},
UseForDocs: true,
},
{
Artifacts: []api.Artifact{
leap.New("x86_64", "15.5", defaultEnvVariables("u1.medium", "opensuse.leap")),
leap.New("aarch64", "15.5", defaultEnvVariables("u1.medium", "opensuse.leap")),
},
},
// for testing only
{
Artifacts: []api.Artifact{
generic.New(
&api.ArtifactDetails{
SHA256Sum: "cc704ab14342c1c8a8d91b66a7fc611d921c8b8f1aaf4695f9d6463d913fa8d1",
DownloadURL: "https://download.cirros-cloud.net/0.6.1/cirros-0.6.1-x86_64-disk.img",
ImageArchitecture: "amd64",
},
&api.Metadata{
Name: "cirros",
Version: "6.1",
},
),
generic.New(
&api.ArtifactDetails{
SHA256Sum: "db9420c481c11dee17860aa46fb1a3efa05fa4fb152726d6344e24da03cb0ccf",
DownloadURL: "https://download.cirros-cloud.net/0.6.1/cirros-0.6.1-aarch64-disk.img",
ImageArchitecture: "arm64",
},
&api.Metadata{
Name: "cirros",
Version: "6.1",
},
),
},
SkipWhenNotFocused: true,
UseForDocs: false,
},
}
func gatherArtifacts(registry *[]Entry, gatherers []api.ArtifactsGatherer) {
for _, gatherer := range gatherers {
artifacts, err := gatherer.Gather()
if err != nil {
logrus.Warn("Failed to gather artifacts", err)
} else {
for i := range artifacts {
*registry = append(*registry, Entry{
Artifacts: artifacts[i],
UseForDocs: i == 0,
UseForLatest: i == 0,
})
}
}
}
}
func defaultEnvVariables(defaultInstancetype, defaultPreference string) map[string]string {
return map[string]string{
common.DefaultInstancetypeEnv: defaultInstancetype,
common.DefaultPreferenceEnv: defaultPreference,
}
}
func NewRegistry() []Entry {
registry := make([]Entry, len(staticRegistry))
copy(registry, staticRegistry)
gatherers := []api.ArtifactsGatherer{fedora.NewGatherer()}
gatherArtifacts(®istry, gatherers)
return registry
}
func ShouldSkip(focus string, entry *Entry) bool {
if focus == "" {
return entry.SkipWhenNotFocused
}
if len(entry.Artifacts) == 0 {
return true
}
focusSplit := strings.Split(focus, ":")
wildcardFocus := len(focusSplit) == 2 && focusSplit[1] == "*"
if wildcardFocus {
return focusSplit[0] != entry.Artifacts[0].Metadata().Name
}
return focus != entry.Artifacts[0].Metadata().Describe()
}