Skip to content
Permalink
Browse files

add -flattened-snapshot flag

The new "-flattened-snapshot" flag alters the "-snapshot" and
"-manifest-based-snapshot-of" flags to return a CSV of images, with 1
unique image per line.

Sample output against us.gcr.io/k8s-artifacts-prod with this flag:

    artifact-promoter/cip@sha256:799f81d9a855717eab7198310655d1b55919320b120f0f015c3bb43c4e90316d,artifact-promoter/cip:20190821-v2.2.1-2-gc29e4fc
    capi-kubeadm/cluster-api-kubeadm-controller@sha256:c3ee2e114b6bf81d0cf0686bc80ba3281d70782ffd56b2ae8ef281aec319530b,capi-kubeadm/cluster-api-kubeadm-controller:v0.1.0
    capi-kubeadm/cluster-api-kubeadm-controller-amd64@sha256:51e5a17ac02cf8f2f9ce0bd0892da6fc52fa15d0a9d4ffd6a623d0e20d2eaacb,capi-kubeadm/cluster-api-kubeadm-controller-amd64:v0.1.0
    capi-kubeadm/cluster-api-kubeadm-controller-arm@sha256:3f53bf8a424f1d70ee58c1b94930ce892c9bad7874cd1a2d8ab4598a60545005,capi-kubeadm/cluster-api-kubeadm-controller-arm:v0.1.0
    capi-kubeadm/cluster-api-kubeadm-controller-arm64@sha256:b3745c214ea8ca87339b58e898bcaaedeffc05015d22c5febdf50017a96626e8,capi-kubeadm/cluster-api-kubeadm-controller-arm64:v0.1.0
    capi-kubeadm/cluster-api-kubeadm-controller-ppc64le@sha256:801beba208ba51f1b8c5be64bb6c5c99e87449eef3544d4e082ac4e2044a148e,capi-kubeadm/cluster-api-kubeadm-controller-ppc64le:v0.1.0
    capi-kubeadm/cluster-api-kubeadm-controller-s390x@sha256:90d53f71722e6b3a1410747c261fc9a23fc6c4a5d02f67852cdec602dc43ced0,capi-kubeadm/cluster-api-kubeadm-controller-s390x:v0.1.0
    cluster-api-aws/cluster-api-aws-controller@sha256:7397e3ef7dfa72b102197eaa6bd20ca8b572ccbc31a30f3d262188376e95836a,cluster-api-aws/cluster-api-aws-controller:v0.3.6
    cluster-api-aws/cluster-api-aws-controller@sha256:76cf7f26e0abfb5bd862670606a93593f4ac9c51a2ba1c281cc7d709869a2cc1,cluster-api-aws/cluster-api-aws-controller:v0.4.0
    cluster-api-aws/cluster-api-aws-controller@sha256:b04cd8882f99aec51ef714a60bd16b7d1f6bae3e4f955bee834744c35b6fb21f,cluster-api-aws/cluster-api-aws-controller:v0.3.8
    cluster-api-aws/cluster-api-aws-controller@sha256:e167eec012a77eb6f1741bcb7c6b9514ffdd5ac154137cba86c14f40db979913,cluster-api-aws/cluster-api-aws-controller:v0.3.7
    cluster-api-aws/cluster-api-aws-controller-amd64@sha256:0bd88bcba94f800715fca33ffc4bde430646a7c797237313cbccdcdef9f80f2d,cluster-api-aws/cluster-api-aws-controller-amd64:v0.4.0
    cluster-api-aws/cluster-api-aws-controller-arm@sha256:19016ec3ce30985a128494909993aef9109a5bdd749874e9b3be20bd65056fee,cluster-api-aws/cluster-api-aws-controller-arm:v0.4.0
    cluster-api-aws/cluster-api-aws-controller-arm64@sha256:5c434128d7e28d96d25f11a096e6b9d666d52c5bb683662ba708d22792a0f154,cluster-api-aws/cluster-api-aws-controller-arm64:v0.4.0
    cluster-api-aws/cluster-api-aws-controller-ppc64le@sha256:e0af472014f7639b6362e1649717a63e621faf91a5be1ed89f1055689111214c,cluster-api-aws/cluster-api-aws-controller-ppc64le:v0.4.0
    cluster-api-aws/cluster-api-aws-controller-s390x@sha256:0ad4f92011b2fa5de88a6e6a2d8b97f38371246021c974760e5fc54b9b7069e5,cluster-api-aws/cluster-api-aws-controller-s390x:v0.4.0
    cluster-api/cluster-api-controller@sha256:04e5bbda841ff8c34afd5fc598b9f3f8fd6b82cca49129ba4de7af316e40f87e,cluster-api/cluster-api-controller:v0.2.0
    cluster-api/cluster-api-controller@sha256:5867b7735a9d85ea13ed5ab0fce90ae0945c753a119e6bd02f7ceeebec2dd608,cluster-api/cluster-api-controller:v0.1.9
    cluster-api/cluster-api-controller@sha256:663829ece3a14201b71ec1e211c3d33f99ecdf0ea8081f7486806442a61d925d,cluster-api/cluster-api-controller:v0.1.7
    cluster-api/cluster-api-controller@sha256:663829ece3a14201b71ec1e211c3d33f99ecdf0ea8081f7486806442a61d925d,cluster-api/cluster-api-controller:v0.1.8
    cluster-api/cluster-api-controller@sha256:9057a2875d6620521ddea456f31655b8480f07f6a31a50c15b111c1ae09af487,cluster-api/cluster-api-controller:v0.1.5
    cluster-api/cluster-api-controller@sha256:9057a2875d6620521ddea456f31655b8480f07f6a31a50c15b111c1ae09af487,cluster-api/cluster-api-controller:v0.1.6
    cluster-api/cluster-api-controller@sha256:9652a07cc57081be625d50ab68d4226c7db0e2289384dc1a7061b6a7375f0f05,cluster-api/cluster-api-controller:v0.1.10
    cluster-api/cluster-api-controller@sha256:a2049bd4253224693abb248ad446c633a2028e1af5b0628491af5ef7877a0166,cluster-api/cluster-api-controller:v0.2.1
    cluster-api/cluster-api-controller@sha256:d5ca573e5fb723a52b267df51e00c811fe97f4d797fb8ad6f8680f13f3282008,cluster-api/cluster-api-controller:v0.2.2
    cluster-api/cluster-api-controller-amd64@sha256:ea0e994082f56bf7713d36002abfbffbad43b2c257b89842b3e3694c987d3a07,cluster-api/cluster-api-controller-amd64:v0.2.0
    cluster-api/cluster-api-controller-arm@sha256:ddac971ea0e62e0bc969263c57d10bcdaace99918ff5b304b0531ad115459a1f,cluster-api/cluster-api-controller-arm:v0.2.0
    cluster-api/cluster-api-controller-arm64@sha256:86e2ae014190d8ab6f511ba8ed9c60658e906f4a2e6eab7adbb65debd91f51b7,cluster-api/cluster-api-controller-arm64:v0.2.0
    cluster-api/cluster-api-controller-ppc64le@sha256:d7ec2c3a3c353e5dccff16e5ca9253415d3e3b5398a7beb3f95bf54f1e270fb8,cluster-api/cluster-api-controller-ppc64le:v0.2.0
    cluster-api/cluster-api-controller-s390x@sha256:47e89f01c17f66513adddac0b48e035ab937469f3b93df7ab704d725d1e611c1,cluster-api/cluster-api-controller-s390x:v0.2.0
    cluster-api/plantuml@sha256:befa605d8640516f9fbada5c1969638c5cb60fb042f598a432cbd22345570bc5,cluster-api/plantuml:1.2019.6

vs without this flag:

    - name: artifact-promoter/cip
      dmap:
        sha256:799f81d9a855717eab7198310655d1b55919320b120f0f015c3bb43c4e90316d:
        - 20190821-v2.2.1-2-gc29e4fc
    - name: capi-kubeadm/cluster-api-kubeadm-controller
      dmap:
        sha256:c3ee2e114b6bf81d0cf0686bc80ba3281d70782ffd56b2ae8ef281aec319530b:
        - v0.1.0
    - name: capi-kubeadm/cluster-api-kubeadm-controller-amd64
      dmap:
        sha256:51e5a17ac02cf8f2f9ce0bd0892da6fc52fa15d0a9d4ffd6a623d0e20d2eaacb:
        - v0.1.0
    - name: capi-kubeadm/cluster-api-kubeadm-controller-arm
      dmap:
        sha256:3f53bf8a424f1d70ee58c1b94930ce892c9bad7874cd1a2d8ab4598a60545005:
        - v0.1.0
    - name: capi-kubeadm/cluster-api-kubeadm-controller-arm64
      dmap:
        sha256:b3745c214ea8ca87339b58e898bcaaedeffc05015d22c5febdf50017a96626e8:
        - v0.1.0
    - name: capi-kubeadm/cluster-api-kubeadm-controller-ppc64le
      dmap:
        sha256:801beba208ba51f1b8c5be64bb6c5c99e87449eef3544d4e082ac4e2044a148e:
        - v0.1.0
    - name: capi-kubeadm/cluster-api-kubeadm-controller-s390x
      dmap:
        sha256:90d53f71722e6b3a1410747c261fc9a23fc6c4a5d02f67852cdec602dc43ced0:
        - v0.1.0
    - name: cluster-api-aws/cluster-api-aws-controller
      dmap:
        sha256:7397e3ef7dfa72b102197eaa6bd20ca8b572ccbc31a30f3d262188376e95836a:
        - v0.3.6
        sha256:76cf7f26e0abfb5bd862670606a93593f4ac9c51a2ba1c281cc7d709869a2cc1:
        - v0.4.0
        sha256:b04cd8882f99aec51ef714a60bd16b7d1f6bae3e4f955bee834744c35b6fb21f:
        - v0.3.8
        sha256:e167eec012a77eb6f1741bcb7c6b9514ffdd5ac154137cba86c14f40db979913:
        - v0.3.7
    - name: cluster-api-aws/cluster-api-aws-controller-amd64
      dmap:
        sha256:0bd88bcba94f800715fca33ffc4bde430646a7c797237313cbccdcdef9f80f2d:
        - v0.4.0
    - name: cluster-api-aws/cluster-api-aws-controller-arm
      dmap:
        sha256:19016ec3ce30985a128494909993aef9109a5bdd749874e9b3be20bd65056fee:
        - v0.4.0
    - name: cluster-api-aws/cluster-api-aws-controller-arm64
      dmap:
        sha256:5c434128d7e28d96d25f11a096e6b9d666d52c5bb683662ba708d22792a0f154:
        - v0.4.0
    - name: cluster-api-aws/cluster-api-aws-controller-ppc64le
      dmap:
        sha256:e0af472014f7639b6362e1649717a63e621faf91a5be1ed89f1055689111214c:
        - v0.4.0
    - name: cluster-api-aws/cluster-api-aws-controller-s390x
      dmap:
        sha256:0ad4f92011b2fa5de88a6e6a2d8b97f38371246021c974760e5fc54b9b7069e5:
        - v0.4.0
    - name: cluster-api/cluster-api-controller
      dmap:
        sha256:04e5bbda841ff8c34afd5fc598b9f3f8fd6b82cca49129ba4de7af316e40f87e:
        - v0.2.0
        sha256:5867b7735a9d85ea13ed5ab0fce90ae0945c753a119e6bd02f7ceeebec2dd608:
        - v0.1.9
        sha256:663829ece3a14201b71ec1e211c3d33f99ecdf0ea8081f7486806442a61d925d:
        - v0.1.7
        - v0.1.8
        sha256:9057a2875d6620521ddea456f31655b8480f07f6a31a50c15b111c1ae09af487:
        - v0.1.5
        - v0.1.6
        sha256:9652a07cc57081be625d50ab68d4226c7db0e2289384dc1a7061b6a7375f0f05:
        - v0.1.10
        sha256:a2049bd4253224693abb248ad446c633a2028e1af5b0628491af5ef7877a0166:
        - v0.2.1
        sha256:d5ca573e5fb723a52b267df51e00c811fe97f4d797fb8ad6f8680f13f3282008:
        - v0.2.2
    - name: cluster-api/cluster-api-controller-amd64
      dmap:
        sha256:ea0e994082f56bf7713d36002abfbffbad43b2c257b89842b3e3694c987d3a07:
        - v0.2.0
    - name: cluster-api/cluster-api-controller-arm
      dmap:
        sha256:ddac971ea0e62e0bc969263c57d10bcdaace99918ff5b304b0531ad115459a1f:
        - v0.2.0
    - name: cluster-api/cluster-api-controller-arm64
      dmap:
        sha256:86e2ae014190d8ab6f511ba8ed9c60658e906f4a2e6eab7adbb65debd91f51b7:
        - v0.2.0
    - name: cluster-api/cluster-api-controller-ppc64le
      dmap:
        sha256:d7ec2c3a3c353e5dccff16e5ca9253415d3e3b5398a7beb3f95bf54f1e270fb8:
        - v0.2.0
    - name: cluster-api/cluster-api-controller-s390x
      dmap:
        sha256:47e89f01c17f66513adddac0b48e035ab937469f3b93df7ab704d725d1e611c1:
        - v0.2.0
    - name: cluster-api/plantuml
      dmap:
        sha256:befa605d8640516f9fbada5c1969638c5cb60fb042f598a432cbd22345570bc5:
        - 1.2019.6
  • Loading branch information
listx committed Sep 25, 2019
1 parent 0396ce4 commit b39ab75f95ba11f5e306366edcff975147dbcdf7
Showing with 43 additions and 1 deletion.
  1. +10 −1 cip.go
  2. +33 −0 lib/dockerregistry/inventory.go
11 cip.go
@@ -93,6 +93,10 @@ func main() {
"minimal-snapshot",
false,
"(only works with -snapshot) discard tagless images from -snapshot output if they are referenced by a manifest list")
flattenedSnapshotPtr := flag.Bool(
"flattened-snapshot",
false,
"(only works with -snapshot) instead of printing YAML, print all images by their full digest reference, sorted lexicographically")
snapshotSvcAccPtr := flag.String(
"snapshot-service-account",
"",
@@ -292,7 +296,12 @@ func main() {
}
}

snapshot := rii.ToYAML()
var snapshot string
if *flattenedSnapshotPtr {
snapshot = rii.ToFlattened()
} else {
snapshot = rii.ToYAML()
}
fmt.Print(snapshot)
os.Exit(0)
}
@@ -1668,6 +1668,39 @@ func (rii *RegInvImage) ToYAML() string {
return b.String()
}

// ToFlattened is like ToYAML, but instead of printing things in an indented
// format, it prints one image on each line as a CSV. If there is a tag pointing
// to the image, then it is printed next to the image on the same line.
//
// E.g.
//
// nolint[lll]
// a@sha256:0000000000000000000000000000000000000000000000000000000000000000,a:1.0
// a@sha256:0000000000000000000000000000000000000000000000000000000000000000,a:latest
// b@sha256:1111111111111111111111111111111111111111111111111111111111111111,-
func (rii *RegInvImage) ToFlattened() string {
images := rii.ToSorted()

var b strings.Builder
for _, image := range images {
for _, digestEntry := range image.digests {
if len(digestEntry.tags) > 0 {
for _, tag := range digestEntry.tags {
fmt.Fprintf(&b, "%s@%s,%s:%s\n",
image.name,
digestEntry.hash,
image.name,
tag)
}
} else {
fmt.Fprintf(&b, "%s@%s,-\n", image.name, digestEntry.hash)
}
}
}

return b.String()
}

// ToLQIN converts a RegistryName and ImangeName to form a loosely-qualified
// image name (LQIN). Notice that it is missing tag information --- hence
// "loosely-qualified".

0 comments on commit b39ab75

Please sign in to comment.
You can’t perform that action at this time.