Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily pull machine images from side repo #13220

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion pkg/machine/fcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

"github.com/coreos/stream-metadata-go/fedoracoreos"
"github.com/coreos/stream-metadata-go/release"
"github.com/coreos/stream-metadata-go/stream"
"github.com/pkg/errors"

Expand All @@ -28,6 +29,14 @@ var (
Format string = "qcow2.xz"
)

const (
// Used for testing the latest podman in fcos
// special builds
podmanTesting = "podman-testing"
PodmanTestingHost = "fedorapeople.org"
PodmanTestingURL = "groups/podman/testing"
)

type FcosDownload struct {
Download
}
Expand Down Expand Up @@ -111,14 +120,39 @@ func getFcosArch() string {
return arch
}

// getStreamURL is a wrapper for the fcos.GetStream URL
// so that we can inject a special stream and url for
// testing podman before it merges into fcos builds
func getStreamURL(streamType string) url2.URL {
// For the podmanTesting stream type, we point to
// a custom url on fedorapeople.org
if streamType == podmanTesting {
return url2.URL{
Scheme: "https",
Host: PodmanTestingHost,
Path: fmt.Sprintf("%s/%s.json", PodmanTestingURL, "podman4"),
}
}
return fedoracoreos.GetStreamURL(streamType)
}

// This should get Exported and stay put as it will apply to all fcos downloads
// getFCOS parses fedoraCoreOS's stream and returns the image download URL and the release version
func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
var (
fcosstable stream.Stream
altMeta release.Release
streamType string
)

// This is being hard set to testing. Once podman4 is in the
// fcos trees, we should remove it and re-release at least on
// macs.
imageStream = "podman-testing"

switch imageStream {
case "podman-testing":
streamType = "podman-testing"
case "testing", "":
streamType = fedoracoreos.StreamTesting
case "next":
Expand All @@ -128,7 +162,7 @@ func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
default:
return nil, errors.Errorf("invalid stream %s: valid streams are `testing` and `stable`", imageStream)
}
streamurl := fedoracoreos.GetStreamURL(streamType)
streamurl := getStreamURL(streamType)
resp, err := http.Get(streamurl.String())
if err != nil {
return nil, err
Expand All @@ -142,6 +176,27 @@ func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
logrus.Error(err)
}
}()
if imageStream == podmanTesting {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the need for this, the data we're getting should be...oh no, argh. Right, there's 3 levels of JSON (cosa meta, release json, and stream JSON), and we actually only got the second. I'm so sorry, I messed that up.

Well, it honestly doesn't matter - what matters is the binary can pull it, if we temporarily uglify this code I don't think it's a big deal.

For general context, Brent and I discussed this and I am firmly of the opinion we on CoreOS side (as well as elsewhere) should aim to ditch all our custom JSON long term in favor of OCI artifacts. For more on that, see coreos/fedora-coreos-tracker#828

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, this is not pretty? I feel pretty.

if err := json.Unmarshal(body, &altMeta); err != nil {
return nil, err
}

arches, ok := altMeta.Architectures[getFcosArch()]
if !ok {
return nil, fmt.Errorf("unable to pull VM image: no targetArch in stream")
}
qcow2, ok := arches.Media.Qemu.Artifacts["qcow2.xz"]
if !ok {
return nil, fmt.Errorf("unable to pull VM image: no qcow2.xz format in stream")
}
disk := qcow2.Disk

return &fcosDownloadInfo{
Location: disk.Location,
Sha256Sum: disk.Sha256,
CompressionType: "xz",
}, nil
}

if err := json.Unmarshal(body, &fcosstable); err != nil {
return nil, err
Expand Down
112 changes: 112 additions & 0 deletions vendor/github.com/coreos/stream-metadata-go/release/release.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading