Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

cosa: use generated structs from schema #1187

Merged
merged 1 commit into from
Feb 24, 2020
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
12 changes: 6 additions & 6 deletions cmd/kola/kola.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ func syncFindParentImageOptions() error {
}
qemuImageDirIsTemp = true
}
qcowUrl := parentBaseUrl + parentCosaBuild.Images.QEMU.Path
qcowLocal := filepath.Join(qemuImageDir, parentCosaBuild.Images.QEMU.Path)
qcowUrl := parentBaseUrl + parentCosaBuild.BuildArtifacts.Qemu.Path
qcowLocal := filepath.Join(qemuImageDir, parentCosaBuild.BuildArtifacts.Qemu.Path)
decompressedQcowLocal, err := downloadImageAndDecompress(qcowUrl, qcowLocal)
if err != nil {
return err
Expand Down Expand Up @@ -495,15 +495,15 @@ func getParentFcosBuildBase() (string, error) {
// parse commitmeta.json for `fedora-coreos.stream`, then fetch the stream
// metadata for that stream, then fetch the release metadata

if kola.CosaBuild.Ref == "" {
if kola.CosaBuild.BuildRef == "" {
return "", errors.New("no ref in build metadata")
}

stream := filepath.Base(kola.CosaBuild.Ref)
stream := filepath.Base(kola.CosaBuild.BuildRef)

var parentVersion string
if kola.CosaBuild.FedoraCoreOSParentVersion != "" {
parentVersion = kola.CosaBuild.FedoraCoreOSParentVersion
if kola.CosaBuild.FedoraCoreOsParentVersion != "" {
parentVersion = kola.CosaBuild.FedoraCoreOsParentVersion
} else {
// ok, we're probably operating on a local dev build since the pipeline
// always injects the parent; just instead fetch the release index
Expand Down
2 changes: 1 addition & 1 deletion cmd/kola/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func syncCosaOptions() error {
switch kolaPlatform {
case "qemu-unpriv", "qemu":
if kola.QEMUOptions.DiskImage == "" {
kola.QEMUOptions.DiskImage = filepath.Join(filepath.Dir(kola.Options.CosaBuild), kola.CosaBuild.Images.QEMU.Path)
kola.QEMUOptions.DiskImage = filepath.Join(filepath.Dir(kola.Options.CosaBuild), kola.CosaBuild.BuildArtifacts.Qemu.Path)
}
}

Expand Down
44 changes: 2 additions & 42 deletions cosa/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,6 @@ import (
"github.com/pkg/errors"
)

// Build is the coreos-assembler `meta.json` which defines a build.
// This code was copied from openshift-installer's
// https://github.com/openshift/installer/blob/a0350404997b0493d7bb16aa2875e5c42879b069/pkg/rhcos/builds.go
// For now, copy-paste updates there. Later, maybe consider making this a public API?
type Build struct {
Ref string `json:"ref"`
OSTreeVersion string `json:"ostree-version"`
OSTreeCommit string `json:"ostree-commit"`
AMIs []struct {
Region string `json:"name"`
HVM string `json:"hvm"`
} `json:"amis"`
Azure struct {
Image string `json:"image"`
URL string `json:"url"`
}
GCP struct {
Image string `json:"image"`
URL string `json:"url"`
}
BaseURI string `json:"baseURI"`
Images struct {
OSTree struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
} `json:"ostree"`
QEMU struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
UncompressedSHA256 string `json:"uncompressed-sha256"`
} `json:"qemu"`
OpenStack struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
UncompressedSHA256 string `json:"uncompressed-sha256"`
} `json:"openstack"`
} `json:"images"`
FedoraCoreOSParentVersion string `json:"fedora-coreos.parent-version"`
}

func ParseBuild(path string) (*Build, error) {
f, err := os.Open(path)
if err != nil {
Expand Down Expand Up @@ -103,9 +63,9 @@ func FetchAndParseBuild(url string) (*Build, error) {
}

func (build *Build) FindAMI(region string) (string, error) {
for _, ami := range build.AMIs {
for _, ami := range build.Amis {
if ami.Region == region {
return ami.HVM, nil
return ami.Hvm, nil
}
}
return "", fmt.Errorf("no AMI found for region %s", region)
Expand Down
98 changes: 98 additions & 0 deletions cosa/cosa_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package cosa

// generated by "schematyper cosa/v1.json -o cosa/cosa_v1.go --package=cosa --root-type=Build" -- DO NOT EDIT

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 int `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,omitempty"`
BuildRef string `json:"ref,omitempty"`
BuildSummary string `json:"summary,omitempty"`
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"`
CosaImageChecksum string `json:"coreos-assembler.image-config-checksum,omitempty"`
CosaImageVersion int `json:"coreos-assembler.image-genver,omitempty"`
FedoraCoreOsParentCommit string `json:"fedora-coreos.parent-commit,omitempty"`
FedoraCoreOsParentVersion string `json:"fedora-coreos.parent-version,omitempty"`
Gcp Cloudartifact `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,omitempty"`
Name string `json:"name,omitempty"`
Oscontainer Image `json:"oscontainer,omitempty"`
OstreeCommit string `json:"ostree-commit,omitempty"`
OstreeContentBytesWritten int `json:"ostree-content-bytes-written,omitempty"`
OstreeContentChecksum string `json:"ostree-content-checksum,omitempty"`
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,omitempty"`
OstreeVersion string `json:"ostree-version,omitempty"`
OverridesActive bool `json:"coreos-assembler.overrides-active,omitempty"`
PkgdiffBetweenBuilds []PackageSetDifferences `json:"pkgdiff,omitempty"`
}

type BuildArtifacts struct {
Aliyun Artifact `json:"aliyun,omitempty"`
Aws Artifact `json:"aws,omitempty"`
Azure Artifact `json:"azure,omitempty"`
Dasd Artifact `json:"dasd,omitempty"`
Gcp Artifact `json:"gcp,omitempty"`
Initramfs Artifact `json:"initramfs,omitempty"`
Iso Artifact `json:"iso,omitempty"`
Kernel Artifact `json:"kernel,omitempty"`
Metal Artifact `json:"metal,omitempty"`
OpenStack Artifact `json:"openstack,omitempty"`
Ostree Artifact `json:"ostree"`
Qemu Artifact `json:"qemu,omitempty"`
Vmware Artifact `json:"vmware,omitempty"`
}

type Cloudartifact struct {
Image string `json:"image"`
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 {
Digest string `json:"digest"`
Image string `json:"image"`
}

type Items interface{}

type PackageSetDifferences []Items
Loading