From 5a178a5578621562ec4f1078136bd14dd6c7483a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 15 Jan 2021 16:34:17 +0000 Subject: [PATCH] mantle: bump coreos/stream-metadata-go Prep for further work on https://github.com/openshift/os/issues/477 --- mantle/go.mod | 2 +- mantle/go.sum | 3 + .../stream-metadata-go/release/release.go | 58 +++--- .../stream-metadata-go/release/translate.go | 183 ++++++++++++++++++ .../stream-metadata-go/stream/stream.go | 55 +++--- mantle/vendor/modules.txt | 2 +- 6 files changed, 248 insertions(+), 55 deletions(-) create mode 100644 mantle/vendor/github.com/coreos/stream-metadata-go/release/translate.go diff --git a/mantle/go.mod b/mantle/go.mod index 736fc1f550..6cffbf5916 100644 --- a/mantle/go.mod +++ b/mantle/go.mod @@ -19,7 +19,7 @@ require ( github.com/coreos/ignition/v2 v2.9.0 github.com/coreos/ioprogress v0.0.0-20151023204047-4637e494fd9b github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f - github.com/coreos/stream-metadata-go v0.0.0-20210107232620-d808ce9d237c + github.com/coreos/stream-metadata-go v0.0.0-20210115160721-ba77d4e64952 github.com/digitalocean/go-libvirt v0.0.0-20200810224808-b9c702499bf7 // indirect github.com/digitalocean/go-qemu v0.0.0-20200529005954-1b453d036a9c github.com/digitalocean/godo v1.33.0 diff --git a/mantle/go.sum b/mantle/go.sum index fc1031572f..5e51e04f58 100644 --- a/mantle/go.sum +++ b/mantle/go.sum @@ -107,6 +107,9 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbp github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/stream-metadata-go v0.0.0-20210107232620-d808ce9d237c h1:7VO10dpKljeaYJUQtObhqjNxpuTCUDELTviJsGy9OeM= github.com/coreos/stream-metadata-go v0.0.0-20210107232620-d808ce9d237c/go.mod h1:RTjQyHgO/G37oJ3qnqYK6Z4TPZ5EsaabOtfMjVXmgko= +github.com/coreos/stream-metadata-go v0.0.0-20210112152733-52b38c241a3d h1:a65dhEcT+kL9Bf5pDpdoOMdT5w0VjwUXE+XO2MoFuSg= +github.com/coreos/stream-metadata-go v0.0.0-20210115160721-ba77d4e64952 h1:t7IgMcyflINfXWPISnHTXwa/F+NxLgWGRGejoyfHUII= +github.com/coreos/stream-metadata-go v0.0.0-20210115160721-ba77d4e64952/go.mod h1:RTjQyHgO/G37oJ3qnqYK6Z4TPZ5EsaabOtfMjVXmgko= github.com/coreos/vcontext v0.0.0-20190529201340-22b159166068 h1:y2aHj7QqyAJ6YBBONTAr17YxHHiogDkYnTsJvFNhxwY= github.com/coreos/vcontext v0.0.0-20190529201340-22b159166068/go.mod h1:E+6hug9bFSe0KZ2ZAzr8M9F5JlArJjv5D1JS7KSkPKE= github.com/coreos/vcontext v0.0.0-20201120045928-b0e13dab675c h1:jA28WeORitsxGFVWhyWB06sAG2HbLHPQuHwDydhU2CQ= diff --git a/mantle/vendor/github.com/coreos/stream-metadata-go/release/release.go b/mantle/vendor/github.com/coreos/stream-metadata-go/release/release.go index e4c2dca252..ae7afc9977 100644 --- a/mantle/vendor/github.com/coreos/stream-metadata-go/release/release.go +++ b/mantle/vendor/github.com/coreos/stream-metadata-go/release/release.go @@ -1,10 +1,9 @@ +// Package release contains APIs for interacting with a +// particular "release". Avoid this unless you are sure +// you need it. It's expected that CoreOS users interact +// with streams instead. package release -// Metadata is common metadata that contains last-modified -type Metadata struct { - LastModified string `json:"last-modified"` -} - // Index models the release index: // https://github.com/coreos/fedora-coreos-tracker/tree/master/metadata/release-index type Index struct { @@ -27,28 +26,6 @@ type IndexReleaseCommit struct { Checksum string `json:"checksum"` } -// ImageFormat contains all artifacts for a single OS image -type ImageFormat struct { - Disk *Artifact `json:"disk,omitempty"` - Kernel *Artifact `json:"kernel,omitempty"` - Initramfs *Artifact `json:"initramfs,omitempty"` - Rootfs *Artifact `json:"rootfs,omitempty"` -} - -// Artifact represents one image file, plus its metadata -type Artifact struct { - Location string `json:"location"` - Signature string `json:"signature"` - Sha256 string `json:"sha256"` -} - -// GcpImage represents a GCP cloud image -type GcpImage struct { - Project string `json:"project,omitempty"` - Family string `json:"family,omitempty"` - Name string `json:"name,omitempty"` -} - // Release contains details from release.json type Release struct { Release string `json:"release"` @@ -57,6 +34,11 @@ type Release struct { Architectures map[string]Arch `json:"architectures"` } +// Metadata is common metadata that contains last-modified +type Metadata struct { + LastModified string `json:"last-modified"` +} + // Arch release details type Arch struct { Commit string `json:"commit"` @@ -96,7 +78,29 @@ type PlatformGcp struct { Image *GcpImage `json:"image"` } +// ImageFormat contains all artifacts for a single OS image +type ImageFormat struct { + Disk *Artifact `json:"disk,omitempty"` + Kernel *Artifact `json:"kernel,omitempty"` + Initramfs *Artifact `json:"initramfs,omitempty"` + Rootfs *Artifact `json:"rootfs,omitempty"` +} + +// Artifact represents one image file, plus its metadata +type Artifact struct { + Location string `json:"location"` + Signature string `json:"signature"` + Sha256 string `json:"sha256"` +} + // CloudImage generic image detail type CloudImage struct { Image string `json:"image"` } + +// GcpImage represents a GCP cloud image +type GcpImage struct { + Project string `json:"project,omitempty"` + Family string `json:"family,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/mantle/vendor/github.com/coreos/stream-metadata-go/release/translate.go b/mantle/vendor/github.com/coreos/stream-metadata-go/release/translate.go new file mode 100644 index 0000000000..adcf9336cb --- /dev/null +++ b/mantle/vendor/github.com/coreos/stream-metadata-go/release/translate.go @@ -0,0 +1,183 @@ +package release + +import ( + "github.com/coreos/stream-metadata-go/stream" +) + +func mapArtifact(ra *Artifact) *stream.Artifact { + if ra == nil { + return nil + } + return &stream.Artifact{ + Location: ra.Location, + Signature: ra.Signature, + Sha256: ra.Sha256, + } +} + +func mapFormats(m map[string]ImageFormat) map[string]stream.ImageFormat { + r := make(map[string]stream.ImageFormat) + for k, v := range m { + r[k] = stream.ImageFormat{ + Disk: mapArtifact(v.Disk), + Kernel: mapArtifact(v.Kernel), + Initramfs: mapArtifact(v.Initramfs), + Rootfs: mapArtifact(v.Rootfs), + } + } + return r +} + +// Convert a release architecture to a stream architecture +func (releaseArch *Arch) toStreamArch(rel *Release) stream.Arch { + artifacts := make(map[string]stream.PlatformArtifacts) + cloudImages := stream.Images{} + if releaseArch.Media.Aws != nil { + artifacts["aws"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Aws.Artifacts), + } + awsAmis := stream.AwsImage{ + Regions: make(map[string]stream.AwsRegionImage), + } + if releaseArch.Media.Aws.Images != nil { + for region, ami := range releaseArch.Media.Aws.Images { + ri := stream.AwsRegionImage{Release: rel.Release, Image: ami.Image} + awsAmis.Regions[region] = ri + + } + cloudImages.Aws = &awsAmis + } + } + + if releaseArch.Media.Azure != nil { + artifacts["azure"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Azure.Artifacts), + } + + // Not enabled right now + // if az := releaseArch.Media.Azure.Images; az != nil && az.Global != nil && az.Global.Image != nil { + // azureImage := StreamCloudImage{} + // azureImage.Image = fmt.Sprintf("Fedora:CoreOS:%s:latest", rel.Stream) + // cloudImages.Azure = &azureImage + // } + } + + if releaseArch.Media.Aliyun != nil { + artifacts["aliyun"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Aliyun.Artifacts), + } + } + + if releaseArch.Media.Exoscale != nil { + artifacts["exoscale"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Exoscale.Artifacts), + } + } + + if releaseArch.Media.Vultr != nil { + artifacts["vultr"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Vultr.Artifacts), + } + } + + if releaseArch.Media.Gcp != nil { + artifacts["gcp"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Gcp.Artifacts), + } + + if releaseArch.Media.Gcp.Image != nil { + cloudImages.Gcp = &stream.GcpImage{ + Name: releaseArch.Media.Gcp.Image.Name, + Family: releaseArch.Media.Gcp.Image.Family, + Project: releaseArch.Media.Gcp.Image.Project, + } + } + } + + if releaseArch.Media.Digitalocean != nil { + artifacts["digitalocean"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Digitalocean.Artifacts), + } + + /* We're producing artifacts but they're not yet available + in DigitalOcean as distribution images. + digitalOceanImage := stream.CloudImage{Image: fmt.Sprintf("fedora-coreos-%s", Stream)} + cloudImages.Digitalocean = &digitalOceanImage + */ + } + + if releaseArch.Media.Ibmcloud != nil { + artifacts["ibmcloud"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Ibmcloud.Artifacts), + } + } + + // if releaseArch.Media.Packet != nil { + // packet := StreamMediaDetails{ + // Release: rel.Release, + // Formats: releaseArch.Media.Packet.Artifacts, + // } + // artifacts.Packet = &packet + + // packetImage := StreamCloudImage{Image: fmt.Sprintf("fedora_coreos_%s", rel.Stream)} + // cloudImages.Packet = &packetImage + // } + + if releaseArch.Media.Openstack != nil { + artifacts["openstack"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Openstack.Artifacts), + } + } + + if releaseArch.Media.Qemu != nil { + artifacts["qemu"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Qemu.Artifacts), + } + } + + // if releaseArch.Media.Virtualbox != nil { + // virtualbox := StreamMediaDetails{ + // Release: rel.Release, + // Formats: releaseArch.Media.Virtualbox.Artifacts, + // } + // artifacts.Virtualbox = &virtualbox + // } + + if releaseArch.Media.Vmware != nil { + artifacts["vmware"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Vmware.Artifacts), + } + } + + if releaseArch.Media.Metal != nil { + artifacts["metal"] = stream.PlatformArtifacts{ + Release: rel.Release, + Formats: mapFormats(releaseArch.Media.Metal.Artifacts), + } + } + + return stream.Arch{ + Artifacts: artifacts, + Images: cloudImages, + } +} + +// ToStreamArchitectures converts a release to a stream +func (rel *Release) ToStreamArchitectures() map[string]stream.Arch { + streamArch := make(map[string]stream.Arch) + for arch, releaseArch := range rel.Architectures { + streamArch[arch] = releaseArch.toStreamArch(rel) + } + return streamArch +} diff --git a/mantle/vendor/github.com/coreos/stream-metadata-go/stream/stream.go b/mantle/vendor/github.com/coreos/stream-metadata-go/stream/stream.go index 0c74117e1d..3571440012 100644 --- a/mantle/vendor/github.com/coreos/stream-metadata-go/stream/stream.go +++ b/mantle/vendor/github.com/coreos/stream-metadata-go/stream/stream.go @@ -1,10 +1,32 @@ +// Package stream models a CoreOS "stream", which is +// a description of the recommended set of binary images for CoreOS. Use +// this API to find cloud images, bare metal disk images, etc. package stream +// Stream contains artifacts available in a stream +type Stream struct { + Stream string `json:"stream"` + Metadata Metadata `json:"metadata"` + Architectures map[string]Arch `json:"architectures"` +} + // Metadata for a release or stream type Metadata struct { LastModified string `json:"last-modified"` } +// Arch contains release details for a particular hardware architecture +type Arch struct { + Artifacts map[string]PlatformArtifacts `json:"artifacts"` + Images Images `json:"images,omitempty"` +} + +// PlatformArtifacts contains images for a platform +type PlatformArtifacts struct { + Release string `json:"release"` + Formats map[string]ImageFormat `json:"formats"` +} + // ImageFormat contains all artifacts for a single OS image type ImageFormat struct { Disk *Artifact `json:"disk,omitempty"` @@ -20,32 +42,6 @@ type Artifact struct { Sha256 string `json:"sha256"` } -// GcpImage represents a GCP cloud image -type GcpImage struct { - Project string `json:"project,omitempty"` - Family string `json:"family,omitempty"` - Name string `json:"name,omitempty"` -} - -// Stream contains artifacts available in a stream -type Stream struct { - Stream string `json:"stream"` - Metadata Metadata `json:"metadata"` - Architectures map[string]Arch `json:"architectures"` -} - -// Architecture release details -type Arch struct { - Artifacts map[string]PlatformArtifacts `json:"artifacts"` - Images Images `json:"images,omitempty"` -} - -// PlatformArtifacts contains images for a platform -type PlatformArtifacts struct { - Release string `json:"release"` - Formats map[string]ImageFormat `json:"formats"` -} - // Images contains images available in cloud providers type Images struct { Aws *AwsImage `json:"aws,omitempty"` @@ -62,3 +58,10 @@ type AwsRegionImage struct { Release string `json:"release"` Image string `json:"image"` } + +// GcpImage represents a GCP cloud image +type GcpImage struct { + Project string `json:"project,omitempty"` + Family string `json:"family,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/mantle/vendor/modules.txt b/mantle/vendor/modules.txt index b80ec67d7f..7a36485013 100644 --- a/mantle/vendor/modules.txt +++ b/mantle/vendor/modules.txt @@ -167,7 +167,7 @@ github.com/coreos/ioprogress # github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f github.com/coreos/pkg/capnslog github.com/coreos/pkg/multierror -# github.com/coreos/stream-metadata-go v0.0.0-20210107232620-d808ce9d237c +# github.com/coreos/stream-metadata-go v0.0.0-20210115160721-ba77d4e64952 github.com/coreos/stream-metadata-go/fedoracoreos github.com/coreos/stream-metadata-go/fedoracoreos/internals github.com/coreos/stream-metadata-go/release