Skip to content
Permalink
Browse files

remove renames feature

The ability to rename images (not just the image names but the entire
path altogether) was never really used in practice. The only time that
has happened is when images path prefixes were renamed, as in

kubernetes/k8s.io@1d14e8e#diff-6d388aca90f2a61817328dbc3db1a123

but that change was short-lived as it was superseded by

kubernetes/k8s.io@946c4d9.
  • Loading branch information
listx committed Oct 10, 2019
1 parent 21a4735 commit b80ef8a1b015d2864aaaed183f5ce5d8b6358833
5 cip.go
@@ -195,11 +195,6 @@ func main() {
klog.Exitln(err)
}

err = reg.ValidateManifestsFromDir(mfests)
if err != nil {
klog.Exitln(err)
}

sc, err = reg.MakeSyncContext(
mfests,
*verbosityPtr,
@@ -75,11 +75,6 @@ func MakeSyncContext(
for _, r := range mfest.Registries {
registriesSeen[r] = nil
}

// Populate rename info found across all manifests.
for k, v := range mfest.renamesDenormalized {
sc.RenamesDenormalized[k] = v
}
}

// Populate SyncContext with registries found across all manifests.
@@ -145,12 +140,6 @@ func (m *Manifest) finalize() error {
}
m.srcRegistry = srcRegistry

rd, err := DenormalizeRenames(*m, srcRegistry.Name)
if err != nil {
return err
}
m.renamesDenormalized = rd

return nil
}

@@ -208,34 +197,6 @@ func ParseManifestsFromDir(dir string) ([]Manifest, error) {
return mfests, nil
}

// ValidateManifestsFromDir parses checks for errors found in the manifests,
// taken as a whole.
//
// nolint[gocyclo]
func ValidateManifestsFromDir(mfests []Manifest) error {
if len(mfests) == 0 {
return fmt.Errorf("no manifests to validate")
}

// If two manifests are renaming images, then they should not share any
// rename information (should be mutually exclusive). We use a separate loop
// for clarity.
renamesSeen := make(map[RegistryImagePath]string)
for _, mfest := range mfests {
for _, rename := range mfest.Renames {
for _, regImgPath := range rename {
if mfestFilepath, seen := renamesSeen[regImgPath]; seen {
// nolint[lll]
return fmt.Errorf("rename key '%s' found in multiple manifests:\n- '%s'\n- '%s'\n", regImgPath, mfestFilepath, mfest.filepath)
}
renamesSeen[regImgPath] = mfest.filepath
}
}
}

return nil
}

// ToPromotionEdges converts a list of manifests to a set of edges we want to
// try promoting.
func ToPromotionEdges(
@@ -257,8 +218,7 @@ func ToPromotionEdges(
destRC,
image.ImageName,
digest,
tag,
mfest.renamesDenormalized)
tag)
edges[edge] = nil
}
} else {
@@ -270,8 +230,7 @@ func ToPromotionEdges(
destRC,
image.ImageName,
digest,
"", // No associated tag; still promote!
mfest.renamesDenormalized)
"") // No associated tag; still promote!
edges[edge] = nil
}
}
@@ -286,8 +245,7 @@ func mkPromotionEdge(
srcRC, dstRC RegistryContext,
srcImageName ImageName,
digest Digest,
tag Tag,
rd RenamesDenormalized) PromotionEdge {
tag Tag) PromotionEdge {

edge := PromotionEdge{
SrcRegistry: srcRC,
@@ -298,20 +256,7 @@ func mkPromotionEdge(
DstRegistry: dstRC,
}

// Renames change how edges are created.
// nolint[lll]
regImgPath := RegistryImagePath(srcRC.Name) + "/" + RegistryImagePath(srcImageName)
if renames, ok := rd[regImgPath]; ok {
if imgName, ok := renames[dstRC.Name]; ok {
edge.DstImageTag = ImageTag{
ImageName: imgName,
Tag: tag}
return edge
}
}

// Without renames, the name in the destination is the same as the name in
// the source.
// The name in the destination is the same as the name in the source.
edge.DstImageTag = ImageTag{
ImageName: srcImageName,
Tag: tag}
@@ -622,7 +622,6 @@ func TestParseManifestsFromDir(t *testing.T) {
// testing).
gotModified := got[:0]
for _, mfest := range got {
mfest.renamesDenormalized = nil
mfest.srcRegistry = nil
gotModified = append(gotModified, mfest)
}
@@ -653,7 +652,6 @@ func TestValidateManifestsFromDir(t *testing.T) {
"multiple-rebases",
"overlapping-src-registries",
"overlapping-destination-vertices-same-digest",
"overlapping-destination-vertices-same-digest-by-rename",
}

pwd := bazelTestPath("TestValidateManifestsFromDir")
@@ -668,13 +666,6 @@ func TestValidateManifestsFromDir(t *testing.T) {
eqErr,
fmt.Sprintf("Test: `%v' should be valid (ParseManifestsFromDir)\n", testInput))

err := ValidateManifestsFromDir(mfests)
eqErr = checkEqual(err, nil)
checkError(
t,
eqErr,
fmt.Sprintf("Test: `%v' should be valid (ValidateManifestsFromDir)\n", testInput))

_, edgeErr := ToPromotionEdges(mfests)
eqErr = checkEqual(edgeErr, nil)
checkError(
@@ -722,14 +713,6 @@ func TestValidateManifestsFromDir(t *testing.T) {
fmt.Errorf(
"overlapping edges detected"),
},
{

"overlapping-destination-vertices-different-digest-by-rename",
nil,
nil,
fmt.Errorf(
"overlapping edges detected"),
},
}

for _, test := range shouldBeInvalid {
@@ -749,16 +732,6 @@ func TestValidateManifestsFromDir(t *testing.T) {
continue
}

validateErr := ValidateManifestsFromDir(mfests)
eqErr = checkEqual(validateErr, test.expectedValidateError)
checkError(
t,
eqErr,
fmt.Sprintf("Test: `%v' should be invalid (ValidateManifestsFromDir)\n", test.dirName))
if validateErr != nil {
continue
}

_, edgeErr := ToPromotionEdges(mfests)
eqErr = checkEqual(edgeErr, test.expectedEdgeError)
checkError(
@@ -1849,58 +1822,6 @@ func TestToPromotionEdges(t *testing.T) {
nil,
make(map[PromotionEdge]interface{}),
},
{
"Basic case (2 new edges; 1 is renamed and should be promoted)",
[]Manifest{
{
Registries: registries2,
Images: []Image{
{
ImageName: "a",
Dmap: DigestTags{
"sha256:000": TagSlice{"0.9"}}}},
Renames: []Rename{
[]RegistryImagePath{
"gcr.io/foo/a",
"gcr.io/cat/some/subdir/a"}},
srcRegistry: &srcRC},
},
map[PromotionEdge]interface{}{
{
SrcRegistry: srcRC,
SrcImageTag: ImageTag{
ImageName: "a",
Tag: "0.9"},
Digest: "sha256:000",
DstRegistry: destRC,
DstImageTag: ImageTag{
ImageName: "a",
Tag: "0.9"}}: nil,
{
SrcRegistry: srcRC,
SrcImageTag: ImageTag{
ImageName: "a",
Tag: "0.9"},
Digest: "sha256:000",
DstRegistry: destRC2,
DstImageTag: ImageTag{
ImageName: "some/subdir/a",
Tag: "0.9"}}: nil,
},
nil,
map[PromotionEdge]interface{}{
{
SrcRegistry: srcRC,
SrcImageTag: ImageTag{
ImageName: "a",
Tag: "0.9"},
Digest: "sha256:000",
DstRegistry: destRC2,
DstImageTag: ImageTag{
ImageName: "some/subdir/a",
Tag: "0.9"}}: nil,
},
},
}

for _, test := range tests {
@@ -2309,126 +2230,6 @@ func TestPromotion(t *testing.T) {
DigestOld: "sha256:111",
Tag: "0.9"}: 1},
},
{
"Promote 1 tag via rename",
Manifest{
Registries: registries,
Images: []Image{
{
ImageName: "a",
Dmap: DigestTags{
"sha256:000": TagSlice{"0.9"}}}},
Renames: []Rename{
[]RegistryImagePath{
"gcr.io/foo/a",
"gcr.io/bar/some/subdir/path/a"}},
srcRegistry: &srcRC},
SyncContext{
Inv: MasterInventory{
"gcr.io/foo": RegInvImage{
"a": DigestTags{
"sha256:000": TagSlice{"0.9"}}},
"gcr.io/bar": RegInvImage{
"some/subdir/path/a": DigestTags{
"sha256:111": TagSlice{"0.8"}}},
"gcr.io/cat": RegInvImage{
"a": DigestTags{
"sha256:000": TagSlice{"0.9"}}}}},
nil,
CapturedRequests{PromotionRequest{
TagOp: Add,
RegistrySrc: srcRegName,
RegistryDest: registries[0].Name,
ServiceAccount: registries[0].ServiceAccount,
ImageNameSrc: "a",
ImageNameDest: "some/subdir/path/a",
Digest: "sha256:000",
Tag: "0.9"}: 1},
},
{
"Promote 1 tag via rename (move image)",
Manifest{
Registries: registries,
Images: []Image{
{
ImageName: "a",
Dmap: DigestTags{
"sha256:000": TagSlice{"0.9"}}}},
Renames: []Rename{
[]RegistryImagePath{
"gcr.io/foo/a",
"gcr.io/bar/some/subdir/path/a"}},
srcRegistry: &srcRC},
SyncContext{
Inv: MasterInventory{
"gcr.io/foo": RegInvImage{
"a": DigestTags{
"sha256:000": TagSlice{"0.9"}}},
"gcr.io/bar": RegInvImage{
"some/subdir/path/a": DigestTags{
"sha256:111": TagSlice{"0.9"}}},
"gcr.io/cat": RegInvImage{
"a": DigestTags{
"sha256:000": TagSlice{"0.9"}}}}},
nil,
CapturedRequests{PromotionRequest{
TagOp: Move,
RegistrySrc: srcRegName,
RegistryDest: registries[0].Name,
ServiceAccount: registries[0].ServiceAccount,
ImageNameSrc: "a",
ImageNameDest: "some/subdir/path/a",
Digest: "sha256:000",
DigestOld: "sha256:111",
Tag: "0.9"}: 1},
},
{
"Promote 1 tag via rename (1 dest should be renamed, another should share the same name as src)",
Manifest{
Registries: registries,
Images: []Image{
{
ImageName: "a",
Dmap: DigestTags{
"sha256:000": TagSlice{"0.9"}}}},
Renames: []Rename{
[]RegistryImagePath{
"gcr.io/foo/a",
"gcr.io/bar/some/subdir/path/a"}},
srcRegistry: &srcRC},
SyncContext{
Inv: MasterInventory{
"gcr.io/foo": RegInvImage{
"a": DigestTags{
"sha256:000": TagSlice{"0.9"}}},
"gcr.io/bar": RegInvImage{
"some/subdir/path/a": DigestTags{
"sha256:111": TagSlice{"0.8"}}},
"gcr.io/cat": RegInvImage{
"b": DigestTags{
"sha256:000": TagSlice{"0.9"}}}}},
nil,
CapturedRequests{
PromotionRequest{
TagOp: Add,
RegistrySrc: srcRegName,
RegistryDest: registries[0].Name,
ServiceAccount: registries[0].ServiceAccount,
ImageNameSrc: "a",
ImageNameDest: "some/subdir/path/a",
Digest: "sha256:000",
Tag: "0.9"}: 1,
PromotionRequest{
TagOp: Add,
RegistrySrc: srcRegName,
RegistryDest: registries[2].Name,
ServiceAccount: registries[2].ServiceAccount,
ImageNameSrc: "a",
ImageNameDest: "a",
Digest: "sha256:000",
Tag: "0.9"}: 1,
},
},
{
"Promote 1 tag as a 'rebase'",
Manifest{
@@ -2654,10 +2455,8 @@ func TestPromotion(t *testing.T) {
srcReg, err := getSrcRegistry(registries)
checkError(t, err,
fmt.Sprintf("checkError (srcReg): test: %v\n", test.name))
rd, err := DenormalizeRenames(test.inputM, srcReg.Name)
checkError(t, err,
fmt.Sprintf("checkError (rd): test: %v\n", test.name))
test.inputM.renamesDenormalized = rd
test.inputSc.SrcRegistry = srcReg

// Simulate bad network conditions.

This file was deleted.

0 comments on commit b80ef8a

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