From 952fc4a6f9b01060d35fdb9e2577e76eeeb83526 Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 14 Sep 2021 09:30:10 -0500 Subject: Use new aarch64 fcos repos Now that aarch64 fcos is an official thing, we no longer need to use the side repo (for lack of a better word). We can now use the same image lookup technique as x86_64. I removed the special lookup, moved the x86_64 lookup to generic arch, and removed the arch specific files that we no longer needed. [NO TESTS NEEDED] Signed-off-by: baude --- pkg/machine/fcos.go | 73 +++++++++++++++++++ pkg/machine/fcos_amd64.go | 78 -------------------- pkg/machine/fcos_arm64.go | 177 ---------------------------------------------- 3 files changed, 73 insertions(+), 255 deletions(-) delete mode 100644 pkg/machine/fcos_amd64.go delete mode 100644 pkg/machine/fcos_arm64.go (limited to 'pkg') diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go index 4ea965b7f..cfcadeb02 100644 --- a/pkg/machine/fcos.go +++ b/pkg/machine/fcos.go @@ -3,12 +3,20 @@ package machine import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" url2 "net/url" "os" "path/filepath" "runtime" "strings" + "github.com/coreos/stream-metadata-go/fedoracoreos" + "github.com/coreos/stream-metadata-go/stream" + "github.com/pkg/errors" + digest "github.com/opencontainers/go-digest" "github.com/sirupsen/logrus" ) @@ -121,3 +129,68 @@ func getFcosArch() string { } return arch } + +// 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 + streamType string + ) + switch imageStream { + case "testing", "": + streamType = fedoracoreos.StreamNext + case "stable": + streamType = fedoracoreos.StreamStable + default: + return nil, errors.Errorf("invalid stream %s: valid streams are `testing` and `stable`", imageStream) + } + streamurl := fedoracoreos.GetStreamURL(streamType) + resp, err := http.Get(streamurl.String()) + if err != nil { + return nil, err + } + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + defer func() { + if err := resp.Body.Close(); err != nil { + logrus.Error(err) + } + }() + + if err := json.Unmarshal(body, &fcosstable); err != nil { + return nil, err + } + arch, ok := fcosstable.Architectures[getFcosArch()] + if !ok { + return nil, fmt.Errorf("unable to pull VM image: no targetArch in stream") + } + artifacts := arch.Artifacts + if artifacts == nil { + return nil, fmt.Errorf("unable to pull VM image: no artifact in stream") + } + qemu, ok := artifacts[artifact] + if !ok { + return nil, fmt.Errorf("unable to pull VM image: no qemu artifact in stream") + } + formats := qemu.Formats + if formats == nil { + return nil, fmt.Errorf("unable to pull VM image: no formats in stream") + } + qcow, ok := formats[Format] + if !ok { + return nil, fmt.Errorf("unable to pull VM image: no qcow2.xz format in stream") + } + disk := qcow.Disk + if disk == nil { + return nil, fmt.Errorf("unable to pull VM image: no disk in stream") + } + return &fcosDownloadInfo{ + Location: disk.Location, + Release: qemu.Release, + Sha256Sum: disk.Sha256, + CompressionType: "xz", + }, nil +} diff --git a/pkg/machine/fcos_amd64.go b/pkg/machine/fcos_amd64.go deleted file mode 100644 index 4e2e86d3e..000000000 --- a/pkg/machine/fcos_amd64.go +++ /dev/null @@ -1,78 +0,0 @@ -package machine - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - - "github.com/coreos/stream-metadata-go/fedoracoreos" - "github.com/coreos/stream-metadata-go/stream" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -// 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 - streamType string - ) - switch imageStream { - case "testing", "": - streamType = fedoracoreos.StreamNext - case "stable": - streamType = fedoracoreos.StreamStable - default: - return nil, errors.Errorf("invalid stream %s: valid streams are `testing` and `stable`", imageStream) - } - streamurl := fedoracoreos.GetStreamURL(streamType) - resp, err := http.Get(streamurl.String()) - if err != nil { - return nil, err - } - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - defer func() { - if err := resp.Body.Close(); err != nil { - logrus.Error(err) - } - }() - - if err := json.Unmarshal(body, &fcosstable); err != nil { - return nil, err - } - arch, ok := fcosstable.Architectures[getFcosArch()] - if !ok { - return nil, fmt.Errorf("unable to pull VM image: no targetArch in stream") - } - artifacts := arch.Artifacts - if artifacts == nil { - return nil, fmt.Errorf("unable to pull VM image: no artifact in stream") - } - qemu, ok := artifacts[artifact] - if !ok { - return nil, fmt.Errorf("unable to pull VM image: no qemu artifact in stream") - } - formats := qemu.Formats - if formats == nil { - return nil, fmt.Errorf("unable to pull VM image: no formats in stream") - } - qcow, ok := formats[Format] - if !ok { - return nil, fmt.Errorf("unable to pull VM image: no qcow2.xz format in stream") - } - disk := qcow.Disk - if disk == nil { - return nil, fmt.Errorf("unable to pull VM image: no disk in stream") - } - return &fcosDownloadInfo{ - Location: disk.Location, - Release: qemu.Release, - Sha256Sum: disk.Sha256, - CompressionType: "xz", - }, nil -} diff --git a/pkg/machine/fcos_arm64.go b/pkg/machine/fcos_arm64.go deleted file mode 100644 index f45522be0..000000000 --- a/pkg/machine/fcos_arm64.go +++ /dev/null @@ -1,177 +0,0 @@ -package machine - -import ( - "encoding/json" - "io/ioutil" - "net/http" - url2 "net/url" - - "github.com/sirupsen/logrus" -) - -const aarchBaseURL = "https://fedorapeople.org/groups/fcos-images/builds/latest/aarch64/" - -// Total hack until automation is possible. -// We need a proper json file at least to automate -func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) { - meta := Build{} - resp, err := http.Get(aarchBaseURL + "meta.json") - if err != nil { - return nil, err - } - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - defer func() { - if err := resp.Body.Close(); err != nil { - logrus.Error(err) - } - }() - if err := json.Unmarshal(body, &meta); err != nil { - return nil, err - } - pathURL, err := url2.Parse(meta.BuildArtifacts.Qemu.Path) - if err != nil { - return nil, err - } - - baseURL, err := url2.Parse(aarchBaseURL) - if err != nil { - return nil, err - } - pullURL := baseURL.ResolveReference(pathURL) - return &fcosDownloadInfo{ - Location: pullURL.String(), - Release: "", - Sha256Sum: meta.BuildArtifacts.Qemu.Sha256, - }, nil -} - -/* - All of this can be nuked when fcos upstream generates a proper meta data file for aarch. -*/ -type AliyunImage struct { - ImageID string `json:"id"` - Region string `json:"name"` -} - -type Amis struct { - Hvm string `json:"hvm"` - Region string `json:"name"` - Snapshot string `json:"snapshot"` -} - -type Artifact struct { - Path string `json:"path"` - Sha256 string `json:"sha256"` - SizeInBytes float64 `json:"size,omitempty"` - UncompressedSha256 string `json:"uncompressed-sha256,omitempty"` - UncompressedSize int `json:"uncompressed-size,omitempty"` -} - -type Build struct { - AlibabaAliyunUploads []AliyunImage `json:"aliyun,omitempty"` - Amis []Amis `json:"amis,omitempty"` - Architecture string `json:"coreos-assembler.basearch,omitempty"` - Azure *Cloudartifact `json:"azure,omitempty"` - BuildArtifacts *BuildArtifacts `json:"images,omitempty"` - BuildID string `json:"buildid"` - BuildRef string `json:"ref,omitempty"` - BuildSummary string `json:"summary"` - BuildTimeStamp string `json:"coreos-assembler.build-timestamp,omitempty"` - BuildURL string `json:"build-url,omitempty"` - ConfigGitRev string `json:"coreos-assembler.config-gitrev,omitempty"` - ContainerConfigGit *Git `json:"coreos-assembler.container-config-git,omitempty"` - CoreOsSource string `json:"coreos-assembler.code-source,omitempty"` - CosaContainerImageGit *Git `json:"coreos-assembler.container-image-git,omitempty"` - CosaDelayedMetaMerge bool `json:"coreos-assembler.delayed-meta-merge,omitempty"` - CosaImageChecksum string `json:"coreos-assembler.image-config-checksum,omitempty"` - CosaImageVersion int `json:"coreos-assembler.image-genver,omitempty"` - Extensions *Extensions `json:"extensions,omitempty"` - FedoraCoreOsParentCommit string `json:"fedora-coreos.parent-commit,omitempty"` - FedoraCoreOsParentVersion string `json:"fedora-coreos.parent-version,omitempty"` - Gcp *Gcp `json:"gcp,omitempty"` - GitDirty string `json:"coreos-assembler.config-dirty,omitempty"` - ImageInputChecksum string `json:"coreos-assembler.image-input-checksum,omitempty"` - InputHasOfTheRpmOstree string `json:"rpm-ostree-inputhash"` - MetaStamp float64 `json:"coreos-assembler.meta-stamp,omitempty"` - Name string `json:"name"` - Oscontainer *Image `json:"oscontainer,omitempty"` - OstreeCommit string `json:"ostree-commit"` - OstreeContentBytesWritten int `json:"ostree-content-bytes-written,omitempty"` - OstreeContentChecksum string `json:"ostree-content-checksum"` - OstreeNCacheHits int `json:"ostree-n-cache-hits,omitempty"` - OstreeNContentTotal int `json:"ostree-n-content-total,omitempty"` - OstreeNContentWritten int `json:"ostree-n-content-written,omitempty"` - OstreeNMetadataTotal int `json:"ostree-n-metadata-total,omitempty"` - OstreeNMetadataWritten int `json:"ostree-n-metadata-written,omitempty"` - OstreeTimestamp string `json:"ostree-timestamp"` - OstreeVersion string `json:"ostree-version"` - OverridesActive bool `json:"coreos-assembler.overrides-active,omitempty"` - PkgdiffAgainstParent PackageSetDifferences `json:"parent-pkgdiff,omitempty"` - PkgdiffBetweenBuilds PackageSetDifferences `json:"pkgdiff,omitempty"` - ReleasePayload *Image `json:"release-payload,omitempty"` -} - -type BuildArtifacts struct { - Aliyun *Artifact `json:"aliyun,omitempty"` - Aws *Artifact `json:"aws,omitempty"` - Azure *Artifact `json:"azure,omitempty"` - AzureStack *Artifact `json:"azurestack,omitempty"` - Dasd *Artifact `json:"dasd,omitempty"` - DigitalOcean *Artifact `json:"digitalocean,omitempty"` - Exoscale *Artifact `json:"exoscale,omitempty"` - Gcp *Artifact `json:"gcp,omitempty"` - IbmCloud *Artifact `json:"ibmcloud,omitempty"` - Initramfs *Artifact `json:"initramfs,omitempty"` - Iso *Artifact `json:"iso,omitempty"` - Kernel *Artifact `json:"kernel,omitempty"` - LiveInitramfs *Artifact `json:"live-initramfs,omitempty"` - LiveIso *Artifact `json:"live-iso,omitempty"` - LiveKernel *Artifact `json:"live-kernel,omitempty"` - LiveRootfs *Artifact `json:"live-rootfs,omitempty"` - Metal *Artifact `json:"metal,omitempty"` - Metal4KNative *Artifact `json:"metal4k,omitempty"` - OpenStack *Artifact `json:"openstack,omitempty"` - Ostree Artifact `json:"ostree"` - Qemu *Artifact `json:"qemu,omitempty"` - Vmware *Artifact `json:"vmware,omitempty"` - Vultr *Artifact `json:"vultr,omitempty"` -} - -type Cloudartifact struct { - Image string `json:"image"` - URL string `json:"url"` -} - -type Extensions struct { - Manifest map[string]interface{} `json:"manifest"` - Path string `json:"path"` - RpmOstreeState string `json:"rpm-ostree-state"` - Sha256 string `json:"sha256"` -} - -type Gcp struct { - ImageFamily string `json:"family,omitempty"` - ImageName string `json:"image"` - ImageProject string `json:"project,omitempty"` - URL string `json:"url"` -} - -type Git struct { - Branch string `json:"branch,omitempty"` - Commit string `json:"commit"` - Dirty string `json:"dirty,omitempty"` - Origin string `json:"origin"` -} - -type Image struct { - Comment string `json:"comment,omitempty"` - Digest string `json:"digest"` - Image string `json:"image"` -} - -type Items interface{} - -type PackageSetDifferences []Items -- cgit v1.2.3-54-g00ecf