Skip to content

Commit bc46191

Browse files
committed
hack: add marketplace stream to coreos manifest
Updates the generation of the coreos stream manifest, which runs during container building, to merge the contents of the marketplace-rhcos.json file with rhcos.json when creating the coreos stream configmap.
1 parent eace8b4 commit bc46191

File tree

1 file changed

+72
-17
lines changed

1 file changed

+72
-17
lines changed

hack/build-coreos-manifest.go

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,31 @@
77
package main
88

99
import (
10+
"encoding/json"
1011
"fmt"
1112
"os"
1213
"path/filepath"
1314
"strings"
1415

16+
"github.com/coreos/stream-metadata-go/stream"
17+
"github.com/coreos/stream-metadata-go/stream/rhcos"
1518
corev1 "k8s.io/api/core/v1"
1619
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1720
"sigs.k8s.io/yaml"
1821
)
1922

2023
const (
21-
streamRHCOSJSON = "data/data/coreos/rhcos.json"
22-
streamFCOSJSON = "data/data/coreos/fcos.json"
23-
streamSCOSJSON = "data/data/coreos/scos.json"
24-
fcosTAG = "okd"
25-
scosTAG = "scos"
26-
dest = "bin/manifests/coreos-bootimages.yaml"
24+
streamRHCOSJSON = "data/data/coreos/rhcos.json"
25+
streamFCOSJSON = "data/data/coreos/fcos.json"
26+
streamSCOSJSON = "data/data/coreos/scos.json"
27+
streamMarketplaceRHCOSJSON = "data/data/coreos/marketplace-rhcos.json"
28+
fcosTAG = "okd"
29+
scosTAG = "scos"
30+
dest = "bin/manifests/coreos-bootimages.yaml"
2731
)
2832

2933
func run() error {
30-
var streamJSON string
31-
tags, _ := os.LookupEnv("TAGS")
32-
switch {
33-
case strings.Contains(tags, fcosTAG):
34-
streamJSON = streamFCOSJSON
35-
case strings.Contains(tags, scosTAG):
36-
streamJSON = streamSCOSJSON
37-
default:
38-
streamJSON = streamRHCOSJSON
39-
}
40-
bootimages, err := os.ReadFile(streamJSON)
34+
bootimages, err := getBootImages()
4135
if err != nil {
4236
return err
4337
}
@@ -79,6 +73,67 @@ func run() error {
7973
return nil
8074
}
8175

76+
func getBootImages() ([]byte, error) {
77+
var okd bool
78+
var streamJSON string
79+
tags, _ := os.LookupEnv("TAGS")
80+
switch {
81+
case strings.Contains(tags, fcosTAG):
82+
streamJSON = streamFCOSJSON
83+
okd = true
84+
case strings.Contains(tags, scosTAG):
85+
streamJSON = streamSCOSJSON
86+
okd = true
87+
default:
88+
streamJSON = streamRHCOSJSON
89+
}
90+
91+
bootimages, err := os.ReadFile(streamJSON)
92+
if err != nil {
93+
return nil, err
94+
}
95+
96+
if okd {
97+
// okd does not yet have marketplace images, so we are done
98+
return bootimages, nil
99+
}
100+
101+
return mergeMarketplaceStream(bootimages)
102+
}
103+
104+
type marketplaceStream map[string]*rhcos.Marketplace
105+
106+
func mergeMarketplaceStream(streamJSON []byte) ([]byte, error) {
107+
mktStream := marketplaceStream{}
108+
mktJSON, err := os.ReadFile(streamMarketplaceRHCOSJSON)
109+
if err != nil {
110+
return nil, fmt.Errorf("failed to open marketplace file: %w", err)
111+
}
112+
if err := json.Unmarshal(mktJSON, &mktStream); err != nil {
113+
return nil, fmt.Errorf("failed to unmarshal market stream: %w", err)
114+
}
115+
116+
stream := stream.Stream{}
117+
if err := json.Unmarshal(streamJSON, &stream); err != nil {
118+
return nil, fmt.Errorf("failed to unmarshal boot image stream: %w", err)
119+
}
120+
121+
for name, arch := range stream.Architectures {
122+
if mkt, ok := mktStream[name]; ok {
123+
if arch.RHELCoreOSExtensions == nil {
124+
arch.RHELCoreOSExtensions = &rhcos.Extensions{}
125+
}
126+
arch.RHELCoreOSExtensions.Marketplace = mkt
127+
}
128+
}
129+
130+
bootImgs, err := json.Marshal(stream)
131+
if err != nil {
132+
return nil, fmt.Errorf("failed to marshal merged boot image stream: %w", err)
133+
}
134+
return bootImgs, nil
135+
}
136+
82137
func main() {
83138
if err := run(); err != nil {
84139
fmt.Fprintf(os.Stderr, "%s\n", err)

0 commit comments

Comments
 (0)