Skip to content

Commit 56486b4

Browse files
committed
update chart.yaml generation
1 parent c5d99f8 commit 56486b4

File tree

3 files changed

+123
-124
lines changed

3 files changed

+123
-124
lines changed

pkg/charts/chartFile/chart_file.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
const (
1717
minHelmVersion = "3.14"
1818
maxHelmVersion = "3.20"
19-
minKubeVersion = "1.24.0"
2019
maxKubeVersion = "1.35.0"
2120
kubeVersion = ">=1.24.0-0"
2221
apiVersion = "v2"
@@ -136,7 +135,6 @@ func (h *HelmChart) setDefaultValues() {
136135
h.setAnnotation("trueforge.org/category", defaultCategory, false)
137136
h.setAnnotation("trueforge.org/min_helm_version", minHelmVersion, true)
138137
h.setAnnotation("trueforge.org/max_helm_version", maxHelmVersion, true)
139-
h.setAnnotation("trueforge.org/min_kubernetes_version", minKubeVersion, true)
140138
h.setAnnotation("trueforge.org/max_kubernetes_version", maxKubeVersion, true)
141139
h.setAnnotation("artifacthub.io/links", supportUrl, true)
142140

pkg/charts/chartFile/updater.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func updateSources(chart *HelmChart, train string, imageLinks []string) error {
159159
!strings.HasPrefix(source, "https://fleet.linuxserver") &&
160160
!strings.HasPrefix(source, "https://mcr.microsoft") &&
161161
!strings.HasPrefix(source, "https://cr.hotio.dev") &&
162+
!strings.HasPrefix(source, "https://github.com/trueforge-org") &&
162163
!strings.HasPrefix(source, "https://github.com/truecharts") &&
163164
!strings.HasPrefix(source, "https://gallery.ecr.aws") &&
164165
!strings.HasPrefix(source, "https://gcr") &&

pkg/charts/image/image.go

Lines changed: 122 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,146 @@
11
package image
22

33
import (
4-
"fmt"
5-
"regexp"
6-
"strings"
7-
8-
"github.com/knadh/koanf/parsers/yaml"
9-
"github.com/knadh/koanf/providers/file"
10-
"github.com/knadh/koanf/v2"
11-
"github.com/rs/zerolog/log"
4+
"fmt"
5+
"regexp"
6+
"strings"
7+
8+
"github.com/knadh/koanf/parsers/yaml"
9+
"github.com/knadh/koanf/providers/file"
10+
"github.com/knadh/koanf/v2"
11+
"github.com/rs/zerolog/log"
1212
)
1313

1414
// Images represents the structure of values.yaml.
1515
type Images struct {
16-
ImagesMap map[string]ImageDetails
17-
K *koanf.Koanf
16+
ImagesMap map[string]ImageDetails
17+
K *koanf.Koanf
1818
}
1919

2020
// ImageDetails represents details for each image.
2121
type ImageDetails struct {
22-
Repository string `yaml:"repository"`
23-
Tag string `yaml:"tag"`
24-
Version string
25-
Link string
26-
// Add other fields as needed
22+
Repository string `yaml:"repository"`
23+
Tag string `yaml:"tag"`
24+
Version string
25+
Link string
26+
// Add other fields as needed
2727
}
2828

2929
var imageRegex = regexp.MustCompile(`^image|[a-zA-Z0-9]+Image$`)
3030

3131
func (i *Images) LoadValuesFile(filename string) error {
32-
// Initialize koanf instance
33-
i.K = koanf.New(".")
34-
35-
// Load YAML file using koanf
36-
if err := i.K.Load(file.Provider(filename), yaml.Parser()); err != nil {
37-
return err
38-
}
39-
40-
// List only root-level keys that match the criteria
41-
keys := getFilteredRootLevelKeys(i.K)
42-
i.ImagesMap = make(map[string]ImageDetails)
43-
for _, key := range keys {
44-
// Extract relevant fields from the loaded configuration
45-
var img ImageDetails
46-
if err := i.K.Unmarshal(key, &img); err != nil {
47-
return err
48-
}
49-
50-
// Set the Link field based on the repository
51-
img.Link = constructLink(img.Repository)
52-
53-
// Set the Version field based on the tag
54-
version, err := CleanTag(img.Tag)
55-
if err != nil {
56-
log.Error().Err(err).Msg("❌ Failed to clean tag")
57-
}
58-
59-
img.Version = version
60-
61-
// Save the extracted values to the struct
62-
i.ImagesMap[key] = img
63-
}
64-
65-
return nil
32+
// Initialize koanf instance
33+
i.K = koanf.New(".")
34+
35+
// Load YAML file using koanf
36+
if err := i.K.Load(file.Provider(filename), yaml.Parser()); err != nil {
37+
return err
38+
}
39+
40+
// List only root-level keys that match the criteria
41+
keys := getFilteredRootLevelKeys(i.K)
42+
i.ImagesMap = make(map[string]ImageDetails)
43+
for _, key := range keys {
44+
// Extract relevant fields from the loaded configuration
45+
var img ImageDetails
46+
if err := i.K.Unmarshal(key, &img); err != nil {
47+
return err
48+
}
49+
50+
// Set the Link field based on the repository
51+
img.Link = constructLink(img.Repository)
52+
53+
// Set the Version field based on the tag
54+
version, err := CleanTag(img.Tag)
55+
if err != nil {
56+
log.Error().Err(err).Msg("❌ Failed to clean tag")
57+
}
58+
59+
img.Version = version
60+
61+
// Save the extracted values to the struct
62+
i.ImagesMap[key] = img
63+
}
64+
65+
return nil
6666
}
6767

6868
func getFilteredRootLevelKeys(k *koanf.Koanf) []string {
69-
filteredKeys := []string{}
70-
71-
// k.Raw() returns a map[string]interface{} with all the keys and their values
72-
// This means the keys will only be the root-level keys, we can drill into the
73-
// values later if we want the nested keys.
74-
for key := range k.Raw() {
75-
if key == "imageSelector" {
76-
log.Error().Msg("❌ Found [imageSelector] in top level keys, this is not supported.")
77-
continue
78-
}
79-
// Filter keys that match the regex
80-
if imageRegex.MatchString(key) {
81-
filteredKeys = append(filteredKeys, key)
82-
}
83-
}
84-
85-
return filteredKeys
69+
filteredKeys := []string{}
70+
71+
// k.Raw() returns a map[string]interface{} with all the keys and their values
72+
// This means the keys will only be the root-level keys, we can drill into the
73+
// values later if we want the nested keys.
74+
for key := range k.Raw() {
75+
if key == "imageSelector" {
76+
log.Error().Msg("❌ Found [imageSelector] in top level keys, this is not supported.")
77+
continue
78+
}
79+
// Filter keys that match the regex
80+
if imageRegex.MatchString(key) {
81+
filteredKeys = append(filteredKeys, key)
82+
}
83+
}
84+
85+
return filteredKeys
8686
}
8787

8888
// constructLink constructs a link based on the repository using the logic from the main function.
8989
func constructLink(repository string) string {
90-
prefix := ""
91-
92-
switch {
93-
case strings.HasPrefix(repository, "lscr.io/linuxserver/"):
94-
prefix = "https://fleet.linuxserver.io/image?name="
95-
repository = strings.TrimPrefix(repository, "lscr.io/")
96-
case strings.HasPrefix(repository, "oci.trueforge.org/tccr/"):
97-
prefix = "https://github.com/truecharts/containers/tree/master/apps/"
98-
repository = strings.TrimPrefix(repository, "oci.trueforge.org/tccr/")
99-
case strings.HasPrefix(repository, "mcr.microsoft.com/"):
100-
prefix = "https://mcr.microsoft.com/en-us/product/"
101-
repository = strings.TrimPrefix(repository, "mcr.microsoft.com/")
102-
case strings.HasPrefix(repository, "public.ecr.aws/"):
103-
prefix = "https://gallery.ecr.aws/"
104-
repository = strings.TrimPrefix(repository, "public.ecr.aws/")
105-
case strings.HasPrefix(repository, "ghcr.io/"):
106-
prefix = "https://"
107-
case strings.HasPrefix(repository, "quay.io/"):
108-
prefix = "https://"
109-
case strings.HasPrefix(repository, "gcr.io/"):
110-
prefix = "https://"
111-
case strings.Contains(repository, ".azurecr.io/"):
112-
reg := fmt.Sprintf(`%s.azurecr.io/`, strings.Split(repository, ".")[0])
113-
prefix = fmt.Sprintf("https://%s", reg)
114-
repository = strings.TrimPrefix(repository, reg)
115-
case strings.Contains(repository, ".ocir.io/"):
116-
prefix = ""
117-
default:
118-
// Docker Hub or unknown registry
119-
prefix = "https://hub.docker.com/r/"
120-
repository = strings.TrimPrefix(repository, "docker.io/")
121-
repository = strings.TrimPrefix(repository, "index.docker.io/")
122-
repository = strings.TrimPrefix(repository, "registry-1.docker.io/")
123-
repository = strings.TrimPrefix(repository, "registry.hub.docker.com/")
124-
125-
// Check for Docker Official Image
126-
if strings.Count(repository, "/") == 0 || strings.HasPrefix(repository, "library/") {
127-
prefix = "https://hub.docker.com/_/"
128-
repository = strings.TrimPrefix(repository, "library/")
129-
}
130-
131-
// Avoid creating a bad link if the image name has more than 1 slash
132-
slashes := strings.Count(repository, "/")
133-
if slashes > 1 {
134-
prefix = ""
135-
log.Warn().Msgf("WARNING: Could not determine source repository url for [%s]", repository)
136-
}
137-
}
138-
139-
if prefix == "" {
140-
log.Warn().Msgf("WARNING: Could not determine source repository url for [%s]", repository)
141-
return ""
142-
}
143-
144-
containerURL := fmt.Sprintf("%s%s", prefix, repository)
145-
return containerURL
90+
prefix := ""
91+
92+
switch {
93+
case strings.HasPrefix(repository, "lscr.io/linuxserver/"):
94+
prefix = "https://fleet.linuxserver.io/image?name="
95+
repository = strings.TrimPrefix(repository, "lscr.io/")
96+
case strings.HasPrefix(repository, "oci.trueforge.org/containerforge/"):
97+
prefix = "https://github.com/trueforge-org/containers/tree/main/apps/"
98+
repository = strings.TrimPrefix(repository, "oci.trueforge.org/tccr/")
99+
case strings.HasPrefix(repository, "mcr.microsoft.com/"):
100+
prefix = "https://mcr.microsoft.com/en-us/product/"
101+
repository = strings.TrimPrefix(repository, "mcr.microsoft.com/")
102+
case strings.HasPrefix(repository, "public.ecr.aws/"):
103+
prefix = "https://gallery.ecr.aws/"
104+
repository = strings.TrimPrefix(repository, "public.ecr.aws/")
105+
case strings.HasPrefix(repository, "ghcr.io/"):
106+
prefix = "https://"
107+
case strings.HasPrefix(repository, "quay.io/"):
108+
prefix = "https://"
109+
case strings.HasPrefix(repository, "gcr.io/"):
110+
prefix = "https://"
111+
case strings.Contains(repository, ".azurecr.io/"):
112+
reg := fmt.Sprintf(`%s.azurecr.io/`, strings.Split(repository, ".")[0])
113+
prefix = fmt.Sprintf("https://%s", reg)
114+
repository = strings.TrimPrefix(repository, reg)
115+
case strings.Contains(repository, ".ocir.io/"):
116+
prefix = ""
117+
default:
118+
// Docker Hub or unknown registry
119+
prefix = "https://hub.docker.com/r/"
120+
repository = strings.TrimPrefix(repository, "docker.io/")
121+
repository = strings.TrimPrefix(repository, "index.docker.io/")
122+
repository = strings.TrimPrefix(repository, "registry-1.docker.io/")
123+
repository = strings.TrimPrefix(repository, "registry.hub.docker.com/")
124+
125+
// Check for Docker Official Image
126+
if strings.Count(repository, "/") == 0 || strings.HasPrefix(repository, "library/") {
127+
prefix = "https://hub.docker.com/_/"
128+
repository = strings.TrimPrefix(repository, "library/")
129+
}
130+
131+
// Avoid creating a bad link if the image name has more than 1 slash
132+
slashes := strings.Count(repository, "/")
133+
if slashes > 1 {
134+
prefix = ""
135+
log.Warn().Msgf("WARNING: Could not determine source repository url for [%s]", repository)
136+
}
137+
}
138+
139+
if prefix == "" {
140+
log.Warn().Msgf("WARNING: Could not determine source repository url for [%s]", repository)
141+
return ""
142+
}
143+
144+
containerURL := fmt.Sprintf("%s%s", prefix, repository)
145+
return containerURL
146146
}

0 commit comments

Comments
 (0)